ZFFramework
 
Loading...
Searching...
No Matches
ZFCoreDataPairSplit.h
Go to the documentation of this file.
1
5
6#ifndef _ZFI_ZFCoreDataPairSplit_h_
7#define _ZFI_ZFCoreDataPairSplit_h_
8
9#include "ZFCoreArray.h"
10#include "ZFCoreStringUtil.h"
11
13
31 , ZF_IN zfindex desiredCountOrIndexMax
32 , ZF_IN const zfchar *src
33 , ZF_IN_OPT zfindex srcLen = zfindexMax()
34 , ZF_IN_OPT const zfchar *separatorTokens = ","
35 , ZF_IN_OPT const zfchar *leftTokens = "("
36 , ZF_IN_OPT const zfchar *rightTokens = ")"
37 , ZF_IN_OPT zfbool allowEmptyItem = zffalse
38 );
39
43template<typename T_int>
46 , ZF_IN zfindex desiredCountOrIndexMax
47 , ZF_IN const zfchar *src
48 , ZF_IN_OPT zfindex srcLen = zfindexMax()
49 , ZF_IN_OPT const zfchar *separatorTokens = ","
50 , ZF_IN_OPT const zfchar *leftTokens = "("
51 , ZF_IN_OPT const zfchar *rightTokens = ")"
52 , ZF_IN_OPT zfbool allowEmptyItem = zffalse
53 ) {
56 splited
57 , desiredCountOrIndexMax
58 , src
59 , srcLen
60 , separatorTokens
61 , leftTokens
62 , rightTokens
63 , allowEmptyItem
64 )) {
65 return zffalse;
66 }
67 for(zfindex i = 0; i < splited.count(); ++i) {
68 T_int tmp;
69 tmp = 0;
70 if(!zfsToIntT(tmp, src + splited[i].start, splited[i].count, 10, zftrue)) {
71 return zffalse;
72 }
73 outData.add(tmp);
74 }
75 return zftrue;
76}
77
81template<typename T_float>
84 , ZF_IN zfindex desiredCountOrIndexMax
85 , ZF_IN const zfchar *src
86 , ZF_IN_OPT zfindex srcLen = zfindexMax()
87 , ZF_IN_OPT const zfchar *separatorTokens = ","
88 , ZF_IN_OPT const zfchar *leftTokens = "("
89 , ZF_IN_OPT const zfchar *rightTokens = ")"
90 , ZF_IN_OPT zfbool allowEmptyItem = zffalse
91 ) {
94 splited
95 , desiredCountOrIndexMax
96 , src
97 , srcLen
98 , separatorTokens
99 , leftTokens
100 , rightTokens
101 , allowEmptyItem
102 )) {
103 return zffalse;
104 }
105 for(zfindex i = 0; i < splited.count(); ++i) {
106 T_float tmp = 0;
107 if(!zfsToFloatT(tmp, src + splited[i].start, splited[i].count)) {
108 return zffalse;
109 }
110 outData.add(tmp);
111 }
112 return zftrue;
113}
114
116
117#endif // #ifndef _ZFI_ZFCoreDataPairSplit_h_
118
light weight array
zfbool ZFCoreDataPairSplitFloat(ZFCoreArray< T_float > &outData, zfindex desiredCountOrIndexMax, const zfchar *src, zfindex srcLen=((zfindex) -1), const zfchar *separatorTokens=",", const zfchar *leftTokens="(", const zfchar *rightTokens=")", zfbool allowEmptyItem=_ZFT_t_zffalse)
split data to float array format, see ZFCoreDataPairSplitString
Definition ZFCoreDataPairSplit.h:82
zfbool ZFCoreDataPairSplitString(ZFCoreArray< ZFIndexRange > &outData, zfindex desiredCountOrIndexMax, const zfchar *src, zfindex srcLen=((zfindex) -1), const zfchar *separatorTokens=",", const zfchar *leftTokens="(", const zfchar *rightTokens=")", zfbool allowEmptyItem=_ZFT_t_zffalse)
split data pair such as "(a, b, c)" from a string
zfbool ZFCoreDataPairSplitInt(ZFCoreArray< T_int > &outData, zfindex desiredCountOrIndexMax, const zfchar *src, zfindex srcLen=((zfindex) -1), const zfchar *separatorTokens=",", const zfchar *leftTokens="(", const zfchar *rightTokens=")", zfbool allowEmptyItem=_ZFT_t_zffalse)
split data to int array format, see ZFCoreDataPairSplitString
Definition ZFCoreDataPairSplit.h:44
#define ZFLIB_ZFCore
used to export symbols
Definition ZFCoreEnvDef.h:30
zfbool zfsToFloatT(T_Float &ret, const zfchar *src, zfindex srcLen=((zfindex) -1))
convert string to float
Definition ZFCoreStringConvert.h:218
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
string utilities for ZFFramework
_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_IN_OUT
dummy macro that shows the param used as required input and output
Definition ZFCoreTypeDef_ClassType.h:196
_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
#define zfindexMax()
(zfindex)-1, indicate a max index value, see zfindex
Definition ZFCoreTypeDef_CoreType.h:159
#define zffalse
bool false type
Definition ZFCoreTypeDef_CoreType.h:111
#define ZF_NAMESPACE_GLOBAL_BEGIN
begin namespace ZFFramework
Definition ZFNamespace.h:97
#define ZF_NAMESPACE_GLOBAL_END
end namespace ZFFramework
Definition ZFNamespace.h:98
light weight array
Definition ZFCoreArray.h:331
virtual zfindex count(void) const
element count of this array
Definition ZFCoreArray.h:920