Browse code

b/f: fix json2arg for numbers with exponent

Stefan Sayer authored on 17/02/2014 16:07:10
Showing 3 changed files
... ...
@@ -381,7 +381,7 @@ void AmArg::assertArrayFmt(const char* format) const {
381 381
     for (size_t i=0;i<fmt_len;i++) {
382 382
       switch (format[i]) {
383 383
       case 'i': assertArgInt(get(i)); got+='i';  break;
384
-      case 'l': assertArgLongLong(get(i)); got+='i';  break;
384
+      case 'l': assertArgLongLong(get(i)); got+='l';  break;
385 385
       case 't': assertArgBool(get(i)); got+='t';  break;
386 386
       case 'f': assertArgDouble(get(i)); got+='f'; break;
387 387
       case 's': assertArgCStr(get(i)); got+='s'; break;
... ...
@@ -167,35 +167,35 @@ bool parse_float(std::istream& input, double* value) {
167 167
   */
168 168
 
169 169
 
170
-bool parse_number(std::istream& input, long* value) {
171
-    eat_whitespaces(input);
172
-    char ch;
173
-    std::string value_str;
174
-    int sign = 1;
175
-    if (match("-", input)) {
176
-        sign = -1;
177
-    } else {
178
-        match("+", input);
179
-    }
180
-    while(input && !input.eof()) {
181
-        input.get(ch);
182
-        if (!isdigit(ch)) {
183
-            input.putback(ch);
184
-            break;
185
-        }
186
-        value_str.push_back(ch);
187
-    }
188
-    if (value_str.size() > 0) {
189
-        std::istringstream(value_str) >> *value;
190
-	*value*=sign;
191
-        return true;
192
-    } else {
193
-        return false;
194
-    }
195
-}
170
+// bool parse_number(std::istream& input, long* value) {
171
+//     eat_whitespaces(input);
172
+//     char ch;
173
+//     std::string value_str;
174
+//     int sign = 1;
175
+//     if (match("-", input)) {
176
+//         sign = -1;
177
+//     } else {
178
+//         match("+", input);
179
+//     }
180
+//     while(input && !input.eof()) {
181
+//         input.get(ch);
182
+//         if (!isdigit(ch)) {
183
+//             input.putback(ch);
184
+//             break;
185
+//         }
186
+//         value_str.push_back(ch);
187
+//     }
188
+//     if (value_str.size() > 0) {
189
+//         std::istringstream(value_str) >> *value;
190
+// 	*value*=sign;
191
+//         return true;
192
+//     } else {
193
+//         return false;
194
+//     }
195
+// }
196 196
 
197 197
 
198
-bool parse_number(std::istream& input, int* value) {
198
+bool parse_number(std::istream& input, long* value) {
199 199
     eat_whitespaces(input);
200 200
     char ch;
201 201
     std::string value_str;
... ...
@@ -204,7 +204,7 @@ bool parse_number(std::istream& input, int* value) {
204 204
     int sign = 1;
205 205
     int e_sign = 1;
206 206
     bool correct = true;
207
-    int e_value;
207
+    long e_value;
208 208
 
209 209
     enum {
210 210
       p_number,
... ...
@@ -303,7 +303,7 @@ bool parse_number(std::istream& input, int* value) {
303 303
 	    
304 304
 	    return false;  
305 305
 	  }
306
-	  *value *= pow(10, e_value);
306
+	  *value *= powl(10, e_value);
307 307
 	}
308 308
 
309 309
         return true;
... ...
@@ -54,7 +54,8 @@ FCTMF_SUITE_BGN(test_jsonarg) {
54 54
       // DBG("s.c_str() %s\n", s.c_str() );
55 55
       AmArg rpc_params;
56 56
       fct_chk(json2arg(s.c_str(), rpc_params));
57
-      fct_chk(isArgInt(rpc_params["result"]) && rpc_params["result"].asInt() == 0);
57
+      fct_chk(isArgInt(rpc_params["result"]));
58
+      fct_chk(rpc_params["result"].asInt() == 0);
58 59
     } FCT_TEST_END();
59 60
 
60 61
     FCT_TEST_BGN(json_number_e_pow) {