LCOV - code coverage report
Current view: top level - libreoffice/solver/unxlngi6.pro/inc/comphelper - locale.hxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 1 1 100.0 %
Date: 2012-12-27 Functions: 1 1 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      11             :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12             :  *   contributor license agreements. See the NOTICE file distributed
      13             :  *   with this work for additional information regarding copyright
      14             :  *   ownership. The ASF licenses this file to you under the Apache
      15             :  *   License, Version 2.0 (the "License"); you may not use this file
      16             :  *   except in compliance with the License. You may obtain a copy of
      17             :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18             :  */
      19             : 
      20             : #ifndef _COMPHELPER_LOCALE_HXX_
      21             : #define _COMPHELPER_LOCALE_HXX_
      22             : 
      23             : #include <vector>
      24             : #include <rtl/ustring.hxx>
      25             : #include "comphelper/comphelperdllapi.h"
      26             : 
      27             : namespace comphelper{
      28             : 
      29             : /** @short  A Locale object represents a specific geographical, political, or cultural region.
      30             : 
      31             :     @descr  This Locale class can be used to:
      32             :             - provide the different parts of a Locale (Language, Country, Variant)
      33             :             - converting it from/to ISO formated string values (like e.g. "en-US")
      34             :             - provide some predefined (static) Locale objects
      35             :  */
      36       16657 : class COMPHELPER_DLLPUBLIC Locale
      37             : {
      38             :     public:
      39             : 
      40             :         /** @short seperates LANGUAGE and COUNTRY part of an ISO formated Locale. */
      41             :         static const sal_Unicode SEPERATOR_LC;
      42             : 
      43             :         /** @short seperates COUNTRY and VARIANT part of an ISO formated Locale. */
      44             :         static const sal_Unicode SEPERATOR_CV;
      45             : 
      46             :         /** @short seperates COUNTRY and VARIANT part of an ISO formated Locale.
      47             :             @descr Its true for some linux derivates only :-( */
      48             :         static const sal_Unicode SEPERATOR_CV_LINUX;
      49             : 
      50             :         /** @short some predefined Locale objects. */
      51             :         static const Locale EN_US();
      52             :         static const Locale X_DEFAULT();
      53             :         static const Locale X_NOTRANSLATE();
      54             : 
      55             :     //-------------------------------------------
      56             :     // types
      57             : 
      58             :     public:
      59             : 
      60             :         /** @short will be throw during convertion, if a Locale cant be interpreted. */
      61             :         struct MalFormedLocaleException
      62             :         {
      63             :             public:
      64             :                 ::rtl::OUString Message;
      65             : 
      66             :                 MalFormedLocaleException()
      67             :                 {}
      68             : 
      69             :                 MalFormedLocaleException(const ::rtl::OUString& sMessage)
      70             :                     : Message(sMessage)
      71             :                 {}
      72             :         };
      73             : 
      74             :     //-------------------------------------------
      75             :     // member
      76             : 
      77             :     private :
      78             : 
      79             :         //---------------------------------------
      80             :         /** @short  must be a valid ISO Language Code.
      81             : 
      82             :             @descr  These codes are the lower-case two-letter codes as defined by ISO-639.
      83             :                     You can find a full list of these codes at a number of sites, such as:
      84             :                     <BR><a href ="http://www.ics.uci.edu/pub/ietf/http/related/iso639.txt">
      85             :                     http://www.ics.uci.edu/pub/ietf/http/related/iso639.txt</a>
      86             :          */
      87             :         ::rtl::OUString m_sLanguage;
      88             : 
      89             :         //---------------------------------------
      90             :         /** @short  must be a valid ISO Country Code.
      91             :             @descr  These codes are the upper-case two-letter codes as defined by ISO-3166.
      92             :                     You can find a full list of these codes at a number of sites, such as:
      93             :                     <BR><a href="http://www.chemie.fu-berlin.de/diverse/doc/ISO_3166.html">
      94             :                     http://www.chemie.fu-berlin.de/diverse/doc/ISO_3166.html</a>
      95             :          */
      96             :         ::rtl::OUString m_sCountry;
      97             : 
      98             :         //---------------------------------------
      99             :         /** @short  Variant codes are vendor and browser-specific.
     100             :             @descr  For example, use WIN for Windows, MAC for Macintosh, and POSIX for POSIX.
     101             :                     Where there are two variants, separate them with an underscore, and
     102             :                     put the most important one first. For example, a Traditional Spanish collation
     103             :                     might be referenced, with "ES", "ES", "Traditional_WIN".
     104             :          */
     105             :         ::rtl::OUString m_sVariant;
     106             : 
     107             :     //-------------------------------------------
     108             :     // interface
     109             : 
     110             :     public :
     111             : 
     112             :         //---------------------------------------
     113             :         /** @short  needed by outside users!
     114             : 
     115             :             @descr  Otherwise it wouldnt be possible to use
     116             :                     any instance of such Locale static ...
     117             :          */
     118             :         Locale();
     119             : 
     120             :         //---------------------------------------
     121             :         /** @short      construct a Locale from an ISO formated string value.
     122             : 
     123             :             @seealso    fromISO()
     124             : 
     125             :             @param      sISO
     126             :                         an ISO formated string value, which can be parsed and
     127             :                         tokenized into a Lamnguage, Country and Variant part.
     128             : 
     129             :             @throw      MalFormedLocaleException
     130             :                         if conversion failed.
     131             :           */
     132             :         Locale(const ::rtl::OUString& sISO)
     133             :             throw(MalFormedLocaleException);
     134             : 
     135             :         //---------------------------------------
     136             :         /** @short      construct a Locale from language, country and variant.
     137             : 
     138             :             @seealso    setLanguage()
     139             :             @seealso    setCountry()
     140             :             @seealso    setVariant()
     141             : 
     142             :             @param      sLanguage
     143             :                         lowercase two-letter ISO-639 code.
     144             : 
     145             :             @param      sCountry
     146             :                         uppercase two-letter ISO-3166 code.
     147             : 
     148             :             @param      sVariant
     149             :                         vendor and browser specific code.
     150             :           */
     151             :         Locale(const ::rtl::OUString& sLanguage                   ,
     152             :                const ::rtl::OUString& sCountry                    ,
     153             :                const ::rtl::OUString& sVariant = ::rtl::OUString());
     154             : 
     155             :         //---------------------------------------
     156             :         /** @short  copy constructor.
     157             : 
     158             :             @param  aCopy
     159             :                     the copy object.
     160             :          */
     161             :         Locale(const Locale& aCopy);
     162             : 
     163             :         //---------------------------------------
     164             :         /** @short  returns the language code for this locale.
     165             : 
     166             :             @descr  That will either be the empty string or
     167             :                     a lowercase ISO 639 code.
     168             : 
     169             :             @return [string]
     170             :                     the language code.
     171             :          */
     172             :         ::rtl::OUString getLanguage() const;
     173             : 
     174             :         //---------------------------------------
     175             :         /** @short  returns the country/region code for this locale.
     176             : 
     177             :             @descr  That will either be the empty string or an
     178             :                     upercase ISO 3166 2-letter code.
     179             : 
     180             :             @return [string]
     181             :                     the country code.
     182             :          */
     183             :         ::rtl::OUString getCountry() const;
     184             : 
     185             :         //---------------------------------------
     186             :         /** @short  returns the variant code for this locale.
     187             : 
     188             :             @return [string]
     189             :                     the variant code.
     190             :          */
     191             :         ::rtl::OUString getVariant() const;
     192             : 
     193             :         //---------------------------------------
     194             :         /** @short  set the new language code for this locale.
     195             : 
     196             :             @descr  That will either be the empty string or
     197             :                     a lowercase ISO 639 code.
     198             : 
     199             :             @param  sLanguage
     200             :                     the language code.
     201             :          */
     202             :         void setLanguage(const ::rtl::OUString& sLanguage);
     203             : 
     204             :         //---------------------------------------
     205             :         /** @short  set the new country/region code for this locale.
     206             : 
     207             :             @descr  That will either be the empty string or an
     208             :                     upercase ISO 3166 2-letter code.
     209             : 
     210             :             @param  sCountry
     211             :                     the country code.
     212             :          */
     213             :         void setCountry(const ::rtl::OUString& sCountry);
     214             : 
     215             :         //---------------------------------------
     216             :         /** @short  set the new variant code for this locale.
     217             : 
     218             :             @param  sVariant
     219             :                     the variant code.
     220             :          */
     221             :         void setVariant(const ::rtl::OUString& sVariant);
     222             : 
     223             :         //---------------------------------------
     224             :         /** @short      take over new Locale informations.
     225             : 
     226             :             @seealso    Locale(const ::rtl::OUString& sISO)
     227             : 
     228             :             @param      sISO
     229             :                         an ISO formated string value, which can be parsed and
     230             :                         tokenized into a Lamnguage, Country and Variant part.
     231             :                         e.g. "en-US" or "en-US_WIN"
     232             : 
     233             :             @throw      MalFormedLocaleException
     234             :                         if conversion failed.
     235             :           */
     236             :         void fromISO(const ::rtl::OUString& sISO)
     237             :             throw(MalFormedLocaleException);
     238             : 
     239             :         //---------------------------------------
     240             :         /** @short  converts this Locale to an ISO formated string value.
     241             : 
     242             :             @descr  The different parts of this Locale will be assempled
     243             :                     e.g. to "en-US" or "en-US_WIN"
     244             : 
     245             :             @return [string]
     246             :                     the ISO formated string.
     247             :           */
     248             :         ::rtl::OUString toISO() const;
     249             : 
     250             :         //---------------------------------------
     251             :         /** @short  check, if two Locale objects are equals.
     252             : 
     253             :             @descr  All parts of a Locale (means Language, Country and Variant)
     254             :                     will be checked.
     255             : 
     256             :             @param  aComparable
     257             :                     the Locale object for compare.
     258             : 
     259             :             @return [boolean]
     260             :                     TRUE if both objects uses the same values for
     261             :                     Language, Country and Variant.
     262             :          */
     263             :         sal_Bool equals(const Locale& aComparable) const;
     264             : 
     265             :         //---------------------------------------
     266             :         /** @short  check, if two Locale objects
     267             :                     uses the same language.
     268             : 
     269             :             @descr  The Country and Variant parts of a Locale
     270             :                     wont be checked here.
     271             : 
     272             :             @return [boolean]
     273             :                     TRUE if both objects uses the same
     274             :                     Language value.
     275             :          */
     276             :         sal_Bool similar(const Locale& aComparable) const;
     277             : 
     278             :         //---------------------------------------
     279             :         /** @short      search for an equal or at least for a similar
     280             :                         Locale in a list of possible ones.
     281             : 
     282             :             @descr      First it searches for a Locale, which is equals
     283             :                         to the reference Locale.
     284             :                         (means: same Language, Country, Variant)
     285             : 
     286             :                         If the reference Locale couldnt be located, it will
     287             :                         tried again - but we are checking for "similar" Locales then.
     288             :                         (means: same Language)
     289             : 
     290             :                         If no similar Locale could be located, we search
     291             :                         for a Locale "en-US" inside the given Locale list.
     292             : 
     293             :                         If "en-US" could not be located, we search for
     294             :                         a Locale "en" inside the given list.
     295             : 
     296             :                         If no "same" nor any "similar" locale could be found,
     297             :                         we try "x-default" and "x-notranslate" explicitly.
     298             :                         Sometimes localized variables are optimized and doesnt use
     299             :                         localzation realy. E.g. in case the localized value is a fix
     300             :                         product name.
     301             : 
     302             :                         If no locale match till now, we use any other existing
     303             :                         locale, which exists inside the set of given ones!
     304             : 
     305             :             @seealso    equals()
     306             :             @seealso    similar()
     307             : 
     308             :             @param      lISOList
     309             :                         the list of possible Locales
     310             :                         (as formated ISO strings).
     311             : 
     312             :             @param      sReferenceISO
     313             :                         the reference Locale, which should be searched
     314             :                         if its equals or similar to any Locale inside
     315             :                         the provided Locale list.
     316             : 
     317             :             @return     An iterator, which points to the found element
     318             :                         inside the given Locale list.
     319             :                         If no matching Locale could be found, it points
     320             :                         to the end of the list.
     321             : 
     322             :             @throw      [MalFormedLocaleException]
     323             :                         if at least one ISO formated string couldnt
     324             :                         be converted to a valid Locale Object.
     325             :          */
     326             :         static ::std::vector< ::rtl::OUString >::const_iterator getFallback(const ::std::vector< ::rtl::OUString >& lISOList     ,
     327             :                                                                             const ::rtl::OUString&                  sReferenceISO)
     328             :             throw(MalFormedLocaleException);
     329             : 
     330             :         //---------------------------------------
     331             :         /** @short      assign elements of another locale
     332             :                         to this instance.
     333             : 
     334             :             @param      rCopy
     335             :                         another locale object.
     336             :          */
     337             :         void operator=(const Locale& rCopy);
     338             : 
     339             :         //---------------------------------------
     340             :         /** @short      check if two Locale objects are equals.
     341             : 
     342             :             @seealso    equals()
     343             : 
     344             :             @param      aComparable
     345             :                         the Locale object for compare.
     346             : 
     347             :             @return     [boolean]
     348             :                         TRUE if both objects uses the same values for
     349             :                         Language, Country and Variant.
     350             :          */
     351             :         sal_Bool operator==(const Locale& aComparable) const;
     352             : 
     353             :         //---------------------------------------
     354             :         /** @short  check if two Locale objects are different.
     355             : 
     356             :             @param  aComparable
     357             :                     the Locale object for compare.
     358             : 
     359             :             @return [boolean]
     360             :                     TRUE if at least one part of such Locale
     361             :                     isnt the same.
     362             :          */
     363             :         sal_Bool operator!=(const Locale& aComparable) const;
     364             : };
     365             : 
     366             : } // namespace salhelper
     367             : 
     368             : #endif // _COMPHELPER_LOCALE_HXX_
     369             : 
     370             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10