Locale Class Reference

#include <Locale.h>

List of all members.

Public Member Functions

 Locale (const std::string &language)
 Locale (const std::string &language, const std::string &country)
 Locale (const std::string &language, const std::string &country, const std::string &variant)
virtual ~Locale ()
bool operator== (const Locale &rhs) const
bool operator!= (const Locale &rhs) const
bool operator< (const Locale &rhs) const
const std::string & getLanguage () const
const std::string & getCountry () const
const std::string & getVariant () const
std::string getDisplayName () const
bool hasParentLocale () const
Locale getParentLocale () const

Static Public Member Functions

static const LocalegetDefault ()
static void setDefault (const Locale &locale)

Private Attributes

std::string _lang
std::string _country
std::string _variant

Static Private Attributes

static Locale DEFAULT


Detailed Description

Definition at line 40 of file Locale.h.


Constructor & Destructor Documentation

Locale::Locale ( const std::string &  language  )  [explicit]

Referenced by getParentLocale().

Locale::Locale ( const std::string &  language,
const std::string &  country 
) [explicit]

Locale::Locale ( const std::string &  language,
const std::string &  country,
const std::string &  variant 
) [explicit]

Locale::~Locale (  )  [virtual]

Definition at line 72 of file Locale.cpp.

00073 {
00074 }


Member Function Documentation

bool Locale::operator== ( const Locale rhs  )  const

Definition at line 76 of file Locale.cpp.

References _country, _lang, and _variant.

00077 {
00078     return (_lang == rhs._lang &&
00079             _country == rhs._country &&
00080             _variant == rhs._variant);
00081 }

bool Locale::operator!= ( const Locale rhs  )  const

Definition at line 83 of file Locale.cpp.

References _country, _lang, and _variant.

00083                                                {
00084     return (_lang != rhs._lang ||
00085             _country != rhs._country ||
00086             _variant != rhs._variant);
00087 }

bool Locale::operator< ( const Locale rhs  )  const

Definition at line 89 of file Locale.cpp.

References getCountry(), getLanguage(), and getVariant().

00090 {
00091     int langCmp = this->getLanguage().compare(rhs.getLanguage());
00092     if (langCmp < 0) {
00093         return true;
00094     }
00095     if (langCmp > 0) {
00096         return false;
00097     }
00098 
00099     // same language, check country
00100     int countryCmp = this->getCountry().compare(rhs.getCountry());
00101     if (countryCmp < 0) {
00102         return true;
00103     }
00104     if (countryCmp > 0) {
00105         return false;
00106     }
00107 
00108     // same country, check variant
00109     int variantCmp = this->getVariant().compare(rhs.getVariant());
00110     if (variantCmp < 0) {
00111         return true;
00112     }
00113     return false;
00114 }

const string & Locale::getLanguage (  )  const

Definition at line 116 of file Locale.cpp.

References _lang.

Referenced by operator<().

00117 {
00118     return _lang;
00119 }

const string & Locale::getCountry (  )  const

Definition at line 121 of file Locale.cpp.

References _country.

Referenced by operator<().

00122 {
00123     return _country;
00124 }

const string & Locale::getVariant (  )  const

Definition at line 126 of file Locale.cpp.

References _variant.

Referenced by operator<().

00127 {
00128     return _variant;
00129 }

string Locale::getDisplayName (  )  const

Definition at line 131 of file Locale.cpp.

References _country, _lang, and _variant.

Referenced by ResourceDefinition::format(), ResourceBundle::loadMessages(), operator<<(), and ResourceDefinition::prepareFormatter().

00132 {
00133     if (_lang.empty()) {
00134         return DEFAULT_LOCALE_DISPLAY;
00135     }
00136 
00137     return
00138         _lang
00139         + (_country.empty() ? "" : (string("_") + _country))
00140         + (_variant.empty() ? "" : (string("_") + _variant));
00141 }

bool Locale::hasParentLocale (  )  const

Definition at line 143 of file Locale.cpp.

References _country, and _variant.

Referenced by getParentLocale().

00144 {
00145     return !(_country.empty() && _variant.empty());
00146 }

Locale Locale::getParentLocale (  )  const

Definition at line 148 of file Locale.cpp.

References _country, _lang, _variant, hasParentLocale(), and Locale().

00149 {
00150     if (hasParentLocale()) {
00151         // one or both of _country and _variant is non-empty
00152         if (_country.empty() ^ _variant.empty()) {
00153             return Locale(_lang);
00154         }
00155 
00156         return Locale(_lang, _country);
00157     } else {
00158         // TODO: gotta give them something -- maybe a locale with no language?
00159         return *this;
00160     }
00161 }

const Locale & Locale::getDefault (  )  [static]

Definition at line 163 of file Locale.cpp.

References DEFAULT.

Referenced by fennel::FennelResource::instance().

00164 {
00165     return DEFAULT;
00166 }

void Locale::setDefault ( const Locale locale  )  [static]

Definition at line 168 of file Locale.cpp.

References DEFAULT.

00169 {
00170     DEFAULT = locale;
00171 }


Member Data Documentation

std::string Locale::_lang [private]

Definition at line 71 of file Locale.h.

Referenced by getDisplayName(), getLanguage(), getParentLocale(), operator!=(), and operator==().

std::string Locale::_country [private]

Definition at line 72 of file Locale.h.

Referenced by getCountry(), getDisplayName(), getParentLocale(), hasParentLocale(), operator!=(), and operator==().

std::string Locale::_variant [private]

Definition at line 73 of file Locale.h.

Referenced by getDisplayName(), getParentLocale(), getVariant(), hasParentLocale(), operator!=(), and operator==().

Locale Locale::DEFAULT [static, private]

Definition at line 75 of file Locale.h.

Referenced by getDefault(), and setDefault().


The documentation for this class was generated from the following files:
Generated on Mon Jun 22 04:00:39 2009 for Fennel by  doxygen 1.5.1