Read unsigned integer in a simple form from a non-0-terminated string.
| 18 | |
| 19 | /// Read unsigned integer in a simple form from a non-0-terminated string. |
| 20 | static UInt64 readUIntText(const char * buf, const char * end) |
| 21 | { |
| 22 | UInt64 x = 0; |
| 23 | |
| 24 | if (buf == end) |
| 25 | throw JSONException("JSON: cannot parse unsigned integer: unexpected end of data."); |
| 26 | |
| 27 | while (buf != end) |
| 28 | { |
| 29 | switch (*buf) |
| 30 | { |
| 31 | case '+': |
| 32 | break; |
| 33 | case '0': |
| 34 | case '1': |
| 35 | case '2': |
| 36 | case '3': |
| 37 | case '4': |
| 38 | case '5': |
| 39 | case '6': |
| 40 | case '7': |
| 41 | case '8': |
| 42 | case '9': |
| 43 | x *= 10; |
| 44 | x += *buf - '0'; |
| 45 | break; |
| 46 | default: |
| 47 | return x; |
| 48 | } |
| 49 | ++buf; |
| 50 | } |
| 51 | |
| 52 | return x; |
| 53 | } |
| 54 | |
| 55 | |
| 56 | /// Read signed integer in a simple form from a non-0-terminated string. |