We need well defined results that don't depend on locale
| 49 | |
| 50 | // We need well defined results that don't depend on locale |
| 51 | std::array<char, 4 + std::numeric_limits<std::int64_t>::digits10> |
| 52 | to_string(std::int64_t const n) |
| 53 | { |
| 54 | std::array<char, 4 + std::numeric_limits<std::int64_t>::digits10> ret; |
| 55 | char *p = &ret.back(); |
| 56 | *p = '\0'; |
| 57 | // we want "un" to be the absolute value |
| 58 | // since the absolute of INT64_MIN cannot be represented by a signed |
| 59 | // int64, we calculate the abs in unsigned space |
| 60 | std::uint64_t un = n < 0 |
| 61 | ? std::numeric_limits<std::uint64_t>::max() - std::uint64_t(n) + 1 |
| 62 | : std::uint64_t(n); |
| 63 | do { |
| 64 | *--p = '0' + un % 10; |
| 65 | un /= 10; |
| 66 | } while (un); |
| 67 | if (n < 0) *--p = '-'; |
| 68 | std::memmove(ret.data(), p, std::size_t(&ret.back() - p + 1)); |
| 69 | return ret; |
| 70 | } |
| 71 | |
| 72 | bool is_alpha(char c) |
| 73 | { |