| 8295 | #endif |
| 8296 | |
| 8297 | PUGI__FN xpath_string convert_number_to_string(double value, xpath_allocator* alloc) |
| 8298 | { |
| 8299 | // try special number conversion |
| 8300 | const char_t* special = convert_number_to_string_special(value); |
| 8301 | if (special) return xpath_string::from_const(special); |
| 8302 | |
| 8303 | // get mantissa + exponent form |
| 8304 | char mantissa_buffer[32]; |
| 8305 | |
| 8306 | char* mantissa; |
| 8307 | int exponent; |
| 8308 | convert_number_to_mantissa_exponent(value, mantissa_buffer, &mantissa, &exponent); |
| 8309 | |
| 8310 | // allocate a buffer of suitable length for the number |
| 8311 | size_t result_size = strlen(mantissa_buffer) + (exponent > 0 ? exponent : -exponent) + 4; |
| 8312 | char_t* result = static_cast<char_t*>(alloc->allocate(sizeof(char_t) * result_size)); |
| 8313 | if (!result) return xpath_string(); |
| 8314 | |
| 8315 | // make the number! |
| 8316 | char_t* s = result; |
| 8317 | |
| 8318 | // sign |
| 8319 | if (value < 0) *s++ = '-'; |
| 8320 | |
| 8321 | // integer part |
| 8322 | if (exponent <= 0) |
| 8323 | { |
| 8324 | *s++ = '0'; |
| 8325 | } |
| 8326 | else |
| 8327 | { |
| 8328 | while (exponent > 0) |
| 8329 | { |
| 8330 | assert(*mantissa == 0 || static_cast<unsigned int>(*mantissa - '0') <= 9); |
| 8331 | *s++ = *mantissa ? *mantissa++ : '0'; |
| 8332 | exponent--; |
| 8333 | } |
| 8334 | } |
| 8335 | |
| 8336 | // fractional part |
| 8337 | if (*mantissa) |
| 8338 | { |
| 8339 | // decimal point |
| 8340 | *s++ = '.'; |
| 8341 | |
| 8342 | // extra zeroes from negative exponent |
| 8343 | while (exponent < 0) |
| 8344 | { |
| 8345 | *s++ = '0'; |
| 8346 | exponent++; |
| 8347 | } |
| 8348 | |
| 8349 | // extra mantissa digits |
| 8350 | while (*mantissa) |
| 8351 | { |
| 8352 | assert(static_cast<unsigned int>(*mantissa - '0') <= 9); |
| 8353 | *s++ = *mantissa++; |
| 8354 | } |
nothing calls this directly
no test coverage detected