| 152 | } |
| 153 | |
| 154 | static char *print_int(cJSON *item) { |
| 155 | char *str; |
| 156 | str = reinterpret_cast<char *>(cJSON_malloc(22)); /* 2^64+1 can be represented in 21 chars. */ |
| 157 | if (str) { |
| 158 | if (item->sign == -1) { |
| 159 | if (item->valueint <= static_cast<int64>(INT_MAX) && item->valueint >= static_cast<int64>(INT_MIN)) { |
| 160 | sprintf(str, "%d", static_cast<int32>(item->valueint)); |
| 161 | } else { |
| 162 | sprintf(str, "%lld", static_cast<int64>(item->valueint)); |
| 163 | } |
| 164 | } else { |
| 165 | if (item->valueint <= static_cast<uint64>(UINT_MAX)) { |
| 166 | sprintf(str, "%u", static_cast<uint32>(item->valueint)); |
| 167 | } else { |
| 168 | sprintf(str, "%llu", item->valueint); |
| 169 | } |
| 170 | } |
| 171 | } |
| 172 | return str; |
| 173 | } |
| 174 | |
| 175 | /* Parse the input text into an unescaped cstring, and populate item. */ |
| 176 | static const unsigned char firstByteMark[7] = {0x00, 0x00, 0xC0, 0xE0, 0xF0, 0xF8, 0xFC}; |