MCPcopy Create free account
hub / github.com/dirkvranckaert/AndroidDecompiler / getNumberFormat

Method getNumberFormat

astyle/src/astyle_main.cpp:912–951  ·  view source on GitHub ↗

* WINDOWS function to format a number according to the current locale. * This formats positive integers only, no float. * * @param num The number to be formatted. * @param lcid The LCID of the locale to be used for testing. * @return The formatted number. */

Source from the content-addressed store, hash-verified

910 * @return The formatted number.
911 */
912string ASConsole::getNumberFormat(int num, size_t lcid) const
913{
914#if defined(_MSC_VER) || defined(__MINGW32__) || defined(__BORLANDC__) || defined(__GNUC__)
915 // Compilers that don't support C++ locales should still support this assert.
916 // The C locale should be set but not the C++.
917 // This function is not necessary if the C++ locale is set.
918 // The locale().name() return value is not portable to all compilers.
919 assert(locale().name() == "C");
920#endif
921 // convert num to a string
922 stringstream alphaNum;
923 alphaNum << num;
924 string number = alphaNum.str();
925 if (useAscii)
926 return number;
927
928 // format the number using the Windows API
929 if (lcid == 0)
930 lcid = LOCALE_USER_DEFAULT;
931 int outSize = ::GetNumberFormat(lcid, 0, number.c_str(), NULL, NULL, 0);
932 char* outBuf = new(nothrow) char[outSize];
933 if (outBuf == NULL)
934 return number;
935 ::GetNumberFormat(lcid, 0, number.c_str(), NULL, outBuf, outSize);
936 string formattedNum(outBuf);
937 delete [] outBuf;
938 // remove the decimal
939 int decSize = ::GetLocaleInfo(lcid, LOCALE_SDECIMAL, NULL, 0);
940 char* decBuf = new(nothrow) char[decSize];
941 if (decBuf == NULL)
942 return number;
943 ::GetLocaleInfo(lcid, LOCALE_SDECIMAL, decBuf, decSize);
944 size_t i = formattedNum.rfind(decBuf);
945 delete [] decBuf;
946 if (i != string::npos)
947 formattedNum.erase(i);
948 if (!formattedNum.length())
949 formattedNum = "0";
950 return formattedNum;
951}
952
953#else // not _WIN32
954

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected