i18npool/inc/i18npool/languagetag.hxx | 8 i18npool/source/languagetag/languagetag.cxx | 22 ++ sal/Package_inc.mk | 1 sal/inc/rtl/locale.hxx | 250 ---------------------------- sal/qa/rtl/locale/rtl_locale.cxx | 60 +++--- sal/qa/rtl_strings/rtl_old_testowstring.cxx | 2 vcl/generic/fontmanager/fontconfig.cxx | 8 vcl/source/app/brand.cxx | 14 - 8 files changed, 70 insertions(+), 295 deletions(-)
New commits: commit 73bda5058bcef6be9a3185aa46375c7b147ffa22 Author: Eike Rathke <[email protected]> Date: Fri Nov 30 17:26:32 2012 +0100 ditched rtl::OLocale Change-Id: I3f4a09c82df1bc71759331705c502320f973d4bb diff --git a/sal/Package_inc.mk b/sal/Package_inc.mk index fa4246d..dff0229 100644 --- a/sal/Package_inc.mk +++ b/sal/Package_inc.mk @@ -77,7 +77,6 @@ $(eval $(call gb_Package_add_file,sal_inc,inc/rtl/crc.h,rtl/crc.h)) $(eval $(call gb_Package_add_file,sal_inc,inc/rtl/digest.h,rtl/digest.h)) $(eval $(call gb_Package_add_file,sal_inc,inc/rtl/instance.hxx,rtl/instance.hxx)) $(eval $(call gb_Package_add_file,sal_inc,inc/rtl/locale.h,rtl/locale.h)) -$(eval $(call gb_Package_add_file,sal_inc,inc/rtl/locale.hxx,rtl/locale.hxx)) $(eval $(call gb_Package_add_file,sal_inc,inc/rtl/logfile.h,rtl/logfile.h)) $(eval $(call gb_Package_add_file,sal_inc,inc/rtl/logfile.hxx,rtl/logfile.hxx)) $(eval $(call gb_Package_add_file,sal_inc,inc/rtl/malformeduriexception.hxx,rtl/malformeduriexception.hxx)) diff --git a/sal/inc/rtl/locale.hxx b/sal/inc/rtl/locale.hxx deleted file mode 100644 index 9fb4960..0000000 --- a/sal/inc/rtl/locale.hxx +++ /dev/null @@ -1,250 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* - * This file is part of the LibreOffice project. - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. - * - * This file incorporates work covered by the following license notice: - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed - * with this work for additional information regarding copyright - * ownership. The ASF licenses this file to you under the Apache - * License, Version 2.0 (the "License"); you may not use this file - * except in compliance with the License. You may obtain a copy of - * the License at http://www.apache.org/licenses/LICENSE-2.0 . - */ - -#ifndef _RTL_LOCALE_HXX_ -#define _RTL_LOCALE_HXX_ - -#include <rtl/locale.h> -#include <rtl/ustring.hxx> - -#ifdef __cplusplus - -namespace rtl -{ - -/** - A <code>OLocale</code> object represents a specific geographical, political, - or cultural region. An operation that requires a <code>OLocale</code> to perform - its task is called <em>locale-sensitive</em> and uses the <code>OLocale</code> - to tailor information for the user. For example, displaying a number - is a locale-sensitive operation--the number should be formatted - according to the customs/conventions of the user's native country, - region, or culture. - - <P> - You create a <code>OLocale</code> object using one of the two constructors in - this class: - <blockquote> - <pre> - OLocale(String language, String country) - OLocale(String language, String country, String variant) - </pre> - </blockquote> - The first argument to both constructors is a valid <STRONG>ISO - Language Code.</STRONG> These codes are the lower-case two-letter - codes as defined by ISO-639. - You can find a full list of these codes at a number of sites, such as: - <BR><a href ="http://www.ics.uci.edu/pub/ietf/http/related/iso639.txt"> - <code>http://www.ics.uci.edu/pub/ietf/http/related/iso639.txt</code></a> - - <P> - The second argument to both constructors is a valid <STRONG>ISO Country - Code.</STRONG> These codes are the upper-case two-letter codes - as defined by ISO-3166. - You can find a full list of these codes at a number of sites, such as: - <BR><a href="http://www.chemie.fu-berlin.de/diverse/doc/ISO_3166.html"> - <code>http://www.chemie.fu-berlin.de/diverse/doc/ISO_3166.html</code></a> - - <P> - The second constructor requires a third argument--the <STRONG>Variant.</STRONG> - The Variant codes are vendor and browser-specific. - For example, use WIN for Windows, MAC for Macintosh, and POSIX for POSIX. - Where there are two variants, separate them with an underscore, and - put the most important one first. For - example, a Traditional Spanish collation might be referenced, with - "ES", "ES", "Traditional_WIN". - - <P> - Because a <code>OLocale</code> object is just an identifier for a region, - no validity check is performed when you construct a <code>OLocale</code>. - If you want to see whether particular resources are available for the - <code>OLocale</code> you construct, you must query those resources. For - example, ask the <code>NumberFormat</code> for the locales it supports - using its <code>getAvailableLocales</code> method. - <BR><STRONG>Note:</STRONG> When you ask for a resource for a particular - locale, you get back the best available match, not necessarily - precisely what you asked for. For more information, look at - <a href="java.util.ResourceBundle.html"><code>ResourceBundle</code></a>. - - <P> - The <code>OLocale</code> class provides a number of convenient constants - that you can use to create <code>OLocale</code> objects for commonly used - locales. For example, the following creates a <code>OLocale</code> object - for the United States: - <blockquote> - <pre> - OLocale.US - </pre> - </blockquote> - - <P> - Once you've created a <code>OLocale</code> you can query it for information about - itself. Use <code>getCountry</code> to get the ISO Country Code and - <code>getLanguage</code> to get the ISO Language Code. You can - use <code>getDisplayCountry</code> to get the - name of the country suitable for displaying to the user. Similarly, - you can use <code>getDisplayLanguage</code> to get the name of - the language suitable for displaying to the user. Interestingly, - the <code>getDisplayXXX</code> methods are themselves locale-sensitive - and have two versions: one that uses the default locale and one - that uses the locale specified as an argument. - - <P> - The JDK provides a number of classes that perform locale-sensitive - operations. For example, the <code>NumberFormat</code> class formats - numbers, currency, or percentages in a locale-sensitive manner. Classes - such as <code>NumberFormat</code> have a number of convenience methods - for creating a default object of that type. For example, the - <code>NumberFormat</code> class provides these three convenience methods - for creating a default <code>NumberFormat</code> object: - <blockquote> - <pre> - NumberFormat.getInstance() - NumberFormat.getCurrencyInstance() - NumberFormat.getPercentInstance() - </pre> - </blockquote> - These methods have two variants; one with an explicit locale - and one without; the latter using the default locale. - <blockquote> - <pre> - NumberFormat.getInstance(myLocale) - NumberFormat.getCurrencyInstance(myLocale) - NumberFormat.getPercentInstance(myLocale) - </pre> - </blockquote> - A <code>OLocale</code> is the mechanism for identifying the kind of object - (<code>NumberFormat</code>) that you would like to get. The locale is - <STRONG>just</STRONG> a mechanism for identifying objects, - <STRONG>not</STRONG> a container for the objects themselves. - - <P> - Each class that performs locale-sensitive operations allows you - to get all the available objects of that type. You can sift - through these objects by language, country, or variant, - and use the display names to present a menu to the user. - For example, you can create a menu of all the collation objects - suitable for a given language. Such classes must implement these - three class methods: - <blockquote> - <pre> - public static OLocale[] getAvailableLocales() - public static String getDisplayName(OLocale objectLocale, - OLocale displayLocale) - public static final String getDisplayName(OLocale objectLocale) - // getDisplayName will throw MissingResourceException if the locale - // is not one of the available locales. - </pre> - </blockquote> - */ -class OLocale -{ -public: - OLocale( rtl_Locale * locale ) - : pData( locale ) {} - - OLocale( const OLocale & obj) - : pData(obj.pData) {} - - OLocale & operator = ( const OLocale & obj) - { - pData = obj.pData; - return *this; - } - - /** - Construct a locale from language, country, variant. - @param language lowercase two-letter ISO-639 code. - @param country uppercase two-letter ISO-3166 code. - @param variant vendor and browser specific code. See class description. - */ - static OLocale registerLocale( const OUString & language, const OUString & country, - const OUString & variant ) - { - return rtl_locale_register( language.getStr(), country.getStr(), variant.getStr() ); - } - - /** - Construct a locale from language, country. - @param language lowercase two-letter ISO-639 code. - @param country uppercase two-letter ISO-3166 code. - */ - static OLocale registerLocale( const OUString & language, const OUString & country ) - { - return rtl_locale_register( language.getStr(), country.getStr(), NULL ); - } - - /** @deprecated - */ - static OLocale getDefault() { return rtl_locale_getDefault(); } - - /** @deprecated - */ - static void setDefault( const OUString & language, const OUString & country, - const OUString & variant ) - { rtl_locale_setDefault(language.getStr(), country.getStr(), variant.getStr()); } - - /** - Getter for programmatic name of field, - an lowercased two-letter ISO-639 code. - */ - OUString getLanguage() const { return pData->Language; } - - /** - Getter for programmatic name of field, - an uppercased two-letter ISO-3166 code. - */ - OUString getCountry() const { return pData->Country; } - - /** - Getter for programmatic name of field. - */ - OUString getVariant() const { return pData->Variant; } - - - /** - Returns the hash code of the locale This. - */ - sal_Int32 hashCode() const { return pData->HashCode; } - - sal_Bool operator == (const OLocale & obj ) const - { - return pData == obj.pData; - } - - rtl_Locale * getData() const { return pData; } - -private: - /** - Must be the first member in this class. OUString access this member with - *(rtl_Locale **)&locale. - */ - rtl_Locale * pData; - - OLocale() - : pData(rtl_locale_getDefault()) {} -}; - -} - -#endif /* __cplusplus */ -#endif /* _RTL_LOCALE_HXX_ */ - - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sal/qa/rtl/locale/rtl_locale.cxx b/sal/qa/rtl/locale/rtl_locale.cxx index 8a047ca..6607b76 100644 --- a/sal/qa/rtl/locale/rtl_locale.cxx +++ b/sal/qa/rtl/locale/rtl_locale.cxx @@ -19,7 +19,8 @@ #include <sal/types.h> #include <osl/thread.h> -#include <rtl/locale.hxx> +#include <rtl/locale.h> +#include <rtl/ustring.hxx> #include <cppunit/TestFixture.h> #include <cppunit/extensions/HelperMacros.h> @@ -30,7 +31,7 @@ namespace rtl_locale // default locale for test purpose void setDefaultLocale() { - rtl::OLocale::setDefault(rtl::OUString("de"), rtl::OUString("DE"), /* rtl::OUString() */ rtl::OUString("hochdeutsch") ); + rtl_locale_setDefault(rtl::OUString("de").getStr(), rtl::OUString("DE").getStr(), /* rtl::OUString() */ rtl::OUString("hochdeutsch").getStr() ); } class getDefault : public CppUnit::TestFixture @@ -61,9 +62,8 @@ public: void getDefault_001() { - // rtl::OLocale::setDefault(rtl::OUString("de"), rtl::OUString("DE"), rtl::OUString()); - rtl::OLocale aLocale = ::rtl::OLocale::getDefault(); - CPPUNIT_ASSERT_MESSAGE("locale must not null", aLocale.getData() != NULL); + rtl_Locale* pData = rtl_locale_getDefault(); + CPPUNIT_ASSERT_MESSAGE("locale must not null", pData != NULL); } // Change the following lines only, if you add, remove or rename @@ -95,9 +95,9 @@ public: // insert your test code here. void setDefault_001() { - rtl::OLocale::setDefault(rtl::OUString("en"), rtl::OUString("US"), rtl::OUString()); - rtl::OLocale aLocale = ::rtl::OLocale::getDefault(); - CPPUNIT_ASSERT_MESSAGE("locale must not null", aLocale.getData() != NULL); + rtl_locale_setDefault(rtl::OUString("en").getStr(), rtl::OUString("US").getStr(), rtl::OUString().getStr()); + rtl_Locale* pData = rtl_locale_getDefault(); + CPPUNIT_ASSERT_MESSAGE("locale must not null", pData != NULL); // be sure to not GPF } @@ -129,14 +129,14 @@ public: // insert your test code here. void getLanguage_001() { - rtl::OLocale aLocale = ::rtl::OLocale::getDefault(); - rtl::OUString suLanguage = aLocale.getLanguage(); + rtl_Locale* pData = rtl_locale_getDefault(); + rtl::OUString suLanguage = pData->Language; CPPUNIT_ASSERT_MESSAGE( "locale language must be 'de'", suLanguage == "de" ); } void getLanguage_002() { - rtl::OLocale aLocale = ::rtl::OLocale::getDefault(); - rtl::OUString suLanguage(rtl_locale_getLanguage(aLocale.getData()), SAL_NO_ACQUIRE); + rtl_Locale* pData = rtl_locale_getDefault(); + rtl::OUString suLanguage(rtl_locale_getLanguage(pData), SAL_NO_ACQUIRE); CPPUNIT_ASSERT_MESSAGE( "locale language must be 'de'", suLanguage == "de" ); } @@ -168,14 +168,14 @@ public: // insert your test code here. void getCountry_001() { - rtl::OLocale aLocale = ::rtl::OLocale::getDefault(); - rtl::OUString suCountry = aLocale.getCountry(); + rtl_Locale* pData = rtl_locale_getDefault(); + rtl::OUString suCountry = pData->Country; CPPUNIT_ASSERT_MESSAGE( "locale country must be 'DE'", suCountry == "DE" ); } void getCountry_002() { - rtl::OLocale aLocale = ::rtl::OLocale::getDefault(); - rtl::OUString suCountry(rtl_locale_getCountry(aLocale.getData()), SAL_NO_ACQUIRE); + rtl_Locale* pData = rtl_locale_getDefault(); + rtl::OUString suCountry(rtl_locale_getCountry(pData), SAL_NO_ACQUIRE); CPPUNIT_ASSERT_MESSAGE( "locale country must be 'DE'", suCountry == "DE" ); } @@ -207,14 +207,14 @@ public: // insert your test code here. void getVariant_001() { - rtl::OLocale aLocale = ::rtl::OLocale::getDefault(); - rtl::OUString suVariant = aLocale.getVariant(); + rtl_Locale* pData = rtl_locale_getDefault(); + rtl::OUString suVariant = pData->Variant; CPPUNIT_ASSERT_MESSAGE( "locale variant must be 'hochdeutsch'", suVariant == "hochdeutsch" ); } void getVariant_002() { - rtl::OLocale aLocale = ::rtl::OLocale::getDefault(); - rtl::OUString suVariant(rtl_locale_getVariant(aLocale.getData()), SAL_NO_ACQUIRE); + rtl_Locale* pData = rtl_locale_getDefault(); + rtl::OUString suVariant(rtl_locale_getVariant(pData), SAL_NO_ACQUIRE); CPPUNIT_ASSERT_MESSAGE( "locale variant must be 'hochdeutsch'", suVariant == "hochdeutsch" ); } @@ -246,14 +246,14 @@ public: // insert your test code here. void hashCode_001() { - rtl::OLocale aLocale = ::rtl::OLocale::getDefault(); - sal_Int32 nHashCode = aLocale.hashCode(); + rtl_Locale* pData = rtl_locale_getDefault(); + sal_Int32 nHashCode = pData->HashCode; CPPUNIT_ASSERT_MESSAGE("locale hashcode must be 3831", nHashCode != 0); } void hashCode_002() { - rtl::OLocale aLocale = ::rtl::OLocale::getDefault(); - sal_Int32 nHashCode = rtl_locale_hashCode(aLocale.getData()); + rtl_Locale* pData = rtl_locale_getDefault(); + sal_Int32 nHashCode = rtl_locale_hashCode(pData); CPPUNIT_ASSERT_MESSAGE("locale hashcode must be 3831", nHashCode != 0); } @@ -285,21 +285,21 @@ public: // insert your test code here. void equals_001() { - rtl::OLocale aLocale1 = rtl::OLocale::registerLocale(rtl::OUString("en"), rtl::OUString("US"), rtl::OUString()); - rtl::OLocale aLocale2 = rtl::OLocale::registerLocale(rtl::OUString("en"), rtl::OUString("US")); + rtl_Locale* pData1 = rtl_locale_register(rtl::OUString("en").getStr(), rtl::OUString("US").getStr(), rtl::OUString().getStr()); + rtl_Locale* pData2 = rtl_locale_register(rtl::OUString("en").getStr(), rtl::OUString("US").getStr(), rtl::OUString().getStr()); sal_Bool bLocaleAreEqual = sal_False; - bLocaleAreEqual = (aLocale1 == aLocale2); + bLocaleAreEqual = (pData1 == pData2); CPPUNIT_ASSERT_MESSAGE("check operator ==()", bLocaleAreEqual == sal_True); } void equals_002() { - rtl::OLocale aLocale1 = rtl::OLocale::registerLocale(rtl::OUString("en"), rtl::OUString("US"), rtl::OUString()); - rtl::OLocale aLocale2 = rtl::OLocale::registerLocale(rtl::OUString("en"), rtl::OUString("US")); + rtl_Locale* pData1 = rtl_locale_register(rtl::OUString("en").getStr(), rtl::OUString("US").getStr(), rtl::OUString().getStr()); + rtl_Locale* pData2 = rtl_locale_register(rtl::OUString("en").getStr(), rtl::OUString("US").getStr(), rtl::OUString().getStr()); - sal_Int32 nEqual = rtl_locale_equals(aLocale1.getData(), aLocale2.getData()); + sal_Int32 nEqual = rtl_locale_equals(pData1, pData2); CPPUNIT_ASSERT(nEqual != 0); } diff --git a/sal/qa/rtl_strings/rtl_old_testowstring.cxx b/sal/qa/rtl_strings/rtl_old_testowstring.cxx index 207a7d9..92a0e14 100644 --- a/sal/qa/rtl_strings/rtl_old_testowstring.cxx +++ b/sal/qa/rtl_strings/rtl_old_testowstring.cxx @@ -33,8 +33,6 @@ #include <rtl/string.hxx> -#include <rtl/locale.hxx> - #include <testshl/simpleheader.hxx> #define TEST_ENSURE(c, m) CPPUNIT_ASSERT_MESSAGE((m), (c)) diff --git a/vcl/generic/fontmanager/fontconfig.cxx b/vcl/generic/fontmanager/fontconfig.cxx index 8270585..f5fe7d8 100644 --- a/vcl/generic/fontmanager/fontconfig.cxx +++ b/vcl/generic/fontmanager/fontconfig.cxx @@ -283,9 +283,9 @@ namespace { class localizedsorter { - rtl::OLocale maLoc; + LanguageTag maLoc; public: - localizedsorter(rtl_Locale* pLoc) : maLoc(pLoc) {} + localizedsorter(const LanguageTag& rLanguageTag) : maLoc(rLanguageTag) {} FcChar8* bestname(const std::vector<lang_and_element> &elements); }; @@ -380,9 +380,9 @@ FcResult FontCfgWrapper::LocalizedElementFromPattern(FcPattern* pPattern, FcChar } //possible to-do, sort by UILocale instead of process locale - rtl_Locale* pLoc; + rtl_Locale* pLoc = NULL; osl_getProcessLocale(&pLoc); - localizedsorter aSorter(pLoc); + localizedsorter aSorter( *pLoc); *element = aSorter.bestname(lang_and_elements); //if this element is a fontname, map the other names to this best-name diff --git a/vcl/source/app/brand.cxx b/vcl/source/app/brand.cxx index b24307e..74d5510 100644 --- a/vcl/source/app/brand.cxx +++ b/vcl/source/app/brand.cxx @@ -74,13 +74,12 @@ bool Application::LoadBrandBitmap (const char* pName, BitmapEx &rBitmap) rtl_Locale *pLoc = NULL; osl_getProcessLocale (&pLoc); - rtl::OLocale aLoc( pLoc ); + LanguageTag aLanguageTag( *pLoc); rtl::OUString aName = aBaseName + aPng; rtl::OUString aLocaleName = ( aBaseName + rtl::OUString("-") + - aLoc.getLanguage() + - rtl::OUString("_") + - aLoc.getCountry() + aPng ); + aLanguageTag.getBcp47() + + aPng ); return ( loadPng ("$BRAND_BASE_DIR/program/edition", aLocaleName, rBitmap) || loadPng ("$BRAND_BASE_DIR/program", aLocaleName, rBitmap) || @@ -97,13 +96,12 @@ vcl::RenderGraphicRasterizer Application::LoadBrandSVG (const char* pName) rtl_Locale *pLoc = NULL; osl_getProcessLocale (&pLoc); - rtl::OLocale aLoc( pLoc ); + LanguageTag aLanguageTag( *pLoc); rtl::OUString aName = aBaseName + aSvg; rtl::OUString aLocaleName = ( aBaseName + rtl::OUString("-") + - aLoc.getLanguage() + - rtl::OUString("_") + - aLoc.getCountry() + aSvg ); + aLanguageTag.getBcp47() + + aSvg ); vcl::RenderGraphicRasterizer aRasterizer = loadSvg ("$BRAND_BASE_DIR/program/edition", aLocaleName); if (!aRasterizer.GetRenderGraphic().IsEmpty()) commit 84f24288ee5883cd533985ee9ff66b60046bd4ac Author: Eike Rathke <[email protected]> Date: Fri Nov 30 16:16:20 2012 +0100 added rtl_Locale convenience ctor Change-Id: I195506b32a5cbf751ac90ad1ab13680097c8c428 diff --git a/i18npool/inc/i18npool/languagetag.hxx b/i18npool/inc/i18npool/languagetag.hxx index cefb0de..0b3eedd 100644 --- a/i18npool/inc/i18npool/languagetag.hxx +++ b/i18npool/inc/i18npool/languagetag.hxx @@ -16,6 +16,8 @@ #include <i18npool/i18npooldllapi.h> #include <i18npool/lang.h> +typedef struct _rtl_Locale rtl_Locale; // as in rtl/locale.h + /** Wrapper for liblangtag BCP 47 language tags, MS-LangIDs, locales and conversions in between. @@ -57,6 +59,12 @@ public: */ explicit LanguageTag( const rtl::OUString& rLanguage, const rtl::OUString& rCountry ); + /** Init LanguageTag with rtl_Locale. + + This is a convenience ctor. + */ + explicit LanguageTag( const rtl_Locale & rLocale ); + LanguageTag( const LanguageTag & rLanguageTag ); ~LanguageTag(); LanguageTag& operator=( const LanguageTag & rLanguageTag ); diff --git a/i18npool/source/languagetag/languagetag.cxx b/i18npool/source/languagetag/languagetag.cxx index 8ec730c..fc5b058 100644 --- a/i18npool/source/languagetag/languagetag.cxx +++ b/i18npool/source/languagetag/languagetag.cxx @@ -13,6 +13,7 @@ #include <rtl/bootstrap.hxx> #include <osl/file.hxx> #include <rtl/instance.hxx> +#include <rtl/locale.h> //#define erDEBUG @@ -229,6 +230,27 @@ LanguageTag::LanguageTag( const rtl::OUString& rLanguage, const rtl::OUString& r } +LanguageTag::LanguageTag( const rtl_Locale & rLocale ) + : + maLocale( rLocale.Language, rLocale.Country, rLocale.Variant), + mpImplLangtag( NULL), + mnLangID( LANGUAGE_DONTKNOW), + meIsValid( DECISION_DONTKNOW), + meIsIsoLocale( DECISION_DONTKNOW), + meIsIsoODF( DECISION_DONTKNOW), + mbSystemLocale( maLocale.Language.isEmpty()), + mbInitializedBcp47( false), + mbInitializedLocale( !mbSystemLocale), + mbInitializedLangID( false), + mbCachedLanguage( false), + mbCachedScript( false), + mbCachedCountry( false), + mbIsFallback( false) +{ + theDataRef::get().incRef(); +} + + LanguageTag::LanguageTag( const LanguageTag & rLanguageTag ) : maLocale( rLanguageTag.maLocale), _______________________________________________ Libreoffice-commits mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits
