6#ifndef _ZFI_ZFCoreStringConvert_h_
7#define _ZFI_ZFCoreStringConvert_h_
31template<
typename T_Int>
38 if(radix < 2 || radix > 36) {
return zffalse;}
51 else if(n == (T_Int)-1) {
57 unsigned long long e = 1;
58 while(n / e) {e *= radix;}
60 const zfchar *token = useUpperCase
61 ?
"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"
62 :
"0123456789abcdefghijklmnopqrstuvwxyz";
72template<
typename T_Int>
92template<
typename T_Int>
100 if(src ==
zfnull || srcLen == 0 || radix < 2 || radix > 36) {
115 while(*p !=
'\0' && p != pEnd) {
117 if(*p >=
'0' && *p <=
'9') {tmp = *p -
'0';}
118 else if(*p >=
'a' && *p <=
'z') {tmp = 10 + *p -
'a';}
119 else if(*p >=
'A' && *p <=
'Z') {tmp = 10 + *p -
'A';}
121 if(tmp >= radix) {
break;}
122 ret = (T_Int)((ret * (
zfuint)radix) + tmp);
126 ret = (T_Int)0 - ret;
129 if(*p ==
'\0' || p == pEnd) {
139template<
typename T_Int>
147 zfsToIntT(ret, src, srcLen, radix, allowNegative);
170template<
typename T_Float>
176 snprintf(buf,
sizeof(buf),
"%lf", (
double)n);
178 while(*p && *p !=
'.') {++p;}
185 do {--pEnd;}
while(*pEnd ==
'0');
187 s.append(buf, p - buf);
190 s.append(buf, pEnd + 1 - buf);
201template<
typename T_Float>
217template<
typename T_Float>
223 if(src ==
zfnull || srcLen == 0) {
236 while(*p !=
'\0' && *p !=
'.' && p != pEnd) {
237 if(*p <
'0' || *p >
'9') {
break;}
238 ret = ret * 10 + (*p -
'0');
241 if(*p !=
'\0' && *p !=
'.' && p != pEnd) {
248 unsigned long e = 10;
249 while(*p !=
'\0' && p != pEnd
250 && *p >=
'0' && *p <=
'9'
252 ret += (T_Float)(*p -
'0') / e;
256 if(*p !=
'\0' && p != pEnd) {
264 if(*(p + 1) ==
'+') {
276 else if(*(p + 1) ==
'-') {
290 ret = (T_Float)(0 - ret);
293 if(*p ==
'\0' || p == pEnd) {
303template<
typename T_Float>
329 ,
ZF_IN const void *p
333 snprintf(buf,
sizeof(buf),
"<null>");
336 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:218
T_Int zfsToInt(const zfchar *src, zfindex srcLen=((zfindex) -1), zfindex radix=10, zfbool allowNegative=_ZFT_t_zftrue)
see zfsToIntT
Definition ZFCoreStringConvert.h:140
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:93
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:347
T_Float zfsToFloat(const zfchar *src, zfindex srcLen=((zfindex) -1))
see zfsToFloatT
Definition ZFCoreStringConvert.h:304
zfbool zfsFromFloatT(zfstring &s, T_Float n)
convert float number (int, long, etc) to string
Definition ZFCoreStringConvert.h:171
zfstring zfsFromFloat(T_Float n)
see zfsFromFloatT
Definition ZFCoreStringConvert.h:202
zfbool zfsFromPointerT(zfstring &s, const void *p)
convert pointer value to string
Definition ZFCoreStringConvert.h:327
zfstring zfsFromInt(T_Int n, zfindex radix=10, zfbool useUpperCase=_ZFT_t_zftrue)
see zfsFromIntT
Definition ZFCoreStringConvert.h:73
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:180
#define ZF_IN_OPT
dummy macro that shows the param used as optional input
Definition ZFCoreTypeDef_ClassType.h:184
#define ZF_OUT
dummy macro that shows the param used as required output
Definition ZFCoreTypeDef_ClassType.h:188
_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