X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/d8d9844b299bb9c91a35025f87a079f04c30eae9..77c8efc8c37da6d6a5e2e8022d21d1cd7d76371d:/src/common/numformatter.cpp diff --git a/src/common/numformatter.cpp b/src/common/numformatter.cpp index 898c1cf933..0c3a6a7a1a 100644 --- a/src/common/numformatter.cpp +++ b/src/common/numformatter.cpp @@ -1,5 +1,5 @@ ///////////////////////////////////////////////////////////////////////////// -// Name: numformatter.cpp +// Name: src/common/numformatter.cpp // Purpose: wxNumberFormatter // Author: Fulvio Senore, Vadim Zeitlin // Created: 2010-11-06 @@ -21,6 +21,8 @@ #include "wx/numformatter.h" #include "wx/intl.h" +#include // for setlocale and LC_ALL + // ---------------------------------------------------------------------------- // local helpers // ---------------------------------------------------------------------------- @@ -39,7 +41,9 @@ class LocaleId public: LocaleId() { +#if wxUSE_INTL m_wxloc = NULL; +#endif // wxUSE_INTL m_cloc = NULL; } @@ -48,6 +52,7 @@ public: Free(); } +#if wxUSE_INTL // Return true if this is the first time this function is called for this // object or if the program locale has changed since the last time it was // called. Otherwise just return false indicating that updating locale- @@ -70,15 +75,20 @@ public: return true; } +#endif // wxUSE_INTL private: void Free() { +#if wxUSE_INTL free(m_cloc); +#endif // wxUSE_INTL } +#if wxUSE_INTL // Non-owned pointer to wxLocale which was used. wxLocale *m_wxloc; +#endif // wxUSE_INTL // Owned pointer to the C locale string. char *m_cloc; @@ -98,6 +108,7 @@ private: wxChar wxNumberFormatter::GetDecimalSeparator() { +#if wxUSE_INTL // Notice that while using static variable here is not MT-safe, the worst // that can happen is that we redo the initialization if we're called // concurrently from more than one thread so it's not a real problem. @@ -128,10 +139,14 @@ wxChar wxNumberFormatter::GetDecimalSeparator() } return s_decimalSeparator; +#else // !wxUSE_INTL + return wxT('.'); +#endif // wxUSE_INTL/!wxUSE_INTL } bool wxNumberFormatter::GetThousandsSeparatorIfUsed(wxChar *sep) { +#if wxUSE_INTL static wxChar s_thousandsSeparator = 0; static LocaleId s_localeUsedForInit; @@ -157,6 +172,10 @@ bool wxNumberFormatter::GetThousandsSeparatorIfUsed(wxChar *sep) *sep = s_thousandsSeparator; return true; +#else // !wxUSE_INTL + wxUnusedVar(sep); + return false; +#endif // wxUSE_INTL/!wxUSE_INTL } // ---------------------------------------------------------------------------- @@ -216,6 +235,10 @@ void wxNumberFormatter::AddThousandsSeparators(wxString& s) pos = s.length(); } + // End grouping at the beginning of the digits -- there could be at a sign + // before their start. + const size_t start = s.find_first_of("0123456789"); + // We currently group digits by 3 independently of the locale. This is not // the right thing to do and we should use lconv::grouping (under POSIX) // and GetLocaleInfo(LOCALE_SGROUPING) (under MSW) to get information about @@ -223,7 +246,7 @@ void wxNumberFormatter::AddThousandsSeparators(wxString& s) // wxLocale level first and then used here in the future (TODO). const size_t GROUP_LEN = 3; - while ( pos > GROUP_LEN ) + while ( pos > start + GROUP_LEN ) { pos -= GROUP_LEN; s.insert(pos, thousandsSep);