1 unsigned stou(const char *ptr, void *endptr = NULL, unsigned radix = 10);
2 inline unsigned stou(const byte *ptr, void *endptr = NULL, unsigned radix = 10) { return stou((const char *)ptr, endptr, radix); }
3 unsigned stou(const wchar *ptr, void *endptr = NULL, unsigned radix = 10);
4
5 uint64 stou64(const char *s, void *endptr = NULL, unsigned radix = 10);
6 uint64 stou64(const wchar *s, void *endptr = NULL, unsigned radix = 10);
7
8 int ScanInt(const char *ptr, const char **endptr = NULL, int radix = 10);
9 int ScanInt(const wchar *ptr, const wchar **endptr = NULL, int radix = 10);
10
11 int64 ScanInt64(const char *ptr, const char **endptr = NULL, int radix = 10);
12
13 double ScanDouble(const char *ptr, const char **endptr = NULL, bool accept_comma = true);
14 double ScanDouble(const wchar *ptr, const wchar **endptr = NULL, bool accept_comma = true);
15
16 double Atof(const char *s);
17
18 Value StrIntValue(const char *s);
19
StrInt(const char * s)20 inline int StrInt(const char* s) { return ScanInt(s); }
IntStr(int i)21 inline String IntStr(int i) { return FormatInt(i); }
22
StrInt64(const char * s)23 inline int64 StrInt64(const char *s) { return ScanInt64(s); }
IntStr64(int64 i)24 inline String IntStr64(int64 i) { return FormatInt64(i); }
25
StrDbl(const char * s)26 inline double StrDbl(const char* s) { return ScanDouble(s); }
DblStr(double d)27 inline String DblStr(double d) { return FormatDouble(d, 10); }
28
IntDbl(int i)29 inline double IntDbl(int i) { return IsNull(i) ? double(Null) : double(i); }
DblInt(double d)30 inline int DblInt(double d) { return IsNull(d) ? int(Null) : fround(d); }
31
32 Value StrDblValue(const char* s);
33
34
35 Value NotNullError();
36
37 class Convert {
38 public:
39 Convert();
40 virtual ~Convert();
41
42 virtual Value Format(const Value& q) const;
43 virtual Value Scan(const Value& text) const;
44 virtual int Filter(int chr) const;
45
operator()46 Value operator()(const Value& q) const { return Format(q); }
47 };
48
49 const Convert& StdConvert();
50
51 String StdFormat(const Value& q);
52
53 class ConvertInt : public Convert {
54 public:
55 virtual Value Scan(const Value& text) const;
56 virtual int Filter(int chr) const;
57
58 protected:
59 int64 minval, maxval;
60 bool notnull;
61
62 public:
MinMax(int _min,int _max)63 ConvertInt& MinMax(int _min, int _max) { minval = _min; maxval = _max; return *this; }
Min(int _min)64 ConvertInt& Min(int _min) { minval = _min; return *this; }
Max(int _max)65 ConvertInt& Max(int _max) { maxval = _max; return *this; }
66 ConvertInt& NotNull(bool b = true) { notnull = b; return *this; }
NoNotNull()67 ConvertInt& NoNotNull() { return NotNull(false); }
GetMin()68 int GetMin() const { return (int)minval; }
GetMax()69 int GetMax() const { return (int)maxval; }
IsNotNull()70 bool IsNotNull() const { return notnull; }
71
GetDefaultMin()72 static int GetDefaultMin() { return -INT_MAX; }
GetDefaultMax()73 static int GetDefaultMax() { return INT_MAX; }
74
75 ConvertInt(int minval = -INT_MAX, int maxval = INT_MAX, bool notnull = false)
minval(minval)76 : minval(minval), maxval(maxval), notnull(notnull) {}
77 };
78
79 const ConvertInt& StdConvertInt();
80 const ConvertInt& StdConvertIntNotNull();
81
82 struct ConvertInt64 : public ConvertInt {
MinMaxConvertInt6483 ConvertInt64& MinMax(int64 _min, int64 _max) { minval = _min; maxval = _max; return *this; }
MinConvertInt6484 ConvertInt64& Min(int64 _min) { minval = _min; return *this; }
MaxConvertInt6485 ConvertInt64& Max(int64 _max) { maxval = _max; return *this; }
GetMinConvertInt6486 int64 GetMin() const { return minval; }
GetMaxConvertInt6487 int64 GetMax() const { return maxval; }
88
GetDefaultMinConvertInt6489 static int64 GetDefaultMin() { return -INT64_MAX; }
GetDefaultMaxConvertInt6490 static int64 GetDefaultMax() { return INT64_MAX; }
91
92 ConvertInt64(int64 minval = -INT64_MAX, int64 maxval = INT64_MAX, bool notnull = false) {
93 MinMax(minval, maxval); NotNull(notnull);
94 }
95 };
96
97 class ConvertDouble : public Convert {
98 public:
99 virtual Value Format(const Value& q) const;
100 virtual Value Scan(const Value& text) const;
101 virtual int Filter(int chr) const;
102
103 protected:
104 double minval, maxval;
105 bool notnull, comma;
106 String pattern;
107
108 public:
109 ConvertDouble& Pattern(const char *p);
MinMax(double _min,double _max)110 ConvertDouble& MinMax(double _min, double _max) { minval = _min; maxval = _max; return *this; }
Min(double _min)111 ConvertDouble& Min(double _min) { minval = _min; return *this; }
Max(double _max)112 ConvertDouble& Max(double _max) { maxval = _max; return *this; }
113 ConvertDouble& NotNull(bool b = true) { notnull = b; return *this; }
NoNotNull()114 ConvertDouble& NoNotNull() { return NotNull(false); }
GetMin()115 double GetMin() const { return minval; }
GetMax()116 double GetMax() const { return maxval; }
IsNotNull()117 bool IsNotNull() const { return notnull; }
118
GetDefaultMin()119 static double GetDefaultMin() { return DOUBLE_NULL_LIM; }
GetDefaultMax()120 static double GetDefaultMax() { return -DOUBLE_NULL_LIM; }
121
122 ConvertDouble(double minval = DOUBLE_NULL_LIM, double maxval = -DOUBLE_NULL_LIM,
123 bool notnull = false);
124 };
125
126 const ConvertDouble& StdConvertDouble();
127 const ConvertDouble& StdConvertDoubleNotNull();
128
129 class ConvertDate : public Convert {
130 public:
131 virtual Value Format(const Value& q) const;
132 virtual Value Scan(const Value& text) const;
133 virtual int Filter(int chr) const;
134
135 protected:
136 Date minval, maxval, defaultval;
137 bool notnull;
138
139 static Date& default_min();
140 static Date& default_max();
141
142 public:
MinMax(Date _min,Date _max)143 ConvertDate& MinMax(Date _min, Date _max) { minval = _min; maxval = _max; return *this; }
Min(Date _min)144 ConvertDate& Min(Date _min) { minval = _min; return *this; }
Max(Date _max)145 ConvertDate& Max(Date _max) { maxval = _max; return *this; }
146 ConvertDate& NotNull(bool b = true) { notnull = b; return *this; }
NoNotNull()147 ConvertDate& NoNotNull() { return NotNull(false); }
Default(Date d)148 ConvertDate& Default(Date d) { defaultval = d; return *this; }
IsNotNull()149 bool IsNotNull() const { return notnull; }
GetMin()150 Date GetMin() const { return max(GetDefaultMin(), minval); }
GetMax()151 Date GetMax() const { return min(GetDefaultMax(), maxval); }
152
153 static void SetDefaultMinMax(Date min, Date max);
GetDefaultMin()154 static Date GetDefaultMin() { return default_min(); }
GetDefaultMax()155 static Date GetDefaultMax() { return default_max(); }
156
157 ConvertDate(Date minval = Date::Low(), Date maxval = Date::High(), bool notnull = false);
158 };
159
160 const ConvertDate& StdConvertDate();
161 const ConvertDate& StdConvertDateNotNull();
162
163 class ConvertTime : public Convert {
164 public:
165 virtual Value Scan(const Value& text) const;
166 virtual int Filter(int chr) const;
167 virtual Value Format(const Value& q) const;
168
169 protected:
170 Time minval, maxval, defaultval;
171 bool notnull;
172 bool seconds;
173 bool timealways;
174 bool dayend;
175
176 public:
MinMax(Time _min,Time _max)177 ConvertTime& MinMax(Time _min, Time _max) { minval = _min; maxval = _max; return *this; }
Min(Time _min)178 ConvertTime& Min(Time _min) { minval = _min; return *this; }
Max(Time _max)179 ConvertTime& Max(Time _max) { maxval = _max; return *this; }
180 ConvertTime& NotNull(bool b = true) { notnull = b; return *this; }
NoNotNull()181 ConvertTime& NoNotNull() { return NotNull(false); }
182 ConvertTime& Seconds(bool b = true) { seconds = b; return *this; }
NoSeconds()183 ConvertTime& NoSeconds() { return Seconds(false); }
IsSeconds()184 bool IsSeconds() const { return seconds; }
185 ConvertTime& TimeAlways(bool b = true) { timealways = b; return *this; }
IsTimeAlways()186 bool IsTimeAlways() const { return timealways; }
187 ConvertTime& DayEnd(bool b = true) { dayend = b; return *this; }
IsDayEnd()188 bool IsDayEnd() const { return dayend; }
Default(Time d)189 ConvertTime& Default(Time d) { defaultval = d; return *this; }
IsNotNull()190 bool IsNotNull() const { return notnull; }
191
GetMin()192 Time GetMin() const { return max(minval, GetDefaultMin()); }
GetMax()193 Time GetMax() const { return min(maxval, GetDefaultMax()); }
194
GetDefaultMin()195 static Time GetDefaultMin() { return ToTime(ConvertDate::GetDefaultMin()); }
GetDefaultMax()196 static Time GetDefaultMax() { return ToTime(ConvertDate::GetDefaultMax()); }
197
198 ConvertTime(Time minval = ToTime(Date::Low()), Time maxval = ToTime(Date::High()), bool notnull = false);
199 virtual ~ConvertTime();
200 };
201
202 const ConvertTime& StdConvertTime();
203 const ConvertTime& StdConvertTimeNotNull();
204
205 class ConvertString : public Convert {
206 public:
207 virtual Value Scan(const Value& text) const;
208
209 protected:
210 int maxlen;
211 bool notnull, trimleft, trimright;
212
213 public:
MaxLen(int _maxlen)214 ConvertString& MaxLen(int _maxlen) { maxlen = _maxlen; return *this; }
GetMaxLength()215 int GetMaxLength() const { return maxlen; }
216 ConvertString& NotNull(bool b = true) { notnull = b; return *this; }
NoNotNull()217 ConvertString& NoNotNull() { return NotNull(false); }
IsNotNull()218 bool IsNotNull() const { return notnull; }
219 ConvertString& TrimLeft(bool b = true) { trimleft = b; return *this; }
220 ConvertString& TrimRight(bool b = true) { trimright = b; return *this; }
221 ConvertString& TrimBoth(bool b = true) { return TrimLeft(b).TrimRight(b); }
IsTrimLeft()222 bool IsTrimLeft() const { return trimleft; }
IsTrimRight()223 bool IsTrimRight() const { return trimright; }
224
225 ConvertString(int maxlen = INT_MAX, bool notnull = false)
maxlen(maxlen)226 : maxlen(maxlen), notnull(notnull) { trimleft = trimright = false; }
227 };
228
229 const ConvertString& StdConvertString();
230 const ConvertString& StdConvertStringNotNull();
231
232 class NoConvertClass : public Convert {
233 public:
234 NoConvertClass();
235
236 virtual Value Format(const Value& q) const;
237 };
238
239 const NoConvertClass& NoConvert();
240
241 class ErrorConvertClass : public Convert {
242 public:
243 Value Scan(const Value& v) const;
244 };
245
246 const ErrorConvertClass& ErrorConvert();
247
248 class MapConvert : public Convert {
249 public:
250 virtual Value Format(const Value& q) const;
251
252 protected:
253 VectorMap<Value, Value> map;
254 Value default_value;
255
256 public:
Clear()257 void Clear() { map.Clear(); }
Add(const Value & a,const Value & b)258 MapConvert& Add(const Value& a, const Value& b) { map.Add(a, b); return *this; }
Default(const Value & v)259 MapConvert& Default(const Value& v) { default_value = v; return *this; }
260
GetCount()261 int GetCount() const { return map.GetCount(); }
Find(const Value & v)262 int Find(const Value& v) const { return map.Find(v); }
GetKey(int i)263 const Value& GetKey(int i) const { return map.GetKey(i); }
GetValue(int i)264 const Value& GetValue(int i) const { return map[i]; }
265 const Value& operator[](int i) const { return map[i]; }
266
~MapConvert()267 virtual ~MapConvert() {}
268 };
269
270 class JoinConvert : public Convert {
271 public:
272 virtual Value Format(const Value& v) const;
273
274 protected:
275 struct Item {
276 int pos;
277 const Convert *convert;
278 String text;
279 };
280 Array<Item> item;
281
282 int NextPos() const;
283
284 public:
285 JoinConvert& Add(const char *text);
286 JoinConvert& Add(int pos, const Convert& cv);
287 JoinConvert& Add(int pos);
288 JoinConvert& Add(const Convert& cv);
289 JoinConvert& Add();
290 };
291
292 class FormatConvert : public Convert {
293 public:
294 virtual Value Format(const Value& v) const;
295
296 private:
297 String format;
298
299 public:
SetFormat(const char * fmt)300 void SetFormat(const char *fmt) { format = fmt; }
301 };
302
303 Convert& LNGConvert();
304