summaryrefslogtreecommitdiff
path: root/i18npool
diff options
context:
space:
mode:
authorEike Rathke <erack@redhat.com>2012-11-20 15:07:35 +0100
committerEike Rathke <erack@redhat.com>2012-11-20 15:08:47 +0100
commitb134b6dd76843ba4423006bc22ecd527e98e683a (patch)
tree602770825ccbfca349efc810c649d64310e85c16 /i18npool
parentd5d7232fb5eac4a449cd35ab605075a30c7324d3 (diff)
slowly stabbing MsLangId::convert...() to death
Change-Id: I0134593f8ba664b7a8e8a14f54485b96b749418d
Diffstat (limited to 'i18npool')
-rw-r--r--i18npool/inc/i18npool/mslangid.hxx195
-rw-r--r--i18npool/source/isolang/isolang.cxx122
-rw-r--r--i18npool/source/isolang/mslangid.cxx24
-rw-r--r--i18npool/source/languagetag/languagetag.cxx8
4 files changed, 91 insertions, 258 deletions
diff --git a/i18npool/inc/i18npool/mslangid.hxx b/i18npool/inc/i18npool/mslangid.hxx
index 120d9c6313d4..eba15ad944d9 100644
--- a/i18npool/inc/i18npool/mslangid.hxx
+++ b/i18npool/inc/i18npool/mslangid.hxx
@@ -26,20 +26,10 @@
#include "i18npool/lang.h"
#include <com/sun/star/lang/Locale.hpp>
-// 0 := normal usage
-// 1 := force LanguageTag and make all conversion functions private to make the
-// compiler bail out
-#define I18NPOOL_FORCE_LANGUAGETAG 0
-
/** Methods related to Microsoft language IDs. For details about MS-LANGIDs
please see lang.h */
class I18NISOLANG_DLLPUBLIC MsLangId
{
-
-#if I18NPOOL_FORCE_LANGUAGETAG
- friend class LanguageTag;
-#endif
-
public:
/// Create a LangID from a primary and a sublanguage.
@@ -93,73 +83,6 @@ public:
static LanguageType getRealLanguage( LanguageType nLang );
-#if I18NPOOL_FORCE_LANGUAGETAG
-private:
-#endif
-
- /** @short: Convert a LanguageType to a Locale, resolving LANGUAGE_SYSTEM.
-
- @ATTENTION: A round trip convertLanguageToLocale(
- convertLocaleToLanguage( ...)) is NOT possible because this
- method substitutes LANGUAGE_SYSTEM and the like. If round-trip
- is desired, you MUST use convertLanguageToLocale( ..., false)
- instead.
- */
- static void convertLanguageToLocale( LanguageType nLang,
- ::com::sun::star::lang::Locale & rLocale );
-
-
- /** @short: Convert a LanguageType to a Locale with handling of
- getRealLanguage().
-
- @descr: If bResolveSystem==true don't use to convert a Language to a
- Locale for file storage because it substitutes LANGUAGE_SYSTEM
- and LANGUAGE_NONE and similar, use only at runtime! If
- bResolveSystem==false a LANGUAGE_SYSTEM results in an empty
- Locale.
-
- @ATTENTION: A round trip convertLanguageToLocale(
- convertLocaleToLanguage( ...)) using the default parameter is
- NOT possible because this method
- substitutes LANGUAGE_SYSTEM and the like. If round-trip is
- desired, you MUST use convertLanguageToLocale( ..., false)
- instead.
- */
- static ::com::sun::star::lang::Locale convertLanguageToLocale(
- LanguageType nLang, bool bResolveSystem = true );
-
-
- /** Convert a Locale to a LanguageType with handling of an empty language
- name designating the SYSTEM language.
- */
- static LanguageType convertLocaleToLanguage( const ::com::sun::star::lang::Locale & rLocale );
-
-
- /** Convert a LanguageType to a Locale, resolving LANGUAGE_SYSTEM, falling
- back to a default locale if no exact match was found.
- */
- static ::com::sun::star::lang::Locale convertLanguageToLocaleWithFallback( LanguageType nLang );
-
-
- /** Convert a Locale to a LanguageType with handling of an empty language
- name designating the SYSTEM language, falling back to a default locale
- if no exact match was found.
- */
- static LanguageType convertLocaleToLanguageWithFallback(
- const ::com::sun::star::lang::Locale & rLocale );
-
-
- /** To be used only by LanguageTag. */
- I18NISOLANG_DLLPRIVATE static LanguageType lookupFallbackLanguage( LanguageType nLang );
-
- /** To be used only by LanguageTag. */
- I18NISOLANG_DLLPRIVATE static ::com::sun::star::lang::Locale lookupFallbackLocale(
- const ::com::sun::star::lang::Locale & rLocale );
-
-
-#if I18NPOOL_FORCE_LANGUAGETAG
-public:
-#endif
// TODO: refactor to LanguageTag? Used only in
// i18npool/source/localedata/localedata.cxx
@@ -170,50 +93,12 @@ public:
static ::com::sun::star::lang::Locale getFallbackLocale(
const ::com::sun::star::lang::Locale & rLocale );
-#if I18NPOOL_FORCE_LANGUAGETAG
-private:
-#endif
-
- // -----------------------------
- // - ConvertLanguageToIsoNames -
- // -----------------------------
-
- static void convertLanguageToIsoNames( LanguageType nLang,
- rtl::OUString& rLangStr, rtl::OUString& rCountry );
- static void convertLanguageToIsoNames( LanguageType nLang,
- rtl::OString& rLangStr, rtl::OString& rCountry );
- static rtl::OUString convertLanguageToIsoString( LanguageType nLang,
- sal_Unicode cSep = '-' );
- static rtl::OString convertLanguageToIsoByteString( LanguageType nLang,
- sal_Char cSep = '-' );
-
- // -----------------------------
- // - ConvertIsoNamesToLanguage -
- // -----------------------------
-
- static LanguageType convertIsoNamesToLanguage( const rtl::OUString& rLang,
- const rtl::OUString& rCountry );
- static LanguageType convertIsoNamesToLanguage( const rtl::OString& rLang,
- const rtl::OString& rCountry );
- static LanguageType convertIsoStringToLanguage(
- const rtl::OUString& rString, sal_Unicode cSep = '-' );
-
-#if I18NPOOL_FORCE_LANGUAGETAG
-public:
-#endif
+
// TODO: refactor to LanguageTag, used only in
// i18npool/source/isolang/inunx.cxx to convert Unix locale string
static LanguageType convertUnxByteStringToLanguage( const rtl::OString& rString );
-#if I18NPOOL_FORCE_LANGUAGETAG
-private:
-#endif
-
-
-#if I18NPOOL_FORCE_LANGUAGETAG
-public:
-#endif
static LanguageType resolveSystemLanguageByScriptType( LanguageType nLang, sal_Int16 nType );
@@ -308,6 +193,79 @@ public:
// ---------------------------------------------------------------------------
+ /** Encapsulated conversion methods used by LanguageTag and conversions,
+ not to be used by anything else.
+ */
+ class Conversion
+ {
+ private:
+
+ friend class LanguageTag;
+
+ friend ::com::sun::star::lang::Locale MsLangId::getFallbackLocale(
+ const ::com::sun::star::lang::Locale & rLocale );
+
+ friend LanguageType MsLangId::convertUnxByteStringToLanguage(
+ const rtl::OString& rString );
+
+
+ /** Convert a Locale to a LanguageType with handling of an empty
+ language name designating LANGUAGE_SYSTEM.
+ */
+ I18NISOLANG_DLLPRIVATE static LanguageType convertLocaleToLanguage(
+ const ::com::sun::star::lang::Locale & rLocale );
+
+ /** Used by convertLocaleToLanguage(Locale) */
+ I18NISOLANG_DLLPRIVATE static LanguageType convertIsoNamesToLanguage(
+ const rtl::OUString& rLang, const rtl::OUString& rCountry );
+
+
+ /** Used by convertUnxByteStringToLanguage(OString) */
+ I18NISOLANG_DLLPRIVATE static LanguageType convertIsoNamesToLanguage(
+ const rtl::OString& rLang, const rtl::OString& rCountry );
+
+
+ /** Convert a LanguageType to a Locale.
+
+ @param bResolveSystem
+ If bResolveSystem==true, a LANGUAGE_SYSTEM is resolved.
+ If bResolveSystem==false, a LANGUAGE_SYSTEM results in an
+ empty Locale.
+ */
+ I18NISOLANG_DLLPRIVATE static ::com::sun::star::lang::Locale convertLanguageToLocale(
+ LanguageType nLang, bool bResolveSystem );
+
+ /** Convert a LanguageType to a Locale, resolving LANGUAGE_SYSTEM.
+
+ Used by convertLanguageToLocale(LanguageType,bool)
+ */
+ I18NISOLANG_DLLPRIVATE static void convertLanguageToLocale(
+ LanguageType nLang, ::com::sun::star::lang::Locale & rLocale );
+
+ /** Used by convertLanguageToLocale(LanguageType,Locale) */
+ I18NISOLANG_DLLPRIVATE static void convertLanguageToIsoNames(
+ LanguageType nLang, rtl::OUString& rLangStr, rtl::OUString& rCountry );
+
+
+ I18NISOLANG_DLLPRIVATE static LanguageType lookupFallbackLanguage( LanguageType nLang );
+
+ I18NISOLANG_DLLPRIVATE static ::com::sun::star::lang::Locale lookupFallbackLocale(
+ const ::com::sun::star::lang::Locale & rLocale );
+
+
+ /** Convert a LanguageType to a Locale, resolving LANGUAGE_SYSTEM,
+ falling back to a default locale if no exact match was found.
+
+ Used by getFallbackLocale(Locale)
+ */
+ I18NISOLANG_DLLPRIVATE static ::com::sun::star::lang::Locale convertLanguageToLocaleWithFallback(
+ LanguageType nLang );
+
+ /** Used by convertLanguageToLocaleWithFallback(LanguageType) */
+ I18NISOLANG_DLLPRIVATE static ::com::sun::star::lang::Locale lookupFallbackLocale(
+ LanguageType nLang );
+ };
+
private:
static LanguageType nConfiguredSystemLanguage;
@@ -323,11 +281,6 @@ private:
// Substitute LANGUAGE_SYSTEM for LANGUAGE_SYSTEM_DEFAULT and
// LANGUAGE_PROCESS_OR_USER_DEFAULT, other values aren't touched.
I18NISOLANG_DLLPRIVATE static inline LanguageType simplifySystemLanguages( LanguageType nLang );
-
- // Several locale lookups with fall-back
- I18NISOLANG_DLLPRIVATE static LanguageType lookupFallbackLanguage(
- const ::com::sun::star::lang::Locale & rLocale );
- I18NISOLANG_DLLPRIVATE static ::com::sun::star::lang::Locale lookupFallbackLocale( LanguageType nLang );
};
diff --git a/i18npool/source/isolang/isolang.cxx b/i18npool/source/isolang/isolang.cxx
index 1605d9ef5a43..69e97dd6fc46 100644
--- a/i18npool/source/isolang/isolang.cxx
+++ b/i18npool/source/isolang/isolang.cxx
@@ -609,7 +609,7 @@ static IsoLangOtherEntry const aImplOtherEntries[] =
// =======================================================================
// static
-void MsLangId::convertLanguageToIsoNames( LanguageType nLang,
+void MsLangId::Conversion::convertLanguageToIsoNames( LanguageType nLang,
rtl::OUString& rLangStr, rtl::OUString& rCountry )
{
if ( nLang == LANGUAGE_SYSTEM )
@@ -652,48 +652,6 @@ void MsLangId::convertLanguageToIsoNames( LanguageType nLang,
// -----------------------------------------------------------------------
-// static
-void MsLangId::convertLanguageToIsoNames( LanguageType nLang,
- rtl::OString& rLangStr, rtl::OString& rCountry )
-{
- if ( nLang == LANGUAGE_SYSTEM )
- nLang = MsLangId::getSystemLanguage();
-
- // Search for LangID (in this table we find only defined ISO combinations)
- const IsoLangEntry* pEntry = aImplIsoLangEntries;
- do
- {
- if ( pEntry->mnLang == nLang )
- { // avoid embedded \0 warning
- rLangStr = rtl::OString( static_cast< const char* >( pEntry->maLangStr ));
- rCountry = rtl::OString( static_cast< const char* >( pEntry->maCountry ));
- return;
- }
- ++pEntry;
- }
- while ( pEntry->mnLang != LANGUAGE_DONTKNOW );
-
- // Search for LangID if we didn't find a specific ISO combination.
- // All entries in this table are allowed for mime specifications,
- // but not defined ISO combinations.
- const IsoLangNoneStdEntry* pNoneStdEntry = aImplIsoNoneStdLangEntries;
- do
- {
- if ( pNoneStdEntry->mnLang == nLang )
- { // avoid embedded \0 warning
- rLangStr = rtl::OString( static_cast< const char* >( pNoneStdEntry->maLangStr ));
- rCountry = rtl::OString( static_cast< const char* >( pNoneStdEntry->maCountry ));
- return;
- }
- ++pNoneStdEntry;
- }
- while ( pNoneStdEntry->mnLang != LANGUAGE_DONTKNOW );
-
- // not found
- rLangStr = rtl::OString();
- rCountry = rtl::OString();
-}
-
// -----------------------------------------------------------------------
static const MsLangId::IsoLangEntry & lcl_lookupFallbackEntry( LanguageType nLang )
@@ -749,14 +707,14 @@ static const MsLangId::IsoLangEntry & lcl_lookupFallbackEntry( LanguageType nLan
}
// static
-LanguageType MsLangId::lookupFallbackLanguage( LanguageType nLang )
+LanguageType MsLangId::Conversion::lookupFallbackLanguage( LanguageType nLang )
{
return lcl_lookupFallbackEntry( nLang).mnLang;
}
// static
-::com::sun::star::lang::Locale MsLangId::lookupFallbackLocale( LanguageType nLang )
+::com::sun::star::lang::Locale MsLangId::Conversion::lookupFallbackLocale( LanguageType nLang )
{
const MsLangId::IsoLangEntry& rEntry = lcl_lookupFallbackEntry( nLang);
return ::com::sun::star::lang::Locale(
@@ -829,16 +787,9 @@ static const MsLangId::IsoLangEntry & lcl_lookupFallbackEntry(
return aLastResortFallbackEntry;
}
-// static
-LanguageType MsLangId::lookupFallbackLanguage(
- const ::com::sun::star::lang::Locale & rLocale )
-{
- return lcl_lookupFallbackEntry( rLocale).mnLang;
-}
-
// static
-::com::sun::star::lang::Locale MsLangId::lookupFallbackLocale(
+::com::sun::star::lang::Locale MsLangId::Conversion::lookupFallbackLocale(
const ::com::sun::star::lang::Locale & rLocale )
{
const MsLangId::IsoLangEntry& rEntry = lcl_lookupFallbackEntry( rLocale);
@@ -848,49 +799,10 @@ LanguageType MsLangId::lookupFallbackLanguage(
rtl::OUString());
}
-// -----------------------------------------------------------------------
-
-// static
-rtl::OUString MsLangId::convertLanguageToIsoString( LanguageType nLang,
- sal_Unicode cSep )
-{
- rtl::OUString aLangStr;
- rtl::OUString aCountry;
- convertLanguageToIsoNames( nLang, aLangStr, aCountry );
- if ( !aCountry.isEmpty() )
- {
- rtl::OUStringBuffer aBuf( aLangStr);
- aBuf.append( cSep );
- aBuf.append( aCountry );
- return aBuf.makeStringAndClear();
- }
- else
- return aLangStr;
-}
-
-// -----------------------------------------------------------------------
-
-// static
-rtl::OString MsLangId::convertLanguageToIsoByteString( LanguageType nLang,
- sal_Char cSep )
-{
- rtl::OString aLangStr;
- rtl::OString aCountry;
- convertLanguageToIsoNames( nLang, aLangStr, aCountry );
- if ( !aCountry.isEmpty() )
- {
- rtl::OStringBuffer aBuf( aLangStr);
- aBuf.append( cSep );
- aBuf.append( aCountry );
- return aBuf.makeStringAndClear();
- }
- return aLangStr;
-}
-
// =======================================================================
// static
-LanguageType MsLangId::convertIsoNamesToLanguage( const rtl::OUString& rLang,
+LanguageType MsLangId::Conversion::convertIsoNamesToLanguage( const rtl::OUString& rLang,
const rtl::OUString& rCountry )
{
// language is lower case in table
@@ -992,7 +904,7 @@ LanguageType MsLangId::convertIsoNamesToLanguage( const rtl::OUString& rLang,
// -----------------------------------------------------------------------
// static
-LanguageType MsLangId::convertIsoNamesToLanguage( const rtl::OString& rLang,
+LanguageType MsLangId::Conversion::convertIsoNamesToLanguage( const rtl::OString& rLang,
const rtl::OString& rCountry )
{
rtl::OUString aLang = OStringToOUString( rLang, RTL_TEXTENCODING_ASCII_US);
@@ -1002,26 +914,6 @@ LanguageType MsLangId::convertIsoNamesToLanguage( const rtl::OString& rLang,
// -----------------------------------------------------------------------
-// static
-LanguageType MsLangId::convertIsoStringToLanguage(
- const rtl::OUString& rString, sal_Unicode cSep )
-{
- rtl::OUString aLang;
- rtl::OUString aCountry;
- sal_Int32 nSepPos = rString.indexOf( cSep );
- if ( nSepPos >= 0 )
- {
- aLang = rString.copy( 0, nSepPos );
- aCountry = rString.copy( nSepPos+1 );
- }
- else
- aLang = rString;
-
- return convertIsoNamesToLanguage( aLang, aCountry );
-}
-
-// -----------------------------------------------------------------------
-
struct IsoLangGLIBCModifiersEntry
{
LanguageType mnLang;
@@ -1102,7 +994,7 @@ LanguageType MsLangId::convertUnxByteStringToLanguage(
while ( pGLIBCModifiersEntry->mnLang != LANGUAGE_DONTKNOW );
}
- return convertIsoNamesToLanguage( aLang, aCountry );
+ return Conversion::convertIsoNamesToLanguage( aLang, aCountry );
}
// -----------------------------------------------------------------------
diff --git a/i18npool/source/isolang/mslangid.cxx b/i18npool/source/isolang/mslangid.cxx
index 887b88b7fcf9..405ce2993704 100644
--- a/i18npool/source/isolang/mslangid.cxx
+++ b/i18npool/source/isolang/mslangid.cxx
@@ -142,7 +142,7 @@ LanguageType MsLangId::resolveSystemLanguageByScriptType( LanguageType nLang, sa
}
// static
-void MsLangId::convertLanguageToLocale( LanguageType nLang,
+void MsLangId::Conversion::convertLanguageToLocale( LanguageType nLang,
::com::sun::star::lang::Locale & rLocale )
{
if (!rLocale.Variant.isEmpty())
@@ -152,7 +152,7 @@ void MsLangId::convertLanguageToLocale( LanguageType nLang,
// static
-::com::sun::star::lang::Locale MsLangId::convertLanguageToLocale(
+::com::sun::star::lang::Locale MsLangId::Conversion::convertLanguageToLocale(
LanguageType nLang, bool bResolveSystem )
{
::com::sun::star::lang::Locale aLocale;
@@ -171,7 +171,7 @@ void MsLangId::convertLanguageToLocale( LanguageType nLang,
// static
-LanguageType MsLangId::convertLocaleToLanguage(
+LanguageType MsLangId::Conversion::convertLocaleToLanguage(
const ::com::sun::star::lang::Locale& rLocale )
{
// empty language => LANGUAGE_SYSTEM
@@ -188,19 +188,7 @@ LanguageType MsLangId::convertLocaleToLanguage(
// static
-LanguageType MsLangId::convertLocaleToLanguageWithFallback(
- const ::com::sun::star::lang::Locale & rLocale )
-{
- // empty language => LANGUAGE_SYSTEM
- if (rLocale.Language.isEmpty())
- return lookupFallbackLanguage( LANGUAGE_SYSTEM);
-
- return lookupFallbackLanguage( rLocale);
-}
-
-
-// static
-::com::sun::star::lang::Locale MsLangId::convertLanguageToLocaleWithFallback(
+::com::sun::star::lang::Locale MsLangId::Conversion::convertLanguageToLocaleWithFallback(
LanguageType nLang )
{
return lookupFallbackLocale( MsLangId::getRealLanguage( nLang));
@@ -213,9 +201,9 @@ LanguageType MsLangId::convertLocaleToLanguageWithFallback(
{
// empty language => LANGUAGE_SYSTEM
if (rLocale.Language.isEmpty())
- return convertLanguageToLocaleWithFallback( LANGUAGE_SYSTEM);
+ return Conversion::convertLanguageToLocaleWithFallback( LANGUAGE_SYSTEM);
- return lookupFallbackLocale( rLocale);
+ return Conversion::lookupFallbackLocale( rLocale);
}
// static
diff --git a/i18npool/source/languagetag/languagetag.cxx b/i18npool/source/languagetag/languagetag.cxx
index 1dcc6bfc2373..07b494f03106 100644
--- a/i18npool/source/languagetag/languagetag.cxx
+++ b/i18npool/source/languagetag/languagetag.cxx
@@ -451,7 +451,7 @@ void LanguageTag::convertLocaleToLang()
/* FIXME: this is temporary until code base is converted to not use
* MsLangId::convert...() anymore. After that, proper new method has to
* be implemented to allow ISO639_LANGUAGE_TAG and sript tag and such. */
- mnLangID = MsLangId::convertLocaleToLanguage( maLocale);
+ mnLangID = MsLangId::Conversion::convertLocaleToLanguage( maLocale);
}
mbInitializedLangID = true;
}
@@ -506,7 +506,7 @@ void LanguageTag::convertLangToLocale()
* MsLangId::convert...() anymore. After that, proper new method has to be
* implemented to allow ISO639_LANGUAGE_TAG and script tag and such. */
// Resolve system here!
- maLocale = MsLangId::convertLanguageToLocale( mnLangID, true);
+ maLocale = MsLangId::Conversion::convertLanguageToLocale( mnLangID, true);
mbInitializedLocale = true;
}
@@ -820,14 +820,14 @@ LanguageTag & LanguageTag::makeFallback()
if (mbInitializedLangID)
{
LanguageType nLang1 = getLanguageType();
- LanguageType nLang2 = MsLangId::lookupFallbackLanguage( nLang1);
+ LanguageType nLang2 = MsLangId::Conversion::lookupFallbackLanguage( nLang1);
if (nLang1 != nLang2)
reset( nLang2);
}
else
{
const lang::Locale& rLocale1 = getLocale();
- lang::Locale aLocale2( MsLangId::lookupFallbackLocale( rLocale1));
+ lang::Locale aLocale2( MsLangId::Conversion::lookupFallbackLocale( rLocale1));
if ( rLocale1.Language != aLocale2.Language ||
rLocale1.Country != aLocale2.Country ||
rLocale1.Variant != aLocale2.Variant)