6#ifndef _ZFI_ZFCoreStringConvert_h_
7#define _ZFI_ZFCoreStringConvert_h_
31template<
typename T_Int>
38 if(radix < 2 || radix > 36) {
return zffalse;}
44 if(n == (T_Int)0 - n) {
55 else if(n == (T_Int)-1) {
61 unsigned long long e = 1;
62 while(n / e) {e *= radix;}
64 const zfchar *token = useUpperCase
65 ?
"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"
66 :
"0123456789abcdefghijklmnopqrstuvwxyz";
76template<
typename T_Int>
96template<
typename T_Int>
104 if(src ==
zfnull || srcLen == 0 || radix < 2 || radix > 36) {
119 while(*p !=
'\0' && p != pEnd) {
121 if(*p >=
'0' && *p <=
'9') {tmp = *p -
'0';}
122 else if(*p >=
'a' && *p <=
'z') {tmp = 10 + *p -
'a';}
123 else if(*p >=
'A' && *p <=
'Z') {tmp = 10 + *p -
'A';}
125 if(tmp >= radix) {
break;}
126 ret = (T_Int)((ret * (
zfuint)radix) + tmp);
130 ret = (T_Int)0 - ret;
133 if(*p ==
'\0' || p == pEnd) {
143template<
typename T_Int>
151 zfsToIntT(ret, src, srcLen, radix, allowNegative);
174template<
typename T_Float>
180 snprintf(buf,
sizeof(buf),
"%.15lf", (
double)n);
182 while(*p && *p !=
'.') {++p;}
189 do {--pEnd;}
while(*pEnd ==
'0');
191 s.append(buf, p - buf);
194 s.append(buf, pEnd + 1 - buf);
205template<
typename T_Float>
221template<
typename T_Float>
227 if(src ==
zfnull || srcLen == 0) {
240 while(*p !=
'\0' && *p !=
'.' && p != pEnd) {
241 if(*p <
'0' || *p >
'9') {
break;}
242 ret = ret * 10 + (*p -
'0');
245 if(*p !=
'\0' && *p !=
'.' && p != pEnd) {
252 unsigned long e = 10;
253 while(*p !=
'\0' && p != pEnd
254 && *p >=
'0' && *p <=
'9'
256 ret += (T_Float)(*p -
'0') / e;
260 if(*p !=
'\0' && p != pEnd) {
268 if(*(p + 1) ==
'+') {
280 else if(*(p + 1) ==
'-') {
294 ret = (T_Float)(0 - ret);
297 if(*p ==
'\0' || p == pEnd) {
307template<
typename T_Float>
333 ,
ZF_IN const void *p
337 snprintf(buf,
sizeof(buf),
"<null>");
340 snprintf(buf,
sizeof(buf),
"%p", p);
zfbool zfsToFloatT(T_Float &ret, const zfchar *src, zfindex srcLen=((zfindex) -1))
convert string to float
Definition ZFCoreStringConvert.h:222
T_Int zfsToInt(const zfchar *src, zfindex srcLen=((zfindex) -1), zfindex radix=10, zfbool allowNegative=_ZFT_t_zftrue)
see zfsToIntT
Definition ZFCoreStringConvert.h:144
zfbool zfsToIntT(T_Int &ret, const zfchar *src, zfindex srcLen=((zfindex) -1), zfindex radix=10, zfbool allowNegative=_ZFT_t_zftrue)
convert string to int, return error position if failed, or null if success
Definition ZFCoreStringConvert.h:97
zfbool zfsFromIntT(zfstring &s, T_Int n, zfindex radix=10, zfbool useUpperCase=_ZFT_t_zftrue)
convert integer number (int, long, etc) to string
Definition ZFCoreStringConvert.h:32
zfstring zfsFromPointer(const void *p)
see zfsFromPointerT
Definition ZFCoreStringConvert.h:351
T_Float zfsToFloat(const zfchar *src, zfindex srcLen=((zfindex) -1))
see zfsToFloatT
Definition ZFCoreStringConvert.h:308
zfbool zfsFromFloatT(zfstring &s, T_Float n)
convert float number (int, long, etc) to string
Definition ZFCoreStringConvert.h:175
zfstring zfsFromFloat(T_Float n)
see zfsFromFloatT
Definition ZFCoreStringConvert.h:206
zfbool zfsFromPointerT(zfstring &s, const void *p)
convert pointer value to string
Definition ZFCoreStringConvert.h:331
zfstring zfsFromInt(T_Int n, zfindex radix=10, zfbool useUpperCase=_ZFT_t_zftrue)
see zfsFromIntT
Definition ZFCoreStringConvert.h:77
zfindex zfslen(const zfchar *s)
strlen wrapper as zfchar type
Definition ZFCoreTypeDef_CharType.h:144
_ZFT_t_zfchar zfchar
char wrapper
Definition ZFCoreTypeDef_CharType.h:17
#define ZF_IN
dummy macro that shows the param used as required input
Definition ZFCoreTypeDef_ClassType.h:184
#define ZF_IN_OPT
dummy macro that shows the param used as optional input
Definition ZFCoreTypeDef_ClassType.h:188
#define ZF_OUT
dummy macro that shows the param used as required output
Definition ZFCoreTypeDef_ClassType.h:192
_ZFT_t_zfbool zfbool
bool type
Definition ZFCoreTypeDef_CoreType.h:103
_ZFT_t_zfindex zfindex
similar to size_t, used for index and size only
Definition ZFCoreTypeDef_CoreType.h:154
#define zftrue
bool true type
Definition ZFCoreTypeDef_CoreType.h:107
_ZFT_t_zfint zfint
same as int, see zfindex
Definition ZFCoreTypeDef_CoreType.h:165
#define zfindexMax()
(zfindex)-1, indicate a max index value, see zfindex
Definition ZFCoreTypeDef_CoreType.h:159
_zft_zffloat zffloat
same as float, see zfindex
Definition ZFCoreTypeDef_CoreType.h:183
#define zffalse
bool false type
Definition ZFCoreTypeDef_CoreType.h:111
#define zfnull
same as NULL, defined for future use
Definition ZFCoreTypeDef_CoreType.h:88
_ZFT_t_zfuint zfuint
same as unsigned int, see zfindex
Definition ZFCoreTypeDef_CoreType.h:169
zft_zfstring< zfchar > zfstring
see zft_zfstring
Definition ZFCoreTypeDef_StringType.h:15
#define ZF_NAMESPACE_GLOBAL_BEGIN
begin namespace ZFFramework
Definition ZFNamespace.h:97
#define ZF_NAMESPACE_GLOBAL_END
end namespace ZFFramework
Definition ZFNamespace.h:98