Read signed integer in a simple form from a non-0-terminated string.
| 55 | |
| 56 | /// Read signed integer in a simple form from a non-0-terminated string. |
| 57 | static Int64 readIntText(const char * buf, const char * end) |
| 58 | { |
| 59 | bool negative = false; |
| 60 | UInt64 x = 0; |
| 61 | |
| 62 | if (buf == end) |
| 63 | throw JSONException("JSON: cannot parse signed integer: unexpected end of data."); |
| 64 | |
| 65 | bool run = true; |
| 66 | while (buf != end && run) |
| 67 | { |
| 68 | switch (*buf) |
| 69 | { |
| 70 | case '+': |
| 71 | break; |
| 72 | case '-': |
| 73 | negative = true; |
| 74 | break; |
| 75 | case '0': |
| 76 | case '1': |
| 77 | case '2': |
| 78 | case '3': |
| 79 | case '4': |
| 80 | case '5': |
| 81 | case '6': |
| 82 | case '7': |
| 83 | case '8': |
| 84 | case '9': |
| 85 | x *= 10; |
| 86 | x += *buf - '0'; |
| 87 | break; |
| 88 | default: |
| 89 | run = false; |
| 90 | break; |
| 91 | } |
| 92 | ++buf; |
| 93 | } |
| 94 | |
| 95 | return negative ? -x : x; |
| 96 | } |
| 97 | |
| 98 | |
| 99 | /// Read floating point number in simple format, imprecisely, from a non-0-terminated string. |
no outgoing calls
no test coverage detected