summaryrefslogtreecommitdiff
path: root/sal
diff options
context:
space:
mode:
authorStephan Bergmann <sbergman@redhat.com>2017-03-24 09:00:51 +0100
committerStephan Bergmann <sbergman@redhat.com>2017-03-24 09:06:15 +0100
commitce6e07ebfcbb589f22cbc8dda2bb4a1d0a683beb (patch)
treefb2a35d1c879086e9aa3d4b08865739ec9adfcdb /sal
parent003fd6b95033a2a0d28e04dec2e756e4c67f9d1a (diff)
Handle "POSIX" in parse_locale, 2nd attempt
...with the silly errors fixed past 61ecebe0d0febe8429d965355356a9f0f34b323b "Revert 'Handle 'POSIX' in parse_locale'" Change-Id: I0b8e4de0377b92b8cb96efa13e4b39316ffbf707
Diffstat (limited to 'sal')
-rw-r--r--sal/osl/unx/nlsupport.cxx71
1 files changed, 37 insertions, 34 deletions
diff --git a/sal/osl/unx/nlsupport.cxx b/sal/osl/unx/nlsupport.cxx
index 589439fffe94..48558b9489d3 100644
--- a/sal/osl/unx/nlsupport.cxx
+++ b/sal/osl/unx/nlsupport.cxx
@@ -17,6 +17,10 @@
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
+#include <sal/config.h>
+
+#include <algorithm>
+
#include <osl/nlsupport.h>
#include <osl/diagnose.h>
#include <osl/process.h>
@@ -173,52 +177,51 @@ static rtl_Locale * parse_locale( const char * locale )
{
assert(locale != nullptr);
- static sal_Unicode c_locale[2] = { (sal_Unicode) 'C', 0 };
+ if (*locale == '\0' || std::strcmp(locale, "C") == 0
+ || std::strcmp(locale, "POSIX") == 0)
+ {
+ return rtl_locale_register(u"C", u"", u"");
+ }
size_t len = strlen( locale );
- if( len >= 2 )
- {
- rtl_uString * pLanguage = nullptr;
- rtl_uString * pCountry = nullptr;
- rtl_uString * pVariant = nullptr;
+ rtl_uString * pLanguage = nullptr;
+ rtl_uString * pCountry = nullptr;
+ rtl_uString * pVariant = nullptr;
- size_t offset = 2;
+ size_t offset = std::min<size_t>(len, 2);
- rtl_Locale * ret;
+ rtl_Locale * ret;
- /* language is a two or three letter code */
- if( (len > 3 && locale[3] == '_') || (len == 3 && locale[2] != '_') )
- offset = 3;
+ /* language is a two or three letter code */
+ if( (len > 3 && locale[3] == '_') || (len == 3 && locale[2] != '_') )
+ offset = 3;
- /* convert language code to unicode */
- rtl_string2UString( &pLanguage, locale, offset, RTL_TEXTENCODING_ASCII_US, OSTRING_TO_OUSTRING_CVTFLAGS );
- OSL_ASSERT(pLanguage != nullptr);
+ /* convert language code to unicode */
+ rtl_string2UString( &pLanguage, locale, offset, RTL_TEXTENCODING_ASCII_US, OSTRING_TO_OUSTRING_CVTFLAGS );
+ OSL_ASSERT(pLanguage != nullptr);
- /* convert country code to unicode */
- if( len >= offset+3 && locale[offset] == '_' )
- {
- rtl_string2UString( &pCountry, locale + offset + 1, 2, RTL_TEXTENCODING_ASCII_US, OSTRING_TO_OUSTRING_CVTFLAGS );
- OSL_ASSERT(pCountry != nullptr);
- offset += 3;
- }
+ /* convert country code to unicode */
+ if( len >= offset+3 && locale[offset] == '_' )
+ {
+ rtl_string2UString( &pCountry, locale + offset + 1, 2, RTL_TEXTENCODING_ASCII_US, OSTRING_TO_OUSTRING_CVTFLAGS );
+ OSL_ASSERT(pCountry != nullptr);
+ offset += 3;
+ }
- /* convert variant code to unicode - do not rely on "." as delimiter */
- if( len > offset ) {
- rtl_string2UString( &pVariant, locale + offset, len - offset, RTL_TEXTENCODING_ASCII_US, OSTRING_TO_OUSTRING_CVTFLAGS );
- OSL_ASSERT(pVariant != nullptr);
- }
+ /* convert variant code to unicode - do not rely on "." as delimiter */
+ if( len > offset ) {
+ rtl_string2UString( &pVariant, locale + offset, len - offset, RTL_TEXTENCODING_ASCII_US, OSTRING_TO_OUSTRING_CVTFLAGS );
+ OSL_ASSERT(pVariant != nullptr);
+ }
- ret = rtl_locale_register( pLanguage->buffer, pCountry ? pCountry->buffer : c_locale + 1, pVariant ? pVariant->buffer : c_locale + 1 );
+ ret = rtl_locale_register( pLanguage->buffer, pCountry ? pCountry->buffer : u"", pVariant ? pVariant->buffer : u"" );
- if (pVariant) rtl_uString_release(pVariant);
- if (pCountry) rtl_uString_release(pCountry);
- if (pLanguage) rtl_uString_release(pLanguage);
+ if (pVariant) rtl_uString_release(pVariant);
+ if (pCountry) rtl_uString_release(pCountry);
+ if (pLanguage) rtl_uString_release(pLanguage);
- return ret;
- }
- else
- return rtl_locale_register( c_locale, c_locale + 1, c_locale + 1 );
+ return ret;
}
#if defined(LINUX) || defined(__sun) || defined(NETBSD) || \