MCPcopy Create free account
hub / github.com/MyGUI/mygui / xpath_string convert_number_to_string

Function xpath_string convert_number_to_string

Tools/EditorFramework/pugixml.cpp:7039–7102  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

7037 #endif
7038
7039PUGI__FN xpath_string convert_number_to_string(double value, xpath_allocator* alloc)
7040{
7041 // try special number conversion
7042 const char_t* special = convert_number_to_string_special(value);
7043 if (special)
7044 return xpath_string_const(special);
7045
7046 // get mantissa + exponent form
7047 char mantissa_buffer[64];
7048
7049 char* mantissa;
7050 int exponent;
7051 convert_number_to_mantissa_exponent(value, mantissa_buffer, sizeof(mantissa_buffer), &mantissa, &exponent);
7052
7053 // make the number!
7054 char_t result[512];
7055 char_t* s = result;
7056
7057 // sign
7058 if (value < 0)
7059 *s++ = '-';
7060
7061 // integer part
7062 if (exponent <= 0)
7063 {
7064 *s++ = '0';
7065 }
7066 else
7067 {
7068 while (exponent > 0)
7069 {
7070 assert(*mantissa == 0 || static_cast<unsigned int>(*mantissa - '0') <= 9);
7071 *s++ = *mantissa ? *mantissa++ : '0';
7072 exponent--;
7073 }
7074 }
7075
7076 // fractional part
7077 if (*mantissa)
7078 {
7079 // decimal point
7080 *s++ = '.';
7081
7082 // extra zeroes from negative exponent
7083 while (exponent < 0)
7084 {
7085 *s++ = '0';
7086 exponent++;
7087 }
7088
7089 // extra mantissa digits
7090 while (*mantissa)
7091 {
7092 assert(static_cast<unsigned int>(*mantissa - '0') <= 9);
7093 *s++ = *mantissa++;
7094 }
7095 }
7096

Callers

nothing calls this directly

Calls 3

xpath_stringFunction · 0.70

Tested by

no test coverage detected