1*dde7d3faSAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*dde7d3faSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*dde7d3faSAndrew Rist * or more contributor license agreements. See the NOTICE file 5*dde7d3faSAndrew Rist * distributed with this work for additional information 6*dde7d3faSAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*dde7d3faSAndrew Rist * to you under the Apache License, Version 2.0 (the 8*dde7d3faSAndrew Rist * "License"); you may not use this file except in compliance 9*dde7d3faSAndrew Rist * with the License. You may obtain a copy of the License at 10cdf0e10cSrcweir * 11*dde7d3faSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12cdf0e10cSrcweir * 13*dde7d3faSAndrew Rist * Unless required by applicable law or agreed to in writing, 14*dde7d3faSAndrew Rist * software distributed under the License is distributed on an 15*dde7d3faSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*dde7d3faSAndrew Rist * KIND, either express or implied. See the License for the 17*dde7d3faSAndrew Rist * specific language governing permissions and limitations 18*dde7d3faSAndrew Rist * under the License. 19cdf0e10cSrcweir * 20*dde7d3faSAndrew Rist *************************************************************/ 21*dde7d3faSAndrew Rist 22*dde7d3faSAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 25cdf0e10cSrcweir #include "precompiled_comphelper.hxx" 26cdf0e10cSrcweir #include <comphelper/locale.hxx> 27cdf0e10cSrcweir 28cdf0e10cSrcweir //_______________________________________________ 29cdf0e10cSrcweir // includes 30cdf0e10cSrcweir #include <rtl/ustrbuf.hxx> 31cdf0e10cSrcweir 32cdf0e10cSrcweir //_______________________________________________ 33cdf0e10cSrcweir // namespace 34cdf0e10cSrcweir 35cdf0e10cSrcweir namespace comphelper{ 36cdf0e10cSrcweir 37cdf0e10cSrcweir //----------------------------------------------- 38cdf0e10cSrcweir const sal_Unicode Locale::SEPERATOR_LC = (sal_Unicode)'-'; 39cdf0e10cSrcweir const sal_Unicode Locale::SEPERATOR_CV = (sal_Unicode)'_'; 40cdf0e10cSrcweir const sal_Unicode Locale::SEPERATOR_CV_LINUX = (sal_Unicode)'.'; 41cdf0e10cSrcweir 42cdf0e10cSrcweir //----------------------------------------------- 43cdf0e10cSrcweir const Locale Locale::X_DEFAULT() 44cdf0e10cSrcweir { 45cdf0e10cSrcweir static Locale aLocale( 46cdf0e10cSrcweir ::rtl::OUString::createFromAscii("x"), 47cdf0e10cSrcweir ::rtl::OUString::createFromAscii("default")); 48cdf0e10cSrcweir return aLocale; 49cdf0e10cSrcweir } 50cdf0e10cSrcweir 51cdf0e10cSrcweir //----------------------------------------------- 52cdf0e10cSrcweir const Locale Locale::EN() 53cdf0e10cSrcweir { 54cdf0e10cSrcweir static Locale aLocale( 55cdf0e10cSrcweir ::rtl::OUString::createFromAscii("en"), 56cdf0e10cSrcweir ::rtl::OUString()); 57cdf0e10cSrcweir return aLocale; 58cdf0e10cSrcweir } 59cdf0e10cSrcweir 60cdf0e10cSrcweir //----------------------------------------------- 61cdf0e10cSrcweir const Locale Locale::EN_US() 62cdf0e10cSrcweir { 63cdf0e10cSrcweir static Locale aLocale( 64cdf0e10cSrcweir ::rtl::OUString::createFromAscii("en"), 65cdf0e10cSrcweir ::rtl::OUString::createFromAscii("US")); 66cdf0e10cSrcweir return aLocale; 67cdf0e10cSrcweir } 68cdf0e10cSrcweir 69cdf0e10cSrcweir //----------------------------------------------- 70cdf0e10cSrcweir const Locale Locale::DE_DE() 71cdf0e10cSrcweir { 72cdf0e10cSrcweir static Locale aLocale( 73cdf0e10cSrcweir ::rtl::OUString::createFromAscii("de"), 74cdf0e10cSrcweir ::rtl::OUString::createFromAscii("DE")); 75cdf0e10cSrcweir return aLocale; 76cdf0e10cSrcweir } 77cdf0e10cSrcweir 78cdf0e10cSrcweir //----------------------------------------------- 79cdf0e10cSrcweir const Locale Locale::DE_CH() 80cdf0e10cSrcweir { 81cdf0e10cSrcweir static Locale aLocale( 82cdf0e10cSrcweir ::rtl::OUString::createFromAscii("de"), 83cdf0e10cSrcweir ::rtl::OUString::createFromAscii("CH")); 84cdf0e10cSrcweir return aLocale; 85cdf0e10cSrcweir } 86cdf0e10cSrcweir 87cdf0e10cSrcweir //----------------------------------------------- 88cdf0e10cSrcweir const Locale Locale::DE_AT() 89cdf0e10cSrcweir { 90cdf0e10cSrcweir static Locale aLocale( 91cdf0e10cSrcweir ::rtl::OUString::createFromAscii("de"), 92cdf0e10cSrcweir ::rtl::OUString::createFromAscii("AT")); 93cdf0e10cSrcweir return aLocale; 94cdf0e10cSrcweir } 95cdf0e10cSrcweir 96cdf0e10cSrcweir //----------------------------------------------- 97cdf0e10cSrcweir const Locale Locale::AR() 98cdf0e10cSrcweir { 99cdf0e10cSrcweir static Locale aLocale( 100cdf0e10cSrcweir ::rtl::OUString::createFromAscii("ar"), 101cdf0e10cSrcweir ::rtl::OUString()); 102cdf0e10cSrcweir return aLocale; 103cdf0e10cSrcweir } 104cdf0e10cSrcweir 105cdf0e10cSrcweir //----------------------------------------------- 106cdf0e10cSrcweir const Locale Locale::CA() 107cdf0e10cSrcweir { 108cdf0e10cSrcweir static Locale aLocale( 109cdf0e10cSrcweir ::rtl::OUString::createFromAscii("ca"), 110cdf0e10cSrcweir ::rtl::OUString()); 111cdf0e10cSrcweir return aLocale; 112cdf0e10cSrcweir } 113cdf0e10cSrcweir 114cdf0e10cSrcweir //----------------------------------------------- 115cdf0e10cSrcweir const Locale Locale::CS() 116cdf0e10cSrcweir { 117cdf0e10cSrcweir static Locale aLocale( 118cdf0e10cSrcweir ::rtl::OUString::createFromAscii("cs"), 119cdf0e10cSrcweir ::rtl::OUString()); 120cdf0e10cSrcweir return aLocale; 121cdf0e10cSrcweir } 122cdf0e10cSrcweir 123cdf0e10cSrcweir //----------------------------------------------- 124cdf0e10cSrcweir const Locale Locale::DA() 125cdf0e10cSrcweir { 126cdf0e10cSrcweir static Locale aLocale( 127cdf0e10cSrcweir ::rtl::OUString::createFromAscii("da"), 128cdf0e10cSrcweir ::rtl::OUString()); 129cdf0e10cSrcweir return aLocale; 130cdf0e10cSrcweir } 131cdf0e10cSrcweir 132cdf0e10cSrcweir //----------------------------------------------- 133cdf0e10cSrcweir const Locale Locale::EL() 134cdf0e10cSrcweir { 135cdf0e10cSrcweir static Locale aLocale( 136cdf0e10cSrcweir ::rtl::OUString::createFromAscii("el"), 137cdf0e10cSrcweir ::rtl::OUString()); 138cdf0e10cSrcweir return aLocale; 139cdf0e10cSrcweir } 140cdf0e10cSrcweir 141cdf0e10cSrcweir //----------------------------------------------- 142cdf0e10cSrcweir const Locale Locale::ES() 143cdf0e10cSrcweir { 144cdf0e10cSrcweir static Locale aLocale( 145cdf0e10cSrcweir ::rtl::OUString::createFromAscii("es"), 146cdf0e10cSrcweir ::rtl::OUString()); 147cdf0e10cSrcweir return aLocale; 148cdf0e10cSrcweir } 149cdf0e10cSrcweir 150cdf0e10cSrcweir //----------------------------------------------- 151cdf0e10cSrcweir const Locale Locale::FI() 152cdf0e10cSrcweir { 153cdf0e10cSrcweir static Locale aLocale( 154cdf0e10cSrcweir ::rtl::OUString::createFromAscii("fi"), 155cdf0e10cSrcweir ::rtl::OUString()); 156cdf0e10cSrcweir return aLocale; 157cdf0e10cSrcweir } 158cdf0e10cSrcweir 159cdf0e10cSrcweir //----------------------------------------------- 160cdf0e10cSrcweir const Locale Locale::FR() 161cdf0e10cSrcweir { 162cdf0e10cSrcweir static Locale aLocale( 163cdf0e10cSrcweir ::rtl::OUString::createFromAscii("fr"), 164cdf0e10cSrcweir ::rtl::OUString()); 165cdf0e10cSrcweir return aLocale; 166cdf0e10cSrcweir } 167cdf0e10cSrcweir 168cdf0e10cSrcweir //----------------------------------------------- 169cdf0e10cSrcweir const Locale Locale::HE() 170cdf0e10cSrcweir { 171cdf0e10cSrcweir static Locale aLocale( 172cdf0e10cSrcweir ::rtl::OUString::createFromAscii("he"), 173cdf0e10cSrcweir ::rtl::OUString()); 174cdf0e10cSrcweir return aLocale; 175cdf0e10cSrcweir } 176cdf0e10cSrcweir 177cdf0e10cSrcweir //----------------------------------------------- 178cdf0e10cSrcweir const Locale Locale::HI_IN() 179cdf0e10cSrcweir { 180cdf0e10cSrcweir static Locale aLocale( 181cdf0e10cSrcweir ::rtl::OUString::createFromAscii("hi"), 182cdf0e10cSrcweir ::rtl::OUString::createFromAscii("IN")); 183cdf0e10cSrcweir return aLocale; 184cdf0e10cSrcweir } 185cdf0e10cSrcweir 186cdf0e10cSrcweir //----------------------------------------------- 187cdf0e10cSrcweir const Locale Locale::HU() 188cdf0e10cSrcweir { 189cdf0e10cSrcweir static Locale aLocale( 190cdf0e10cSrcweir ::rtl::OUString::createFromAscii("hu"), 191cdf0e10cSrcweir ::rtl::OUString()); 192cdf0e10cSrcweir return aLocale; 193cdf0e10cSrcweir } 194cdf0e10cSrcweir 195cdf0e10cSrcweir //----------------------------------------------- 196cdf0e10cSrcweir const Locale Locale::IT() 197cdf0e10cSrcweir { 198cdf0e10cSrcweir static Locale aLocale( 199cdf0e10cSrcweir ::rtl::OUString::createFromAscii("it"), 200cdf0e10cSrcweir ::rtl::OUString()); 201cdf0e10cSrcweir return aLocale; 202cdf0e10cSrcweir } 203cdf0e10cSrcweir 204cdf0e10cSrcweir //----------------------------------------------- 205cdf0e10cSrcweir const Locale Locale::JA() 206cdf0e10cSrcweir { 207cdf0e10cSrcweir static Locale aLocale( 208cdf0e10cSrcweir ::rtl::OUString::createFromAscii("ja"), 209cdf0e10cSrcweir ::rtl::OUString()); 210cdf0e10cSrcweir return aLocale; 211cdf0e10cSrcweir } 212cdf0e10cSrcweir 213cdf0e10cSrcweir //----------------------------------------------- 214cdf0e10cSrcweir const Locale Locale::KO() 215cdf0e10cSrcweir { 216cdf0e10cSrcweir static Locale aLocale( 217cdf0e10cSrcweir ::rtl::OUString::createFromAscii("ko"), 218cdf0e10cSrcweir ::rtl::OUString()); 219cdf0e10cSrcweir return aLocale; 220cdf0e10cSrcweir } 221cdf0e10cSrcweir 222cdf0e10cSrcweir //----------------------------------------------- 223cdf0e10cSrcweir const Locale Locale::NL() 224cdf0e10cSrcweir { 225cdf0e10cSrcweir static Locale aLocale( 226cdf0e10cSrcweir ::rtl::OUString::createFromAscii("nl"), 227cdf0e10cSrcweir ::rtl::OUString()); 228cdf0e10cSrcweir return aLocale; 229cdf0e10cSrcweir } 230cdf0e10cSrcweir 231cdf0e10cSrcweir //----------------------------------------------- 232cdf0e10cSrcweir const Locale Locale::PL() 233cdf0e10cSrcweir { 234cdf0e10cSrcweir static Locale aLocale( 235cdf0e10cSrcweir ::rtl::OUString::createFromAscii("pl"), 236cdf0e10cSrcweir ::rtl::OUString()); 237cdf0e10cSrcweir return aLocale; 238cdf0e10cSrcweir } 239cdf0e10cSrcweir 240cdf0e10cSrcweir //----------------------------------------------- 241cdf0e10cSrcweir const Locale Locale::PT() 242cdf0e10cSrcweir { 243cdf0e10cSrcweir static Locale aLocale( 244cdf0e10cSrcweir ::rtl::OUString::createFromAscii("pt"), 245cdf0e10cSrcweir ::rtl::OUString()); 246cdf0e10cSrcweir return aLocale; 247cdf0e10cSrcweir } 248cdf0e10cSrcweir 249cdf0e10cSrcweir //----------------------------------------------- 250cdf0e10cSrcweir const Locale Locale::PT_BR() 251cdf0e10cSrcweir { 252cdf0e10cSrcweir static Locale aLocale( 253cdf0e10cSrcweir ::rtl::OUString::createFromAscii("pt"), 254cdf0e10cSrcweir ::rtl::OUString::createFromAscii("BR")); 255cdf0e10cSrcweir return aLocale; 256cdf0e10cSrcweir } 257cdf0e10cSrcweir 258cdf0e10cSrcweir //----------------------------------------------- 259cdf0e10cSrcweir const Locale Locale::RU() 260cdf0e10cSrcweir { 261cdf0e10cSrcweir static Locale aLocale( 262cdf0e10cSrcweir ::rtl::OUString::createFromAscii("ru"), 263cdf0e10cSrcweir ::rtl::OUString()); 264cdf0e10cSrcweir return aLocale; 265cdf0e10cSrcweir } 266cdf0e10cSrcweir 267cdf0e10cSrcweir //----------------------------------------------- 268cdf0e10cSrcweir const Locale Locale::SK() 269cdf0e10cSrcweir { 270cdf0e10cSrcweir static Locale aLocale( 271cdf0e10cSrcweir ::rtl::OUString::createFromAscii("sk"), 272cdf0e10cSrcweir ::rtl::OUString()); 273cdf0e10cSrcweir return aLocale; 274cdf0e10cSrcweir } 275cdf0e10cSrcweir 276cdf0e10cSrcweir //----------------------------------------------- 277cdf0e10cSrcweir const Locale Locale::SL() 278cdf0e10cSrcweir { 279cdf0e10cSrcweir static Locale aLocale( 280cdf0e10cSrcweir ::rtl::OUString::createFromAscii("sl"), 281cdf0e10cSrcweir ::rtl::OUString()); 282cdf0e10cSrcweir return aLocale; 283cdf0e10cSrcweir } 284cdf0e10cSrcweir 285cdf0e10cSrcweir //----------------------------------------------- 286cdf0e10cSrcweir const Locale Locale::SV() 287cdf0e10cSrcweir { 288cdf0e10cSrcweir static Locale aLocale( 289cdf0e10cSrcweir ::rtl::OUString::createFromAscii("sv"), 290cdf0e10cSrcweir ::rtl::OUString()); 291cdf0e10cSrcweir return aLocale; 292cdf0e10cSrcweir } 293cdf0e10cSrcweir 294cdf0e10cSrcweir //----------------------------------------------- 295cdf0e10cSrcweir const Locale Locale::TH() 296cdf0e10cSrcweir { 297cdf0e10cSrcweir static Locale aLocale( 298cdf0e10cSrcweir ::rtl::OUString::createFromAscii("th"), 299cdf0e10cSrcweir ::rtl::OUString()); 300cdf0e10cSrcweir return aLocale; 301cdf0e10cSrcweir } 302cdf0e10cSrcweir 303cdf0e10cSrcweir //----------------------------------------------- 304cdf0e10cSrcweir const Locale Locale::TR() 305cdf0e10cSrcweir { 306cdf0e10cSrcweir static Locale aLocale( 307cdf0e10cSrcweir ::rtl::OUString::createFromAscii("tr"), 308cdf0e10cSrcweir ::rtl::OUString()); 309cdf0e10cSrcweir return aLocale; 310cdf0e10cSrcweir } 311cdf0e10cSrcweir 312cdf0e10cSrcweir //----------------------------------------------- 313cdf0e10cSrcweir const Locale Locale::X_COMMENT() 314cdf0e10cSrcweir { 315cdf0e10cSrcweir static Locale aLocale( 316cdf0e10cSrcweir ::rtl::OUString::createFromAscii("x"), 317cdf0e10cSrcweir ::rtl::OUString::createFromAscii("comment")); 318cdf0e10cSrcweir return aLocale; 319cdf0e10cSrcweir } 320cdf0e10cSrcweir 321cdf0e10cSrcweir //----------------------------------------------- 322cdf0e10cSrcweir const Locale Locale::X_TRANSLATE() 323cdf0e10cSrcweir { 324cdf0e10cSrcweir static Locale aLocale( 325cdf0e10cSrcweir ::rtl::OUString::createFromAscii("x"), 326cdf0e10cSrcweir ::rtl::OUString::createFromAscii("translate")); 327cdf0e10cSrcweir return aLocale; 328cdf0e10cSrcweir } 329cdf0e10cSrcweir 330cdf0e10cSrcweir //----------------------------------------------- 331cdf0e10cSrcweir const Locale Locale::X_NOTRANSLATE() 332cdf0e10cSrcweir { 333cdf0e10cSrcweir static Locale aLocale( 334cdf0e10cSrcweir ::rtl::OUString::createFromAscii("x"), 335cdf0e10cSrcweir ::rtl::OUString::createFromAscii("notranslate")); 336cdf0e10cSrcweir return aLocale; 337cdf0e10cSrcweir } 338cdf0e10cSrcweir 339cdf0e10cSrcweir //----------------------------------------------- 340cdf0e10cSrcweir const Locale Locale::ZH_CN() 341cdf0e10cSrcweir { 342cdf0e10cSrcweir static Locale aLocale( 343cdf0e10cSrcweir ::rtl::OUString::createFromAscii("zh"), 344cdf0e10cSrcweir ::rtl::OUString::createFromAscii("CN")); 345cdf0e10cSrcweir return aLocale; 346cdf0e10cSrcweir } 347cdf0e10cSrcweir 348cdf0e10cSrcweir //----------------------------------------------- 349cdf0e10cSrcweir const Locale Locale::ZH_TW() 350cdf0e10cSrcweir { 351cdf0e10cSrcweir static Locale aLocale( 352cdf0e10cSrcweir ::rtl::OUString::createFromAscii("zh"), 353cdf0e10cSrcweir ::rtl::OUString::createFromAscii("TW")); 354cdf0e10cSrcweir return aLocale; 355cdf0e10cSrcweir } 356cdf0e10cSrcweir 357cdf0e10cSrcweir //----------------------------------------------- 358cdf0e10cSrcweir Locale::Locale(const ::rtl::OUString& sISO) 359cdf0e10cSrcweir throw(Locale::MalFormedLocaleException) 360cdf0e10cSrcweir { 361cdf0e10cSrcweir fromISO(sISO); 362cdf0e10cSrcweir } 363cdf0e10cSrcweir 364cdf0e10cSrcweir //----------------------------------------------- 365cdf0e10cSrcweir Locale::Locale(const ::rtl::OUString& sLanguage, 366cdf0e10cSrcweir const ::rtl::OUString& sCountry , 367cdf0e10cSrcweir const ::rtl::OUString& sVariant ) 368cdf0e10cSrcweir { 369cdf0e10cSrcweir // Use set methods to check values too! 370cdf0e10cSrcweir setLanguage(sLanguage); 371cdf0e10cSrcweir setCountry (sCountry ); 372cdf0e10cSrcweir setVariant (sVariant ); 373cdf0e10cSrcweir } 374cdf0e10cSrcweir 375cdf0e10cSrcweir //----------------------------------------------- 376cdf0e10cSrcweir Locale::Locale() 377cdf0e10cSrcweir { 378cdf0e10cSrcweir // Initialize instance ... otherwhise user will 379cdf0e10cSrcweir // may be get exceptions if he e.g. copy this instance ... 380cdf0e10cSrcweir (*this) = X_NOTRANSLATE(); 381cdf0e10cSrcweir } 382cdf0e10cSrcweir 383cdf0e10cSrcweir //----------------------------------------------- 384cdf0e10cSrcweir Locale::Locale(const Locale& aCopy) 385cdf0e10cSrcweir { 386cdf0e10cSrcweir (*this) = aCopy; // recycle assign operator 387cdf0e10cSrcweir } 388cdf0e10cSrcweir 389cdf0e10cSrcweir //----------------------------------------------- 390cdf0e10cSrcweir ::rtl::OUString Locale::getLanguage() const 391cdf0e10cSrcweir { 392cdf0e10cSrcweir return m_sLanguage; 393cdf0e10cSrcweir } 394cdf0e10cSrcweir 395cdf0e10cSrcweir //----------------------------------------------- 396cdf0e10cSrcweir ::rtl::OUString Locale::getCountry() const 397cdf0e10cSrcweir { 398cdf0e10cSrcweir return m_sCountry; 399cdf0e10cSrcweir } 400cdf0e10cSrcweir 401cdf0e10cSrcweir //----------------------------------------------- 402cdf0e10cSrcweir ::rtl::OUString Locale::getVariant() const 403cdf0e10cSrcweir { 404cdf0e10cSrcweir return m_sVariant; 405cdf0e10cSrcweir } 406cdf0e10cSrcweir 407cdf0e10cSrcweir //----------------------------------------------- 408cdf0e10cSrcweir void Locale::setLanguage(const ::rtl::OUString& sLanguage) 409cdf0e10cSrcweir { 410cdf0e10cSrcweir m_sLanguage = sLanguage; 411cdf0e10cSrcweir } 412cdf0e10cSrcweir 413cdf0e10cSrcweir //----------------------------------------------- 414cdf0e10cSrcweir void Locale::setCountry(const ::rtl::OUString& sCountry) 415cdf0e10cSrcweir { 416cdf0e10cSrcweir m_sCountry = sCountry; 417cdf0e10cSrcweir } 418cdf0e10cSrcweir 419cdf0e10cSrcweir //----------------------------------------------- 420cdf0e10cSrcweir void Locale::setVariant(const ::rtl::OUString& sVariant) 421cdf0e10cSrcweir { 422cdf0e10cSrcweir m_sVariant = sVariant; 423cdf0e10cSrcweir } 424cdf0e10cSrcweir 425cdf0e10cSrcweir //----------------------------------------------- 426cdf0e10cSrcweir /* Attention: Use own interface methods to set the 427cdf0e10cSrcweir different parts of this locale. Because the 428cdf0e10cSrcweir check the incoming value and throw an exception 429cdf0e10cSrcweir automaticly ... 430cdf0e10cSrcweir */ 431cdf0e10cSrcweir void Locale::fromISO(const ::rtl::OUString& sISO) 432cdf0e10cSrcweir throw(Locale::MalFormedLocaleException) 433cdf0e10cSrcweir { 434cdf0e10cSrcweir m_sLanguage = ::rtl::OUString(); 435cdf0e10cSrcweir m_sCountry = ::rtl::OUString(); 436cdf0e10cSrcweir m_sVariant = ::rtl::OUString(); 437cdf0e10cSrcweir 438cdf0e10cSrcweir ::rtl::OUString sParser(sISO); 439cdf0e10cSrcweir sParser.trim(); 440cdf0e10cSrcweir 441cdf0e10cSrcweir sal_Int32 nStart = 0; 442cdf0e10cSrcweir sal_Int32 nEnd = 0; 443cdf0e10cSrcweir 444cdf0e10cSrcweir // extract language part 445cdf0e10cSrcweir nEnd = sParser.indexOf(SEPERATOR_LC, nStart); 446cdf0e10cSrcweir if (nEnd<0) 447cdf0e10cSrcweir { 448cdf0e10cSrcweir setLanguage(sParser); 449cdf0e10cSrcweir return; 450cdf0e10cSrcweir } 451cdf0e10cSrcweir setLanguage(sParser.copy(nStart, nEnd-nStart)); 452cdf0e10cSrcweir nStart = nEnd+1; 453cdf0e10cSrcweir 454cdf0e10cSrcweir // extract country 455cdf0e10cSrcweir nEnd = sParser.indexOf(SEPERATOR_CV, nStart); 456cdf0e10cSrcweir if (nEnd<0) 457cdf0e10cSrcweir nEnd = sParser.indexOf(SEPERATOR_CV_LINUX, nStart); 458cdf0e10cSrcweir if (nEnd<0) 459cdf0e10cSrcweir { 460cdf0e10cSrcweir setCountry(sParser.copy(nStart, sParser.getLength()-nStart)); 461cdf0e10cSrcweir return; 462cdf0e10cSrcweir } 463cdf0e10cSrcweir nStart = nEnd+1; 464cdf0e10cSrcweir 465cdf0e10cSrcweir // extract variant 466cdf0e10cSrcweir setVariant(sParser.copy(nStart, sParser.getLength()-nStart)); 467cdf0e10cSrcweir } 468cdf0e10cSrcweir 469cdf0e10cSrcweir //----------------------------------------------- 470cdf0e10cSrcweir ::rtl::OUString Locale::toISO() const 471cdf0e10cSrcweir { 472cdf0e10cSrcweir ::rtl::OUStringBuffer sISO(64); 473cdf0e10cSrcweir 474cdf0e10cSrcweir sISO.append(m_sLanguage); 475cdf0e10cSrcweir if (m_sCountry.getLength()) 476cdf0e10cSrcweir { 477cdf0e10cSrcweir sISO.append(SEPERATOR_LC); 478cdf0e10cSrcweir sISO.append(m_sCountry); 479cdf0e10cSrcweir 480cdf0e10cSrcweir if (m_sVariant.getLength()) 481cdf0e10cSrcweir { 482cdf0e10cSrcweir sISO.append(SEPERATOR_CV); 483cdf0e10cSrcweir sISO.append(m_sVariant); 484cdf0e10cSrcweir } 485cdf0e10cSrcweir } 486cdf0e10cSrcweir 487cdf0e10cSrcweir return sISO.makeStringAndClear(); 488cdf0e10cSrcweir } 489cdf0e10cSrcweir 490cdf0e10cSrcweir //----------------------------------------------- 491cdf0e10cSrcweir sal_Bool Locale::equals(const Locale& aComparable) const 492cdf0e10cSrcweir { 493cdf0e10cSrcweir return ( 494cdf0e10cSrcweir m_sLanguage.equals(aComparable.m_sLanguage) && 495cdf0e10cSrcweir m_sCountry.equals (aComparable.m_sCountry ) && 496cdf0e10cSrcweir m_sVariant.equals (aComparable.m_sVariant ) 497cdf0e10cSrcweir ); 498cdf0e10cSrcweir } 499cdf0e10cSrcweir 500cdf0e10cSrcweir //----------------------------------------------- 501cdf0e10cSrcweir sal_Bool Locale::similar(const Locale& aComparable) const 502cdf0e10cSrcweir { 503cdf0e10cSrcweir return (m_sLanguage.equals(aComparable.m_sLanguage)); 504cdf0e10cSrcweir } 505cdf0e10cSrcweir 506cdf0e10cSrcweir //----------------------------------------------- 507cdf0e10cSrcweir ::std::vector< ::rtl::OUString >::const_iterator Locale::getFallback(const ::std::vector< ::rtl::OUString >& lISOList , 508cdf0e10cSrcweir const ::rtl::OUString& sReferenceISO) 509cdf0e10cSrcweir throw(Locale::MalFormedLocaleException) 510cdf0e10cSrcweir { 511cdf0e10cSrcweir Locale aReference(sReferenceISO); 512cdf0e10cSrcweir 513cdf0e10cSrcweir // Note: The same language or "en"/"en-US" should be preferred as fallback. 514cdf0e10cSrcweir // On the other side some localized variables doesnt use localzation in real. 515cdf0e10cSrcweir // May be the use a "fix" value only ... marked as X-DEFAULT or X-NOTRANSLATE. 516cdf0e10cSrcweir // At least it can be discussed, if any language is a valid fallback ... 517cdf0e10cSrcweir // But in case some office functionality depends on that (that means real functionality instead 518cdf0e10cSrcweir // of pure UI descriptions) we should do anything, so it can work. 519cdf0e10cSrcweir 520cdf0e10cSrcweir ::std::vector< ::rtl::OUString >::const_iterator pSimilar = lISOList.end(); 521cdf0e10cSrcweir ::std::vector< ::rtl::OUString >::const_iterator pEN_US = lISOList.end(); 522cdf0e10cSrcweir ::std::vector< ::rtl::OUString >::const_iterator pEN = lISOList.end(); 523cdf0e10cSrcweir ::std::vector< ::rtl::OUString >::const_iterator pXDefault = lISOList.end(); 524cdf0e10cSrcweir ::std::vector< ::rtl::OUString >::const_iterator pXNoTranslate = lISOList.end(); 525cdf0e10cSrcweir ::std::vector< ::rtl::OUString >::const_iterator pAny = lISOList.end(); 526cdf0e10cSrcweir 527cdf0e10cSrcweir ::std::vector< ::rtl::OUString >::const_iterator pIt; 528cdf0e10cSrcweir for ( pIt = lISOList.begin(); 529cdf0e10cSrcweir pIt != lISOList.end() ; 530cdf0e10cSrcweir ++pIt ) 531cdf0e10cSrcweir { 532cdf0e10cSrcweir Locale aCheck(*pIt); 533cdf0e10cSrcweir // found Locale, which match with 100% => return it 534cdf0e10cSrcweir if (aCheck.equals(aReference)) 535cdf0e10cSrcweir return pIt; 536cdf0e10cSrcweir 537cdf0e10cSrcweir // found similar Locale => safe it as possible fallback 538cdf0e10cSrcweir if ( 539cdf0e10cSrcweir (pSimilar == lISOList.end()) && 540cdf0e10cSrcweir (aCheck.similar(aReference)) 541cdf0e10cSrcweir ) 542cdf0e10cSrcweir { 543cdf0e10cSrcweir pSimilar = pIt; 544cdf0e10cSrcweir } 545cdf0e10cSrcweir else 546cdf0e10cSrcweir // found en-US => safe it as fallback 547cdf0e10cSrcweir if ( 548cdf0e10cSrcweir (pEN_US == lISOList.end()) && 549cdf0e10cSrcweir (aCheck.equals(EN_US()) ) 550cdf0e10cSrcweir ) 551cdf0e10cSrcweir { 552cdf0e10cSrcweir pEN_US = pIt; 553cdf0e10cSrcweir } 554cdf0e10cSrcweir else 555cdf0e10cSrcweir // found en[-XX] => safe it as fallback 556cdf0e10cSrcweir if ( 557cdf0e10cSrcweir (pEN == lISOList.end() ) && 558cdf0e10cSrcweir (aCheck.similar(EN_US())) 559cdf0e10cSrcweir ) 560cdf0e10cSrcweir { 561cdf0e10cSrcweir pEN = pIt; 562cdf0e10cSrcweir } 563cdf0e10cSrcweir else 564cdf0e10cSrcweir // found an explicit default value(!) => safe it as fallback 565cdf0e10cSrcweir if ( 566cdf0e10cSrcweir (pXDefault == lISOList.end()) && 567cdf0e10cSrcweir (aCheck.equals(X_DEFAULT()) ) 568cdf0e10cSrcweir ) 569cdf0e10cSrcweir { 570cdf0e10cSrcweir pXDefault = pIt; 571cdf0e10cSrcweir } 572cdf0e10cSrcweir else 573cdf0e10cSrcweir // found an implicit default value(!) => safe it as fallback 574cdf0e10cSrcweir if ( 575cdf0e10cSrcweir (pXNoTranslate == lISOList.end()) && 576cdf0e10cSrcweir (aCheck.equals(X_NOTRANSLATE()) ) 577cdf0e10cSrcweir ) 578cdf0e10cSrcweir { 579cdf0e10cSrcweir pXNoTranslate = pIt; 580cdf0e10cSrcweir } 581cdf0e10cSrcweir else 582cdf0e10cSrcweir // safe the first locale, which isn't an explicit fallback 583cdf0e10cSrcweir // as "last possible fallback" 584cdf0e10cSrcweir if (pAny == lISOList.end()) 585cdf0e10cSrcweir pAny = pIt; 586cdf0e10cSrcweir } 587cdf0e10cSrcweir 588cdf0e10cSrcweir if (pSimilar != lISOList.end()) 589cdf0e10cSrcweir return pSimilar; 590cdf0e10cSrcweir 591cdf0e10cSrcweir if (pEN_US != lISOList.end()) 592cdf0e10cSrcweir return pEN_US; 593cdf0e10cSrcweir 594cdf0e10cSrcweir if (pEN != lISOList.end()) 595cdf0e10cSrcweir return pEN; 596cdf0e10cSrcweir 597cdf0e10cSrcweir if (pXDefault != lISOList.end()) 598cdf0e10cSrcweir return pXDefault; 599cdf0e10cSrcweir 600cdf0e10cSrcweir if (pXNoTranslate != lISOList.end()) 601cdf0e10cSrcweir return pXNoTranslate; 602cdf0e10cSrcweir 603cdf0e10cSrcweir if (pAny != lISOList.end()) 604cdf0e10cSrcweir return pAny; 605cdf0e10cSrcweir 606cdf0e10cSrcweir return lISOList.end(); 607cdf0e10cSrcweir } 608cdf0e10cSrcweir 609cdf0e10cSrcweir //----------------------------------------------- 610cdf0e10cSrcweir sal_Bool Locale::getFallback(Locale& aLocale) 611cdf0e10cSrcweir { 612cdf0e10cSrcweir // a) 613cdf0e10cSrcweir // this was our last fallback! 614cdf0e10cSrcweir // break any further calls to this method ... 615cdf0e10cSrcweir if (aLocale.equals(X_NOTRANSLATE())) 616cdf0e10cSrcweir return sal_False; 617cdf0e10cSrcweir 618cdf0e10cSrcweir // b) 619cdf0e10cSrcweir // switch from X_DEFAULT to X_NOTRANSLATE 620cdf0e10cSrcweir // next time we will go to a) 621cdf0e10cSrcweir if (aLocale.equals(X_DEFAULT())) 622cdf0e10cSrcweir { 623cdf0e10cSrcweir aLocale = X_NOTRANSLATE(); 624cdf0e10cSrcweir return sal_True; 625cdf0e10cSrcweir } 626cdf0e10cSrcweir 627cdf0e10cSrcweir // c) 628cdf0e10cSrcweir // switch from EN to X_DEFAULT 629cdf0e10cSrcweir // next time we will go to b) 630cdf0e10cSrcweir if (aLocale.equals(EN())) 631cdf0e10cSrcweir { 632cdf0e10cSrcweir aLocale = X_DEFAULT(); 633cdf0e10cSrcweir return sal_True; 634cdf0e10cSrcweir } 635cdf0e10cSrcweir 636cdf0e10cSrcweir // d) remove country from incoming locale 637cdf0e10cSrcweir // e.g. "de-DE" => "de" or "en-US" => "en"! 638cdf0e10cSrcweir if (aLocale.getCountry().getLength()) 639cdf0e10cSrcweir { 640cdf0e10cSrcweir aLocale.setCountry(::rtl::OUString()); 641cdf0e10cSrcweir return sal_True; 642cdf0e10cSrcweir } 643cdf0e10cSrcweir 644cdf0e10cSrcweir // e) "en-US" possible? 645cdf0e10cSrcweir if (!aLocale.equals(EN_US())) 646cdf0e10cSrcweir { 647cdf0e10cSrcweir aLocale = EN_US(); 648cdf0e10cSrcweir return sal_True; 649cdf0e10cSrcweir } 650cdf0e10cSrcweir 651cdf0e10cSrcweir // f) no more fallbacks 652cdf0e10cSrcweir return sal_False; 653cdf0e10cSrcweir } 654cdf0e10cSrcweir 655cdf0e10cSrcweir //----------------------------------------------- 656cdf0e10cSrcweir void Locale::operator=(const Locale& rCopy) 657cdf0e10cSrcweir { 658cdf0e10cSrcweir // Take over these values without checking ... 659cdf0e10cSrcweir // They was already checked if the copy was constructed 660cdf0e10cSrcweir // and must be valid now! 661cdf0e10cSrcweir m_sLanguage = rCopy.m_sLanguage; 662cdf0e10cSrcweir m_sCountry = rCopy.m_sCountry; 663cdf0e10cSrcweir m_sVariant = rCopy.m_sVariant; 664cdf0e10cSrcweir } 665cdf0e10cSrcweir 666cdf0e10cSrcweir //----------------------------------------------- 667cdf0e10cSrcweir sal_Bool Locale::operator==(const Locale& aComparable) const 668cdf0e10cSrcweir { 669cdf0e10cSrcweir return equals(aComparable); 670cdf0e10cSrcweir } 671cdf0e10cSrcweir 672cdf0e10cSrcweir //----------------------------------------------- 673cdf0e10cSrcweir sal_Bool Locale::operator!=(const Locale& aComparable) const 674cdf0e10cSrcweir { 675cdf0e10cSrcweir return !equals(aComparable); 676cdf0e10cSrcweir } 677cdf0e10cSrcweir 678cdf0e10cSrcweir } // namespace comphelper 679cdf0e10cSrcweir 680