Ticket #5970: kits_locale.patch

File kits_locale.patch, 3.2 KB (added by Karvjorm, 10 years ago)

A 24-hour and country encoding patch

  • src/kits/locale/Country.cpp

     
    88#include <Country.h>
    99
    1010#include <assert.h>
     11#include <string.h>
    1112
    1213#include <IconUtils.h>
    1314#include <Resources.h>
     
    5253}
    5354
    5455
    55 BCountry::BCountry(const char* languageAndCountryCode)
     56/*!
     57    Parameter for the method should follow one of the following models:
     58    "en_US@ISO-8859-1", en_US@ISO-8859-15" "en_US@euro" "en_US@utf8"
     59    "en_US@utf-8" "en_US@UTF8" "en_US@UTF-8""en_US.ISO-8859-1",
     60    "en_US.ISO-8859-15" "en_US.euro" "en_US.utf8" "en_US.utf-8", "en_US.UTF8"
     61    and "en_US.UTF-8".
     62*/
     63BCountry::BCountry(const char* languageAndCountryCodeAtEncoding)
    5664    :
    5765    fStrings(gStrings)
    5866{
    59     fICULocale = new icu_4_2::Locale(languageAndCountryCode);
     67    int len = strcspn(languageAndCountryCodeAtEncoding, "@.");
     68    if (len < strlen(languageAndCountryCodeAtEncoding) {
     69        char languageAndCountryCode[512];
     70        strncpy(languageAndCountryCode, languageAndCountryCodeAtEncoding, len);
     71        languageAndCountryCode[len]='\0';
     72
     73        int langSize = strlen(languageAndCountryCode);
     74        int paramSize = strlen(languageAndCountryCodeAtEncoding);
     75        char encoding[512];
     76
     77        if (paramSize > (langSize+1)) {
     78            len = paramSize-langSize-1;
     79            strncpy(encoding, languageAndCountryCodeAtEncoding+(langSize+1), len);
     80            encoding[len] = '\0';
     81        } else
     82            encoding[0] = '\0';
     83   
     84        fICULocale = new icu_4_2::Locale(languageAndCountryCode);
     85        fICULocale->setEncoding(encoding);
     86    } else
     87        fICULocale = new icu_4_2::Locale(languageAndCountryCodeAtEncoding);
     88       
    6089    fICULongDateFormatter = DateFormat::createDateInstance(
    6190        DateFormat::FULL, *fICULocale);
    6291    fICUShortDateFormatter = DateFormat::createDateInstance(
    6392        DateFormat::SHORT, *fICULocale);
     93    fICULocale->setEncoding("");
    6494}
    6595
    6696
     
    111141}
    112142
    113143
     144bool
     145BCountry::Encoding(BString& code) const
     146{
     147    UnicodeString uString;
     148    fICULocale->getEncoding(uString);
     149    BStringByteSink stringConverter(&code);
     150    uString.toUTF8(stringConverter);
     151    return true;
     152}
     153
     154
    114155// TODO use ICU backend keywords instead
    115156const char*
    116157BCountry::GetString(uint32 id) const
     
    247288
    248289
    249290void
     291BCountry::Set24HourClock(bool clock)
     292{
     293    fIsClock24Hour = clock;
     294}
     295
     296
     297bool
     298BCountry::IsClock24Hour() const
     299{
     300    return fIsClock24Hour;
     301}
     302
     303
     304void
    250305BCountry::FormatNumber(char* string, size_t maxSize, double value)
    251306{
    252307    BString fullString;
  • src/kits/locale/LocaleRoster.cpp

     
    192192    BMessage fPreferredLanguages;
    193193    BString fCountryCodeName;
    194194    BString fCountryDateFormat;
     195    bool    fIsClock24Hour;
    195196
    196197    RosterData();
    197198    ~RosterData();
     
    247248
    248249            if (settingsMessage.FindString("country", &fCountryCodeName) != B_OK)
    249250                fCountryCodeName = "en_US";
     251            fIsClock24Hour = false;
    250252            return;
    251253        }
    252254    }
     
    255257    // set everything to default values
    256258    fPreferredLanguages.AddString("language", "en");
    257259    fCountryCodeName = "en_US";
     260    fIsClock24Hour = false;
    258261    log_team(LOG_ERR,"*** No language preference found!\n");
    259262}
    260263