41 |
} |
} |
42 |
} |
} |
43 |
|
|
44 |
|
// like __eliminate_quotation(), but this one really kills all of 'em |
45 |
|
static void __eliminate_all_quotations(String& s) { |
46 |
|
for (int i = 0; i < s.size(); i++) { |
47 |
|
if (s.c_str()[i] == '\'' || s.c_str()[i] == '\"') { |
48 |
|
s.replace(i, 1, ""); |
49 |
|
i--; |
50 |
|
} |
51 |
|
} |
52 |
|
} |
53 |
|
|
54 |
static bool __parse_bool(String val) throw (Exception) { |
static bool __parse_bool(String val) throw (Exception) { |
55 |
__eliminate_quotation(val); |
__eliminate_all_quotations(val); |
56 |
int b; |
int b; |
57 |
if (val == "1" || !strcasecmp(val.c_str(),"true")) b = true; |
if (val == "1" || !strcasecmp(val.c_str(),"true")) b = true; |
58 |
else if (val == "0" || !strcasecmp(val.c_str(),"false")) b = false; |
else if (val == "0" || !strcasecmp(val.c_str(),"false")) b = false; |
61 |
} |
} |
62 |
|
|
63 |
static int __parse_int(String val) throw (Exception) { |
static int __parse_int(String val) throw (Exception) { |
64 |
__eliminate_quotation(val); |
__eliminate_all_quotations(val); |
65 |
return atoi(val.c_str()); // TODO: format check is missing |
return atoi(val.c_str()); // TODO: format check is missing |
66 |
} |
} |
67 |
|
|
68 |
static float __parse_float(String val) throw (Exception) { |
static float __parse_float(String val) throw (Exception) { |
69 |
__eliminate_quotation(val); |
__eliminate_all_quotations(val); |
70 |
float x; |
float x; |
71 |
std::stringstream ss(val); |
std::stringstream ss(val); |
72 |
ss.imbue(std::locale::classic()); |
ss.imbue(std::locale::classic()); |