sl@0: /* sl@0: * Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: * All rights reserved. sl@0: * This component and the accompanying materials are made available sl@0: * under the terms of "Eclipse Public License v1.0" sl@0: * which accompanies this distribution, and is available sl@0: * at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: * sl@0: * Initial Contributors: sl@0: * Nokia Corporation - initial contribution. sl@0: * sl@0: * Contributors: sl@0: * sl@0: * Description: Contains the source for all locale related functionalities sl@0: * sl@0: * sl@0: */ sl@0: sl@0: sl@0: #include sl@0: #include sl@0: #include "localeinfo.h" sl@0: #include "sysif.h" sl@0: #include sl@0: #include sl@0: sl@0: typedef void (*TLibFn)(TLocale*); sl@0: sl@0: #if (defined(__SYMBIAN32__) && (defined(__WINSCW__) || defined(__WINS__))) sl@0: #include "libc_wsd_defs.h" sl@0: #include "localetlsinfo.h" sl@0: #else sl@0: sl@0: #ifdef SYMBIAN_DISTINCT_LOCALE_MODEL sl@0: #define NEW_LANG_VARIANT_DLL_NAME 30 sl@0: #endif sl@0: sl@0: #endif sl@0: #define LC_TIME_MEMORY 1024 sl@0: #define LC_MONETARY_MEMORY 50 sl@0: #define LC_NUMERIC_MEMORY 20 sl@0: #define MONTHS 12 sl@0: #define WEEKDAYS 7 sl@0: #define DECIMAL_THOUSAND_DATE_TIME_SEPARATOR 2 sl@0: #define EURO_CURRENCY 4 sl@0: #define LOCALE_LENGTH 50 sl@0: #define CHARACTER_SET_NAME 32 sl@0: #define TIME_FORMAT_LENGTH 32 sl@0: #define NON_UNICODE_TEXT_BUFFER_LENGTH 256 sl@0: #define LANG_VARIANT_DLL_NAME 10 sl@0: sl@0: #define MONTH_STR "%m" sl@0: #define DAY_STR "%d" sl@0: #define YEAR_STR "%Y" sl@0: #define TWELVE_HOUR_STR "%I" sl@0: #define TWENTY_FOUR_HOUR_STR "%H" sl@0: #define MINUTE_STR "%M" sl@0: #define SECOND_STR "%S" sl@0: #define AMPM_SPACE " %p" sl@0: #define AMPM_NO_SPACE "%p" sl@0: sl@0: sl@0: #ifdef SYMBIAN_DISTINCT_LOCALE_MODEL sl@0: sl@0: sl@0: _LIT(KLanDllName, "elocl_lan."); sl@0: _LIT(KRegDllName, "elocl_reg."); sl@0: _LIT(KColDllName, "elocl_col."); sl@0: sl@0: #endif sl@0: sl@0: _LIT(KDllName, "elocl"); sl@0: sl@0: sl@0: #ifndef SYMBIAN_OE_ENHANCED_LOCALE_SUPPORT sl@0: _LIT(KEuro, "\x20AC"); sl@0: #endif sl@0: sl@0: _LIT8(KAMPMSpace12hr, "B"); sl@0: _LIT8(KAMPMSpace, "A"); sl@0: _LIT8(KAMPMNoSpace12hr, "*B"); sl@0: _LIT8(KAMPMNoSpace, "*A"); sl@0: sl@0: #ifndef EMULATOR sl@0: sl@0: CLocale* CLocale::iNewLocale = NULL; sl@0: lc_monetary_T* CLocale::iMonetary_locale = NULL; sl@0: lc_numeric_T* CLocale::iNumeric_locale =NULL; sl@0: lc_time_T* CLocale::iTime_locale = NULL; sl@0: sl@0: TText8* numericLocale = NULL; sl@0: TText8* monetaryLocale = NULL; sl@0: TText8* timeLocale = NULL; sl@0: sl@0: static TBuf DllName; sl@0: sl@0: #ifdef SYMBIAN_DISTINCT_LOCALE_MODEL sl@0: static TBuf ColDllName; sl@0: #endif sl@0: sl@0: #else //EMULATOR sl@0: sl@0: #define iNewLocale ((GetGlobals()->localeptr)->GET_WSD_VAR_NAME(iNewLocale,s)) sl@0: #define iMonetary_locale ((GetGlobals()->localeptr)->GET_WSD_VAR_NAME(iMonetary_locale,s)) sl@0: #define iNumeric_locale ((GetGlobals()->localeptr)->GET_WSD_VAR_NAME(iNumeric_locale,s)) sl@0: #define iTime_locale ((GetGlobals()->localeptr)->GET_WSD_VAR_NAME(iTime_locale,s)) sl@0: sl@0: #define numericLocale ((GetGlobals()->localeptr)->GET_WSD_VAR_NAME(numericLocale,s)) sl@0: #define monetaryLocale ((GetGlobals()->localeptr)->GET_WSD_VAR_NAME(monetaryLocale,s)) sl@0: #define timeLocale ((GetGlobals()->localeptr)->GET_WSD_VAR_NAME(timeLocale,s)) sl@0: sl@0: #define DllName ((GetGlobals()->localeptr)->GET_WSD_VAR_NAME(DllName,s)) sl@0: sl@0: #ifdef SYMBIAN_DISTINCT_LOCALE_MODEL sl@0: sl@0: #define ColDllName ((GetGlobals()->localeptr)->GET_WSD_VAR_NAME(ColDllName,s)) sl@0: #endif sl@0: sl@0: #endif //EMULATOR sl@0: sl@0: CLocale::CLocale() sl@0: { sl@0: iMonetary_locale = NULL; sl@0: iNumeric_locale = NULL; sl@0: iTime_locale = NULL; sl@0: sl@0: numericLocale = NULL; sl@0: monetaryLocale = NULL; sl@0: timeLocale = NULL; sl@0: #ifdef SYMBIAN_DISTINCT_LOCALE_MODEL sl@0: iOldDllPresent = 0; sl@0: #endif sl@0: } sl@0: sl@0: sl@0: sl@0: CLocale* CLocale::New() sl@0: { sl@0: CLocale* self = new CLocale(); sl@0: if(self) sl@0: { sl@0: TInt ret=KErrNone; sl@0: TRAPD(result,ret = self->ConstructL()); sl@0: if(KErrNone != (result | ret)) sl@0: { sl@0: delete self; sl@0: self = NULL; sl@0: } sl@0: } sl@0: return self; sl@0: } sl@0: sl@0: TInt CLocale::ConstructL() sl@0: { sl@0: iMonetary_locale = new lc_monetary_T; sl@0: if(!iMonetary_locale) sl@0: { sl@0: return KErrNoMemory; sl@0: } sl@0: iNumeric_locale = new lc_numeric_T; sl@0: if(!iNumeric_locale) sl@0: { sl@0: return KErrNoMemory; sl@0: } sl@0: iTime_locale = new (ELeave) lc_time_T; sl@0: if(!iTime_locale) sl@0: { sl@0: return KErrNoMemory; sl@0: } sl@0: sl@0: for(TInt i =0 ; i < MONTHS; i++) sl@0: { sl@0: iTime_locale->mon[i] = NULL; sl@0: iTime_locale->month[i] = NULL; sl@0: iTime_locale->alt_month[i] = NULL; sl@0: } sl@0: sl@0: sl@0: for(TInt i =0 ; i < WEEKDAYS; i++) sl@0: { sl@0: iTime_locale->wday[i] = NULL; sl@0: iTime_locale->weekday[i] = NULL; sl@0: } sl@0: sl@0: iTime_locale->X_fmt = NULL; sl@0: iTime_locale->x_fmt = NULL; sl@0: iTime_locale->c_fmt = NULL; sl@0: iTime_locale->am = NULL; sl@0: iTime_locale->pm = NULL; sl@0: iTime_locale->date_fmt = NULL; sl@0: iTime_locale->md_order = NULL; sl@0: iTime_locale->ampm_fmt = NULL; sl@0: sl@0: iMonetary_locale->int_curr_symbol = NULL; sl@0: iMonetary_locale->currency_symbol = NULL; sl@0: iMonetary_locale->mon_decimal_point = NULL; sl@0: iMonetary_locale->mon_thousands_sep = NULL; sl@0: iMonetary_locale->mon_grouping = NULL; sl@0: iMonetary_locale->positive_sign = NULL; sl@0: iMonetary_locale->negative_sign = NULL; sl@0: iMonetary_locale->int_frac_digits = iMonetary_locale->frac_digits = NULL; sl@0: iMonetary_locale->p_cs_precedes = iMonetary_locale->int_p_cs_precedes = NULL; sl@0: iMonetary_locale->p_sep_by_space = iMonetary_locale->int_p_sep_by_space = NULL; sl@0: iMonetary_locale->n_cs_precedes = iMonetary_locale->int_n_cs_precedes = NULL; sl@0: iMonetary_locale->n_sep_by_space = iMonetary_locale->int_n_sep_by_space = NULL; sl@0: iMonetary_locale->p_sign_posn = iMonetary_locale->int_p_sign_posn = NULL; sl@0: iMonetary_locale->n_sign_posn = iMonetary_locale->int_n_sign_posn = NULL; sl@0: sl@0: iNumeric_locale->decimal_point = NULL; sl@0: iNumeric_locale->thousands_sep = NULL; sl@0: iNumeric_locale->grouping = NULL; sl@0: sl@0: return KErrNone; sl@0: } sl@0: sl@0: CLocale* CLocale::GetInstance() sl@0: { sl@0: // Switch to the backend heap sl@0: RHeap* oldheap = User::SwitchHeap(Backend()->Heap()); sl@0: sl@0: if(NULL == iNewLocale) sl@0: { sl@0: iNewLocale = New(); sl@0: } sl@0: sl@0: if(numericLocale == NULL ) sl@0: { sl@0: numericLocale = new TText8 [LC_NUMERIC_MEMORY]; sl@0: } sl@0: sl@0: if(monetaryLocale == NULL) sl@0: { sl@0: monetaryLocale = new TText8[LC_MONETARY_MEMORY]; sl@0: } sl@0: sl@0: if(timeLocale == NULL) sl@0: { sl@0: timeLocale = new TText8[LC_TIME_MEMORY]; sl@0: } sl@0: sl@0: sl@0: sl@0: //Set back the default user heap sl@0: User::SwitchHeap(oldheap); sl@0: return iNewLocale; sl@0: } sl@0: sl@0: sl@0: void CLocale::DeleteInstance() sl@0: { sl@0: // Switch to the backend heap so that deletes happen from there sl@0: RHeap* oldheap = User::SwitchHeap(Backend()->Heap()); sl@0: sl@0: delete [] timeLocale; sl@0: timeLocale =NULL; sl@0: sl@0: delete [] numericLocale; sl@0: numericLocale = NULL; sl@0: sl@0: delete [] monetaryLocale; sl@0: monetaryLocale = NULL; sl@0: sl@0: delete iMonetary_locale; sl@0: iMonetary_locale = NULL; sl@0: sl@0: delete iNumeric_locale; sl@0: iNumeric_locale = NULL; sl@0: sl@0: delete iTime_locale; sl@0: iTime_locale = NULL; sl@0: sl@0: delete iNewLocale; sl@0: iNewLocale = NULL; sl@0: sl@0: sl@0: sl@0: //Set back to the default user heap sl@0: User::SwitchHeap(oldheap); sl@0: } sl@0: sl@0: sl@0: TText* CLocale::SetLocale(TDesC& aLocale) sl@0: { sl@0: //Check whether locale is supported sl@0: sl@0: TText* retVal = NULL; sl@0: TInt r; sl@0: #ifdef SYMBIAN_DISTINCT_LOCALE_MODEL sl@0: sl@0: // load the new locale dll if not present check for the old dll sl@0: r = LoadNewLocaleDll( aLocale ); sl@0: if ( r == KErrNone ) sl@0: { sl@0: retVal = (TText*) aLocale.Ptr(); sl@0: iOldDllPresent = 0; sl@0: return retVal; sl@0: } sl@0: #endif sl@0: sl@0: if(!LoadLocale(aLocale)) sl@0: { sl@0: return NULL; sl@0: } sl@0: RLoader loader; sl@0: r = loader.Connect(); sl@0: if(KErrNone == r) sl@0: { sl@0: //Load the language variant DLL sl@0: TInt size = KNumLocaleExports * sizeof(TLibraryFunction); sl@0: TPtr8 functionListBuf((TUint8*) iData, size, size); sl@0: r = loader.SendReceive(ELoadLocale, TIpcArgs(0, (const TDesC*)&DllName, &functionListBuf) ); sl@0: if(KErrNone == r) sl@0: { sl@0: ((TLibFn)iData[FnLocaleData])(&iLocale); sl@0: retVal = (TText*) aLocale.Ptr(); sl@0: #ifdef SYMBIAN_DISTINCT_LOCALE_MODEL sl@0: iOldDllPresent = 1; sl@0: #endif sl@0: } sl@0: loader.Close(); sl@0: } sl@0: return retVal; sl@0: } sl@0: sl@0: #ifdef SYMBIAN_OE_ENHANCED_LOCALE_SUPPORT sl@0: sl@0: #ifdef SYMBIAN_DISTINCT_LOCALE_MODEL sl@0: TInt CLocale::GetSystemLocale(TDesC& aLanDllName,TDesC& aRegDllName) sl@0: { sl@0: RLoader loader; sl@0: TInt retVal = -1; sl@0: TInt r = loader.Connect(); sl@0: if(KErrNone == r) sl@0: { sl@0: TInt size = KNumLocaleExports * sizeof(TLibraryFunction); sl@0: TPtr8 functionListBuf1((TUint8*) iDataLanguage, size, size); sl@0: r = loader.SendReceive(ELoadLocale, TIpcArgs(0, (const TDesC*)&aLanDllName, &functionListBuf1) ); sl@0: if(KErrNone != r) sl@0: return retVal; sl@0: TPtr8 functionListBuf2((TUint8*) iDataRegion, size, size); sl@0: r = loader.SendReceive(ELoadLocale, TIpcArgs(0, (const TDesC*)&aRegDllName, &functionListBuf2) ); sl@0: ((TLibFn)iDataRegion[FnLocaleDataV2])(&iLocale); sl@0: if(KErrNone != r) sl@0: return retVal; sl@0: retVal = 0; sl@0: loader.Close(); sl@0: } sl@0: return retVal; sl@0: sl@0: } sl@0: #endif sl@0: //Load the system dll settings sl@0: TInt CLocale::GetSystemLocale(TDesC& aDllName) sl@0: { sl@0: RLoader loader; sl@0: TInt retVal = -1; sl@0: TInt r = loader.Connect(); sl@0: if(KErrNone == r) sl@0: { sl@0: //Load the language variant DLL sl@0: TInt size = KNumLocaleExports * sizeof(TLibraryFunction); sl@0: TPtr8 functionListBuf((TUint8*) iData, size, size); sl@0: r = loader.SendReceive(ELoadLocale, TIpcArgs(0, (const TDesC*)&aDllName, &functionListBuf) ); sl@0: if(KErrNone == r) sl@0: { sl@0: ((TLibFn)iData[FnLocaleData])(&iLocale); sl@0: retVal = 0; sl@0: } sl@0: loader.Close(); sl@0: } sl@0: return retVal; sl@0: } sl@0: sl@0: #endif sl@0: sl@0: sl@0: TInt CLocale::MonetaryLoadLocaleL(const char* localeName) sl@0: { sl@0: #ifdef SYMBIAN_OE_ENHANCED_LOCALE_SUPPORT sl@0: TInt charsetID=-1; sl@0: if(localeName) sl@0: { sl@0: charsetID = GetCharcaterSetIDL(localeName); sl@0: if(charsetID == -1) sl@0: { sl@0: return -1; sl@0: } sl@0: } sl@0: #else sl@0: TInt charsetID = GetCharcaterSetIDL(localeName); sl@0: if(charsetID == -1) sl@0: { sl@0: return -1; sl@0: } sl@0: #endif sl@0: #ifdef SYMBIAN_OE_ENHANCED_LOCALE_SUPPORT sl@0: else sl@0: { sl@0: //update the iLocale with the system locale settings sl@0: iLocale.Refresh(); sl@0: } sl@0: #endif sl@0: #ifndef SYMBIAN_OE_ENHANCED_LOCALE_SUPPORT sl@0: //Retreive monetary information from language variant DLL sl@0: Mem::Copy(&iLocaleSettings.iCurrencySymbol[0], (const TAny*) iData[FnCurrencySymbol](), sizeof(TText) * (KMaxCurrencySymbol+1)); sl@0: #endif sl@0: TLocalePos aCurrencySymbolPosition = iLocale.CurrencySymbolPosition(); sl@0: TLocale::TNegativeCurrencyFormat aNegativeCurrencyFormat = iLocale.NegativeCurrencyFormat(); sl@0: TBool aCurrencySpaceBetween = iLocale.CurrencySpaceBetween(); sl@0: TBool aNegativeCurrencySymbolOpposite = iLocale.NegativeCurrencySymbolOpposite(); sl@0: TBool aNegativeLoseSpace = iLocale.NegativeLoseSpace(); sl@0: TBool aCurrencyTriadsAllowed = iLocale.CurrencyTriadsAllowed(); sl@0: sl@0: TInt currencyDecimalPlaces = iLocale.CurrencyDecimalPlaces(); sl@0: iThousandsSeparator= iLocale.ThousandsSeparator(); sl@0: iDecimalSeparator = iLocale.DecimalSeparator(); sl@0: sl@0: TText8* temp = monetaryLocale; sl@0: sl@0: //Set the decimal separator sl@0: const TText* dec_point = (const TText*) &iDecimalSeparator; sl@0: if(dec_point) sl@0: { sl@0: const TPtrC dec(dec_point); sl@0: TBuf8 decimal; sl@0: decimal.Copy(dec); sl@0: strncpy((char*) monetaryLocale, (char*) decimal.Ptr(), decimal.Length()); sl@0: monetaryLocale[decimal.Length()] = '\0'; sl@0: iMonetary_locale->mon_decimal_point = (const char*) monetaryLocale; sl@0: monetaryLocale += decimal.Length() + 1; sl@0: } sl@0: sl@0: //Set thousand separator sl@0: const TText* thous_sep = (const TText*) &iThousandsSeparator; sl@0: if(thous_sep) sl@0: { sl@0: const TPtrC thousand(thous_sep); sl@0: TBuf8 thousand_sep; sl@0: thousand_sep.Copy(thousand); sl@0: strncpy((char*) monetaryLocale, (char*) thousand_sep.Ptr(), thousand_sep.Length()); sl@0: monetaryLocale[thousand_sep.Length()] = '\0'; sl@0: iMonetary_locale->mon_thousands_sep = (const char*) monetaryLocale; sl@0: monetaryLocale += thousand_sep.Length() + 1; sl@0: } sl@0: #ifdef SYMBIAN_OE_ENHANCED_LOCALE_SUPPORT sl@0: TBuf CurrencySymbol; sl@0: if(localeName) sl@0: { sl@0: #ifdef SYMBIAN_DISTINCT_LOCALE_MODEL sl@0: if( iOldDllPresent ) // old style dll is loaded sl@0: { sl@0: Mem::Copy(&iLocaleSettings.iCurrencySymbol[0], (const TAny*) iData[FnCurrencySymbol](), sizeof(TText) * (KMaxCurrencySymbol+1)); sl@0: } sl@0: else sl@0: { sl@0: Mem::Copy(&iLocaleSettings.iCurrencySymbol[0], (const TAny*) iDataRegion[FnCurrencySymbolV2](), sizeof(TText) * (KMaxCurrencySymbol+1)); sl@0: } sl@0: #else sl@0: Mem::Copy(&iLocaleSettings.iCurrencySymbol[0], (const TAny*) iData[FnCurrencySymbol](), sizeof(TText) * (KMaxCurrencySymbol+1)); sl@0: #endif sl@0: //Set Currency information sl@0: const TText16* cur = iLocaleSettings.iCurrencySymbol; sl@0: const TPtrC currency(cur); sl@0: CurrencySymbol.Copy(currency); sl@0: } sl@0: else sl@0: { sl@0: TCurrencySymbol cur; sl@0: const TPtrC currency(cur); sl@0: CurrencySymbol.Copy(currency); sl@0: } sl@0: strncpy((char*) monetaryLocale, (char*) CurrencySymbol.Ptr(), CurrencySymbol.Length()); sl@0: monetaryLocale[CurrencySymbol.Length()] = '\0'; sl@0: iMonetary_locale->currency_symbol = (const char*) monetaryLocale; sl@0: monetaryLocale += strlen((char*) monetaryLocale) + 1; sl@0: #else sl@0: //Set Currency information sl@0: const TText16* currency = iLocaleSettings.iCurrencySymbol; sl@0: if(currency) sl@0: { sl@0: TBuf euroSymbol(currency); sl@0: char* temp = strchr(localeName, '.'); sl@0: temp = temp + 1; sl@0: sl@0: if(!euroSymbol.Compare(KEuro) && !strcmp(temp, "ISO-8859-1")) sl@0: { sl@0: strcpy((char*) monetaryLocale,"\x80"); sl@0: monetaryLocale[1] = '\0'; sl@0: } sl@0: else sl@0: { sl@0: ConvertToMultiByteL((TText8*)monetaryLocale, currency, charsetID); sl@0: } sl@0: iMonetary_locale->currency_symbol = (const char*) monetaryLocale; sl@0: monetaryLocale += strlen((char*) monetaryLocale) + 1; sl@0: } sl@0: #endif sl@0: sl@0: //Set grouping information sl@0: strcpy((char*) monetaryLocale,(aCurrencyTriadsAllowed? "\003":"")); sl@0: monetaryLocale[strlen((char*) monetaryLocale)] = '\0'; sl@0: iMonetary_locale->mon_grouping = (const char*) monetaryLocale; sl@0: monetaryLocale += strlen((char*) monetaryLocale) + 1; sl@0: sl@0: //Set currency decimal places sl@0: iMonetary_locale->int_frac_digits = iMonetary_locale->frac_digits = (const char*) monetaryLocale; sl@0: *monetaryLocale++ = currencyDecimalPlaces; sl@0: *monetaryLocale++ = '\0'; sl@0: sl@0: //Set the currency symbol position for a monetary quantity with non-negative value sl@0: iMonetary_locale->p_cs_precedes = (const char*) monetaryLocale; sl@0: iMonetary_locale->int_p_cs_precedes = iMonetary_locale->p_cs_precedes; sl@0: *monetaryLocale++ = (ELocaleBefore == aCurrencySymbolPosition)?1:0; sl@0: *monetaryLocale++ = '\0'; sl@0: sl@0: //Set the currency symbol position for a monetary quantity with negative value sl@0: iMonetary_locale->n_cs_precedes = (const char*) monetaryLocale; sl@0: iMonetary_locale->int_n_cs_precedes = iMonetary_locale->n_cs_precedes; sl@0: *monetaryLocale++ = aNegativeCurrencySymbolOpposite?0:1; sl@0: *monetaryLocale++ ='\0'; sl@0: sl@0: //Set the currency symbol separated by space or not for a monetary quantity with non-negative value sl@0: iMonetary_locale->p_sep_by_space = (const char*) monetaryLocale; sl@0: iMonetary_locale->int_p_sep_by_space = iMonetary_locale->p_sep_by_space; sl@0: *monetaryLocale++ = aCurrencySpaceBetween?1:0; sl@0: *monetaryLocale++ ='\0'; sl@0: sl@0: //Set the currency symbol separated by space or not for a monetary quantity with negative value sl@0: iMonetary_locale->n_sep_by_space = (const char*) monetaryLocale; sl@0: iMonetary_locale->int_n_sep_by_space = iMonetary_locale->n_sep_by_space; sl@0: *monetaryLocale++ = aNegativeLoseSpace?1:0; sl@0: *monetaryLocale++ = '\0'; sl@0: sl@0: //Set the positioning of the negative and positive for a monetary quantity sl@0: if(TLocale::ELeadingMinusSign == aNegativeCurrencyFormat) sl@0: { sl@0: iMonetary_locale->n_sign_posn = (const char*) monetaryLocale; sl@0: *monetaryLocale++ = 1; sl@0: *monetaryLocale++ = '\0'; sl@0: } sl@0: if(TLocale::EInBrackets == aNegativeCurrencyFormat) sl@0: { sl@0: iMonetary_locale->n_sign_posn = (const char*) monetaryLocale; sl@0: *monetaryLocale++ = 0; sl@0: *monetaryLocale++ = '\0'; sl@0: } sl@0: sl@0: if(TLocale::ETrailingMinusSign == aNegativeCurrencyFormat) sl@0: { sl@0: iMonetary_locale->n_sign_posn = (const char*) monetaryLocale; sl@0: *monetaryLocale++ = 2; sl@0: *monetaryLocale++ = '\0'; sl@0: } sl@0: sl@0: if(TLocale::EInterveningMinusSign == aNegativeCurrencyFormat) sl@0: { sl@0: iMonetary_locale->n_sign_posn = (const char*) monetaryLocale; sl@0: *monetaryLocale++ = 3; sl@0: *monetaryLocale++ = '\0'; sl@0: } sl@0: sl@0: iMonetary_locale->int_n_sign_posn = iMonetary_locale->n_sign_posn; sl@0: iMonetary_locale->p_sign_posn = iMonetary_locale->int_p_sign_posn = iMonetary_locale->n_sign_posn; sl@0: //Set the positive sign and negative sign for monetary quantity sl@0: iMonetary_locale->positive_sign = iMonetary_locale->negative_sign = ""; sl@0: //Set the internationla currency symbol sl@0: iMonetary_locale->int_curr_symbol = ""; sl@0: monetaryLocale = temp; sl@0: return 0; sl@0: sl@0: sl@0: } sl@0: /* Forward declaration of ReadALine */ sl@0: inline TInt ReadALine(RFile& aFile, TInt& aPos, TDes8& aDesc); sl@0: extern void GetInstallationDataDir(TFileName& aPath); sl@0: #ifdef SYMBIAN_DISTINCT_LOCALE_MODEL sl@0: sl@0: TInt CLocale::ParseNewLocaleFile( TDesC& aLocale ) sl@0: { sl@0: // open and parse the file sl@0: TPtrC src(aLocale); sl@0: TBuf8 locale_name; sl@0: locale_name.Copy(src); sl@0: char locale[LOCALE_LENGTH]; sl@0: strncpy(locale, (char*) locale_name.Ptr(), locale_name.Length()); sl@0: locale[locale_name.Length()] = '\0'; sl@0: sl@0: if (NULL == strchr(locale, '.')) sl@0: { sl@0: return 0; sl@0: } sl@0: RFile newfile; sl@0: #ifndef __EPOC32__ sl@0: _LIT(localeFileNew,"\\resource\\openc\\locales_new.txt" ); sl@0: #else sl@0: TFileName localeFileNew; sl@0: GetInstallationDataDir(localeFileNew); sl@0: localeFileNew.Append(_L("locales_new.txt" )); sl@0: #endif sl@0: sl@0: int retValNew = newfile.Open(Backend()->FileSession(), localeFileNew, EFileRead); sl@0: if( KErrNone != retValNew ) sl@0: { sl@0: return 0; sl@0: } sl@0: int pos = 0; sl@0: TBuf8 localeInfoNew; sl@0: retValNew = ReadALine(newfile, pos, localeInfoNew); sl@0: char* buffer = (char*) localeInfoNew.Ptr(); sl@0: int i = 0; sl@0: int flag = 0; sl@0: while( retValNew > 0) sl@0: { sl@0: char str1[LOCALE_LENGTH]; sl@0: while(buffer[i] != '=') sl@0: { sl@0: str1[i] = buffer[i]; sl@0: i++; sl@0: } sl@0: str1[i] = '\0'; sl@0: if(!strcmp(str1,locale)) sl@0: { sl@0: flag = 1; sl@0: break; sl@0: } sl@0: i = 0; sl@0: retValNew = ReadALine(newfile, pos, localeInfoNew); sl@0: buffer = (char*) localeInfoNew.Ptr(); sl@0: } sl@0: if(flag) sl@0: { sl@0: sl@0: iLanDllName.Copy(KLanDllName); sl@0: iRegDllName.Copy(KRegDllName); sl@0: ColDllName.Copy(KColDllName); sl@0: i++; sl@0: int len = localeInfoNew.Length(); sl@0: TBuf<50> localeids; sl@0: while(i < len ) sl@0: { sl@0: localeids.Append(buffer[i]); sl@0: i++; sl@0: } sl@0: TLex lex( localeids ); sl@0: TChar ch; sl@0: TInt k = 0; sl@0: TBuf<10> token[3]; sl@0: while((ch = lex.Get()) != 0 ) sl@0: { sl@0: while (ch != ',' && ch != 0 && ch != '\t' && ch != '\n' && ch != '\r') sl@0: { sl@0: lex.Inc(); sl@0: ch = lex.Peek(); sl@0: } sl@0: token[k].Copy(lex.MarkedToken()); sl@0: k++; sl@0: lex.Inc(); sl@0: lex.Mark(); sl@0: } sl@0: iLanDllName.Append(token[0]); sl@0: iRegDllName.Append(token[1]); sl@0: ColDllName.Append(token[2]); sl@0: newfile.Close(); sl@0: return 1; sl@0: sl@0: } sl@0: newfile.Close(); sl@0: return 0; sl@0: } sl@0: sl@0: TInt CLocale::LoadNewLocaleDll( TDesC& aLocale ) sl@0: { sl@0: sl@0: if(!ParseNewLocaleFile( aLocale )) sl@0: { sl@0: return -1; sl@0: } sl@0: RLoader loader; sl@0: TInt r = loader.Connect(); sl@0: if( KErrNone != r) sl@0: return -1; sl@0: TInt size = KNumLocaleExports * sizeof(TLibraryFunction); sl@0: TPtr8 functionListBuf((TUint8*) iDataRegion, size, size ); sl@0: r = loader.SendReceive(ELoadLocale, TIpcArgs(0, (const TDesC*)&iRegDllName, &functionListBuf) ); sl@0: if( KErrNone != r) sl@0: return -1; sl@0: ((TLibFn)iDataRegion[FnLocaleDataV2])(&iLocale); sl@0: // language dll loading sl@0: TPtr8 functionListBuf_lan((TUint8*) iDataLanguage, size, size); sl@0: r = loader.SendReceive(ELoadLocale, TIpcArgs(0, (const TDesC*)&iLanDllName, &functionListBuf_lan) ); sl@0: if( KErrNone != r) sl@0: return -1; sl@0: sl@0: return r; sl@0: sl@0: } sl@0: sl@0: #endif sl@0: sl@0: sl@0: sl@0: #ifdef SYMBIAN_OE_ENHANCED_LOCALE_SUPPORT sl@0: TInt CLocale::NumericLoadLocale(const char* localeName) sl@0: #else sl@0: TInt CLocale::NumericLoadLocale(const char* /*localeName*/) sl@0: #endif sl@0: { sl@0: #ifdef SYMBIAN_OE_ENHANCED_LOCALE_SUPPORT sl@0: if(!localeName) sl@0: { sl@0: //update the iLocale with the system settings sl@0: iLocale.Refresh(); sl@0: sl@0: } sl@0: #endif sl@0: //Retrive numeric information from language variant DLL sl@0: TBool aCurrencyTriadsAllowed = iLocale.CurrencyTriadsAllowed(); sl@0: iThousandsSeparator= iLocale.ThousandsSeparator(); sl@0: iDecimalSeparator = iLocale.DecimalSeparator(); sl@0: sl@0: TText8* temp = numericLocale; sl@0: //Set the decimal separator sl@0: const TText* dec_point = (const TText*) &iDecimalSeparator; sl@0: if(dec_point) sl@0: { sl@0: const TPtrC dec(dec_point); sl@0: TBuf8 decimal; sl@0: decimal.Copy(dec); sl@0: strncpy((char*) numericLocale, (char*) decimal.Ptr(), decimal.Length()); sl@0: numericLocale[decimal.Length()] ='\0'; sl@0: iNumeric_locale->decimal_point = (const char*) numericLocale; sl@0: numericLocale += decimal.Length() + 1; sl@0: } sl@0: sl@0: //Set thousand separator sl@0: const TText* thous_sep = (const TText*) &iThousandsSeparator; sl@0: if(thous_sep) sl@0: { sl@0: const TPtrC thousand(thous_sep); sl@0: TBuf8 thousand_sep; sl@0: thousand_sep.Copy(thousand); sl@0: strncpy((char*) numericLocale, (char*) thousand_sep.Ptr(), thousand_sep.Length()); sl@0: numericLocale[thousand_sep.Length()] = '\0'; sl@0: iNumeric_locale->thousands_sep = (const char*) numericLocale; sl@0: numericLocale += thousand_sep.Length() + 1; sl@0: } sl@0: sl@0: //Set grouping information sl@0: strcpy((char*) numericLocale,(aCurrencyTriadsAllowed? "\003":"")); sl@0: numericLocale[strlen((char*) numericLocale)] = '\0'; sl@0: iNumeric_locale->grouping = (const char*) numericLocale; sl@0: numericLocale += strlen((char*) numericLocale) + 1; sl@0: sl@0: numericLocale = temp; sl@0: return 0; sl@0: sl@0: } sl@0: sl@0: #ifdef SYMBIAN_DISTINCT_LOCALE_MODEL sl@0: sl@0: sl@0: TInt CLocale::TimeLoadNewLocaleL( const char* localeName ) sl@0: { sl@0: TInt charsetID = -1; sl@0: if( localeName ) sl@0: { sl@0: charsetID = GetCharcaterSetIDL(localeName); sl@0: if(charsetID == -1) sl@0: { sl@0: return -1; sl@0: } sl@0: } sl@0: else sl@0: { sl@0: //update the iLocale with the system locale settings sl@0: iLocale.Refresh(); sl@0: } sl@0: TText8* startAddress = timeLocale; sl@0: //Set month and abbreviated month name information sl@0: for(TInt aMonth = 0 ; aMonth < MONTHS; aMonth++) sl@0: { sl@0: sl@0: const TText16* month = ((reinterpret_cast((const TText*) iDataLanguage[FnMonthTableV2]()))[aMonth]); sl@0: if(month) sl@0: { sl@0: #ifdef SYMBIAN_OE_ENHANCED_LOCALE_SUPPORT sl@0: if(!localeName) sl@0: { sl@0: ConvertToMultiByteCustom((TUint8*)timeLocale, month); sl@0: } sl@0: else sl@0: { sl@0: #endif sl@0: ConvertToMultiByteL((TUint8*)timeLocale, month, charsetID); sl@0: #ifdef SYMBIAN_OE_ENHANCED_LOCALE_SUPPORT sl@0: } sl@0: #endif sl@0: iTime_locale->month[aMonth] = (const char*) timeLocale; sl@0: iTime_locale->alt_month[aMonth] = (const char*) timeLocale; sl@0: timeLocale += strlen((char*) timeLocale) + 1; sl@0: } sl@0: const TText16* abbMonth = ((reinterpret_cast((const TText*) iDataLanguage[FnMonthAbbTableV2]()))[aMonth]); sl@0: if(abbMonth) sl@0: { sl@0: #ifdef SYMBIAN_OE_ENHANCED_LOCALE_SUPPORT sl@0: if(!localeName) sl@0: { sl@0: ConvertToMultiByteCustom((TUint8*)timeLocale, abbMonth); sl@0: } sl@0: else sl@0: { sl@0: #endif sl@0: ConvertToMultiByteL((TUint8*)timeLocale, abbMonth, charsetID); sl@0: #ifdef SYMBIAN_OE_ENHANCED_LOCALE_SUPPORT sl@0: } sl@0: #endif sl@0: iTime_locale->mon[aMonth] = (const char*) timeLocale; sl@0: timeLocale += strlen((char*) timeLocale) + 1; sl@0: } sl@0: sl@0: } sl@0: sl@0: //Set day and abbreviated day name information sl@0: const TText16* day = ((reinterpret_cast((const TText*) iDataLanguage[FnDayTableV2]()))[6]); sl@0: if(day) sl@0: { sl@0: #ifdef SYMBIAN_OE_ENHANCED_LOCALE_SUPPORT sl@0: if(!localeName) sl@0: { sl@0: ConvertToMultiByteCustom((TUint8*)timeLocale, day); sl@0: } sl@0: else sl@0: { sl@0: #endif sl@0: ConvertToMultiByteL((TUint8*)timeLocale, day, charsetID); sl@0: #ifdef SYMBIAN_OE_ENHANCED_LOCALE_SUPPORT sl@0: } sl@0: #endif sl@0: iTime_locale->weekday[0] = (const char*) timeLocale; sl@0: timeLocale += strlen((char*) timeLocale) + 1; sl@0: } sl@0: const TText16* abbDay = ((reinterpret_cast((const TText*) iDataLanguage[FnDayAbbTableV2]()))[6]); sl@0: if(abbDay) sl@0: { sl@0: #ifdef SYMBIAN_OE_ENHANCED_LOCALE_SUPPORT sl@0: if(!localeName) sl@0: { sl@0: ConvertToMultiByteCustom((TUint8*)timeLocale, abbDay); sl@0: } sl@0: else sl@0: { sl@0: #endif sl@0: ConvertToMultiByteL((TUint8*)timeLocale, abbDay, charsetID); sl@0: #ifdef SYMBIAN_OE_ENHANCED_LOCALE_SUPPORT sl@0: } sl@0: #endif sl@0: iTime_locale->wday[0] = (const char*) timeLocale; sl@0: timeLocale += strlen((char*) timeLocale) + 1; sl@0: } sl@0: sl@0: for(TInt aDay = 0 ; aDay < WEEKDAYS - 1; aDay++) sl@0: { sl@0: const TText16* day = ((reinterpret_cast((const TText*) iDataLanguage[FnDayTableV2]()))[aDay]); sl@0: if(day) sl@0: { sl@0: #ifdef SYMBIAN_OE_ENHANCED_LOCALE_SUPPORT sl@0: if(!localeName) sl@0: { sl@0: ConvertToMultiByteCustom((TUint8*)timeLocale, day); sl@0: } sl@0: else sl@0: { sl@0: #endif sl@0: ConvertToMultiByteL((TUint8*)timeLocale, day, charsetID); sl@0: #ifdef SYMBIAN_OE_ENHANCED_LOCALE_SUPPORT sl@0: } sl@0: #endif sl@0: iTime_locale->weekday[aDay + 1] = (const char*) timeLocale; sl@0: timeLocale += strlen((char*) timeLocale) + 1; sl@0: } sl@0: const TText16* abbDay = ((reinterpret_cast((const TText*) iDataLanguage[FnDayAbbTableV2]()))[aDay]); sl@0: if(abbDay) sl@0: { sl@0: #ifdef SYMBIAN_OE_ENHANCED_LOCALE_SUPPORT sl@0: if(!localeName) sl@0: { sl@0: ConvertToMultiByteCustom((TUint8*)timeLocale, abbDay); sl@0: } sl@0: else sl@0: { sl@0: #endif sl@0: ConvertToMultiByteL((TUint8*)timeLocale, abbDay, charsetID); sl@0: #ifdef SYMBIAN_OE_ENHANCED_LOCALE_SUPPORT sl@0: } sl@0: #endif sl@0: iTime_locale->wday[aDay + 1] = (const char*) timeLocale; sl@0: timeLocale += strlen((char*) timeLocale) + 1; sl@0: } sl@0: sl@0: } sl@0: const TText16* am = ((reinterpret_cast((const TText*) iDataLanguage[FnAmPmTableV2]()))[0]); sl@0: if(am) sl@0: { sl@0: #ifdef SYMBIAN_OE_ENHANCED_LOCALE_SUPPORT sl@0: if(!localeName) sl@0: { sl@0: ConvertToMultiByteCustom((TUint8*)timeLocale, am); sl@0: } sl@0: else sl@0: { sl@0: #endif sl@0: ConvertToMultiByteL((TUint8*)timeLocale, am, charsetID); sl@0: #ifdef SYMBIAN_OE_ENHANCED_LOCALE_SUPPORT sl@0: } sl@0: #endif sl@0: iTime_locale->am = (const char*) timeLocale; sl@0: timeLocale += strlen((char*) timeLocale) + 1; sl@0: } sl@0: const TText16* pm = ((reinterpret_cast((const TText*) iDataLanguage[FnAmPmTableV2]()))[1]); sl@0: if(pm) sl@0: { sl@0: #ifdef SYMBIAN_OE_ENHANCED_LOCALE_SUPPORT sl@0: if(!localeName) sl@0: { sl@0: ConvertToMultiByteCustom((TUint8*)timeLocale, pm); sl@0: } sl@0: else sl@0: { sl@0: #endif sl@0: ConvertToMultiByteL((TUint8*)timeLocale, pm, charsetID); sl@0: #ifdef SYMBIAN_OE_ENHANCED_LOCALE_SUPPORT sl@0: } sl@0: #endif sl@0: iTime_locale->pm = (const char*) timeLocale; sl@0: timeLocale += strlen((char*) timeLocale) + 1; sl@0: } sl@0: sl@0: Mem::Copy(&iLocaleTimeDateFormat.iTimeFormatSpec[0], (const TAny*) iDataRegion[FnTimeFormatSpecV2](), sizeof(TText) * (KMaxTimeFormatSpec+1)); sl@0: TText* timeForm = iLocaleTimeDateFormat.iTimeFormatSpec; sl@0: sl@0: //Set time format(T_FMT) and am/pm time format(T_FMT_AMPM) string sl@0: if(timeForm) sl@0: { sl@0: const TPtrC time(timeForm); sl@0: TBuf8 timeFormat; sl@0: timeFormat.Copy(time); sl@0: sl@0: TChar timeSeparator = iLocale.TimeSeparator(1); sl@0: TBuf8 timeSeparator1; sl@0: timeSeparator1.Append(timeSeparator); sl@0: sl@0: timeSeparator = iLocale.TimeSeparator(2); sl@0: TBuf8 timeSeparator2; sl@0: timeSeparator2.Append(timeSeparator); sl@0: sl@0: TTimeFormat time12hror24hr = iLocale.TimeFormat(); sl@0: sl@0: if(KErrNotFound != timeFormat.Locate('J')) sl@0: { sl@0: //Check for time format(12/24 hour format) sl@0: if(time12hror24hr == ETime12) sl@0: { sl@0: strcpy((char*) timeLocale,TWELVE_HOUR_STR); sl@0: } sl@0: else sl@0: { sl@0: strcpy((char*) timeLocale,TWENTY_FOUR_HOUR_STR); sl@0: } sl@0: } sl@0: sl@0: else if(KErrNotFound != timeFormat.Locate('I')) sl@0: { sl@0: strcpy((char*) timeLocale,TWELVE_HOUR_STR); sl@0: } sl@0: sl@0: else if(KErrNotFound != timeFormat.Locate('H')) sl@0: { sl@0: strcpy((char*) timeLocale,TWENTY_FOUR_HOUR_STR); sl@0: } sl@0: sl@0: strncat((char*) timeLocale, (char*) timeSeparator1.Ptr(), timeSeparator1.Length()); sl@0: strcat((char*) timeLocale, MINUTE_STR); sl@0: strncat((char*) timeLocale, (char*) timeSeparator2.Ptr(), timeSeparator2.Length()); sl@0: strcat((char*) timeLocale, SECOND_STR); sl@0: sl@0: if(time12hror24hr == ETime12) sl@0: { sl@0: sl@0: if((KErrNotFound != timeFormat.Find(KAMPMSpace12hr)) || (KErrNotFound != timeFormat.Find(KAMPMSpace)) ) sl@0: { sl@0: if((KErrNotFound != timeFormat.Find(KAMPMNoSpace12hr)) || (KErrNotFound != timeFormat.Find(KAMPMNoSpace))) sl@0: { sl@0: strcat((char*) timeLocale, AMPM_NO_SPACE); sl@0: } sl@0: else sl@0: { sl@0: strcat((char*) timeLocale, AMPM_SPACE); sl@0: } sl@0: } sl@0: } sl@0: sl@0: iTime_locale->ampm_fmt = (const char*) timeLocale; sl@0: iTime_locale->X_fmt = iTime_locale->ampm_fmt; sl@0: timeLocale += strlen((char*) timeLocale) + 1; sl@0: } sl@0: sl@0: TDateFormat aDateFormat = iLocale.DateFormat(); sl@0: //Set date fromat string(D_FMT) sl@0: TChar dateSeparator = iLocale.DateSeparator(1); sl@0: TBuf8 dateSeparator1; sl@0: dateSeparator1.Append(dateSeparator); sl@0: sl@0: TBuf8 dateSeparator2; sl@0: dateSeparator = iLocale.DateSeparator(2); sl@0: dateSeparator2.Append(dateSeparator); sl@0: sl@0: //Americal date formt(mm/dd/YYYY) sl@0: if(EDateAmerican == aDateFormat) sl@0: { sl@0: strcpy((char*) timeLocale, MONTH_STR); sl@0: strncat((char*) timeLocale, (char*) dateSeparator1.Ptr(), dateSeparator1.Length()); sl@0: strcat((char*) timeLocale, DAY_STR); sl@0: strncat((char*) timeLocale, (char*) dateSeparator2.Ptr(), dateSeparator2.Length()); sl@0: strcat((char*) timeLocale, YEAR_STR); sl@0: iTime_locale->x_fmt = (const char*) timeLocale; sl@0: } sl@0: sl@0: //European date format(dd/mm/YYYY) sl@0: if(EDateEuropean == aDateFormat) sl@0: { sl@0: strcpy((char*) timeLocale, DAY_STR); sl@0: strncat((char*) timeLocale, (char*) dateSeparator1.Ptr(), dateSeparator1.Length()); sl@0: strcat((char*) timeLocale, MONTH_STR); sl@0: strncat((char*) timeLocale, (char*) dateSeparator2.Ptr(), dateSeparator2.Length()); sl@0: strcat((char*) timeLocale, YEAR_STR); sl@0: iTime_locale->x_fmt = (const char*) timeLocale; sl@0: } sl@0: sl@0: //Japanese date format(YYYY/mm/dd) sl@0: if(EDateJapanese == aDateFormat) sl@0: { sl@0: strcpy((char*) timeLocale, YEAR_STR); sl@0: strncat((char*) timeLocale, (char*) dateSeparator1.Ptr(), dateSeparator1.Length()); sl@0: strcat((char*) timeLocale, MONTH_STR); sl@0: strncat((char*) timeLocale, (char*) dateSeparator2.Ptr(), dateSeparator2.Length()); sl@0: strcat((char*) timeLocale, DAY_STR); sl@0: iTime_locale->x_fmt = (const char*) timeLocale; sl@0: } sl@0: sl@0: iTime_locale->md_order = iTime_locale->c_fmt = iTime_locale->date_fmt = (const char*) L""; sl@0: ; sl@0: timeLocale = startAddress; sl@0: sl@0: sl@0: sl@0: return 0; sl@0: } sl@0: #endif sl@0: TInt CLocale::TimeLoadLocaleL(const char* localeName) sl@0: { sl@0: #ifdef SYMBIAN_DISTINCT_LOCALE_MODEL sl@0: sl@0: if( ! iOldDllPresent) sl@0: { sl@0: TInt ret = TimeLoadNewLocaleL( localeName ); // option 2 to load language and region dll both sl@0: if( ret == -1 ) sl@0: return -1; sl@0: return ret; sl@0: } sl@0: #endif sl@0: TText8* startAddress = timeLocale; sl@0: #ifdef SYMBIAN_OE_ENHANCED_LOCALE_SUPPORT sl@0: TInt charsetID = -1; sl@0: if(localeName) sl@0: { sl@0: charsetID = GetCharcaterSetIDL(localeName); sl@0: if(charsetID == -1) sl@0: { sl@0: return -1; sl@0: } sl@0: } sl@0: #else sl@0: TInt charsetID = GetCharcaterSetIDL(localeName); sl@0: if(charsetID == -1) sl@0: { sl@0: return -1; sl@0: } sl@0: #endif sl@0: sl@0: sl@0: #ifdef SYMBIAN_OE_ENHANCED_LOCALE_SUPPORT sl@0: else sl@0: { sl@0: iLocale.Refresh(); sl@0: } sl@0: #endif sl@0: //Set month and abbreviated month name information sl@0: for(TInt aMonth = 0 ; aMonth < MONTHS; aMonth++) sl@0: { sl@0: sl@0: const TText16* month = ((reinterpret_cast((const TText*) iData[FnMonthTable]()))[aMonth]); sl@0: if(month) sl@0: { sl@0: #ifdef SYMBIAN_OE_ENHANCED_LOCALE_SUPPORT sl@0: if(!localeName) sl@0: { sl@0: ConvertToMultiByteCustom((TUint8*)timeLocale, month); sl@0: } sl@0: else sl@0: { sl@0: #endif sl@0: ConvertToMultiByteL((TUint8*)timeLocale, month, charsetID); sl@0: #ifdef SYMBIAN_OE_ENHANCED_LOCALE_SUPPORT sl@0: } sl@0: #endif sl@0: iTime_locale->month[aMonth] = (const char*) timeLocale; sl@0: iTime_locale->alt_month[aMonth] = (const char*) timeLocale; sl@0: timeLocale += strlen((char*) timeLocale) + 1; sl@0: } sl@0: sl@0: const TText16* abbMonth = ((reinterpret_cast((const TText*) iData[FnMonthAbbTable]()))[aMonth]); sl@0: if(abbMonth) sl@0: { sl@0: #ifdef SYMBIAN_OE_ENHANCED_LOCALE_SUPPORT sl@0: if(!localeName) sl@0: { sl@0: ConvertToMultiByteCustom((TUint8*)timeLocale, abbMonth); sl@0: } sl@0: else sl@0: { sl@0: #endif sl@0: ConvertToMultiByteL((TUint8*)timeLocale, abbMonth, charsetID); sl@0: #ifdef SYMBIAN_OE_ENHANCED_LOCALE_SUPPORT sl@0: } sl@0: #endif sl@0: iTime_locale->mon[aMonth] = (const char*) timeLocale; sl@0: timeLocale += strlen((char*) timeLocale) + 1; sl@0: } sl@0: sl@0: } sl@0: sl@0: //Set day and abbreviated day name information sl@0: sl@0: const TText16* day = ((reinterpret_cast((const TText*) iData[FnDayTable]()))[6]); sl@0: if(day) sl@0: { sl@0: #ifdef SYMBIAN_OE_ENHANCED_LOCALE_SUPPORT sl@0: if(!localeName) sl@0: { sl@0: ConvertToMultiByteCustom((TUint8*)timeLocale, day); sl@0: } sl@0: else sl@0: { sl@0: #endif sl@0: ConvertToMultiByteL((TUint8*)timeLocale, day, charsetID); sl@0: #ifdef SYMBIAN_OE_ENHANCED_LOCALE_SUPPORT sl@0: } sl@0: #endif sl@0: iTime_locale->weekday[0] = (const char*) timeLocale; sl@0: timeLocale += strlen((char*) timeLocale) + 1; sl@0: } sl@0: sl@0: sl@0: const TText16* abbDay = ((reinterpret_cast((const TText*) iData[FnDayAbbTable]()))[6]); sl@0: if(abbDay) sl@0: { sl@0: #ifdef SYMBIAN_OE_ENHANCED_LOCALE_SUPPORT sl@0: if(!localeName) sl@0: { sl@0: ConvertToMultiByteCustom((TUint8*)timeLocale, abbDay); sl@0: } sl@0: else sl@0: { sl@0: #endif sl@0: sl@0: ConvertToMultiByteL((TUint8*)timeLocale, abbDay, charsetID); sl@0: #ifdef SYMBIAN_OE_ENHANCED_LOCALE_SUPPORT sl@0: } sl@0: #endif sl@0: iTime_locale->wday[0] = (const char*) timeLocale; sl@0: timeLocale += strlen((char*) timeLocale) + 1; sl@0: } sl@0: sl@0: for(TInt aDay = 0 ; aDay < WEEKDAYS - 1; aDay++) sl@0: { sl@0: sl@0: const TText16* day = ((reinterpret_cast((const TText*) iData[FnDayTable]()))[aDay]); sl@0: if(day) sl@0: { sl@0: #ifdef SYMBIAN_OE_ENHANCED_LOCALE_SUPPORT sl@0: if(!localeName) sl@0: { sl@0: ConvertToMultiByteCustom((TUint8*)timeLocale, day); sl@0: } sl@0: else sl@0: { sl@0: #endif sl@0: ConvertToMultiByteL((TUint8*)timeLocale, day, charsetID); sl@0: #ifdef SYMBIAN_OE_ENHANCED_LOCALE_SUPPORT sl@0: } sl@0: #endif sl@0: iTime_locale->weekday[aDay + 1] = (const char*) timeLocale; sl@0: timeLocale += strlen((char*) timeLocale) + 1; sl@0: } sl@0: sl@0: sl@0: const TText16* abbDay = ((reinterpret_cast((const TText*) iData[FnDayAbbTable]()))[aDay]); sl@0: if(abbDay) sl@0: { sl@0: #ifdef SYMBIAN_OE_ENHANCED_LOCALE_SUPPORT sl@0: if(!localeName) sl@0: { sl@0: ConvertToMultiByteCustom((TUint8*)timeLocale, abbDay); sl@0: } sl@0: else sl@0: { sl@0: #endif sl@0: ConvertToMultiByteL((TUint8*)timeLocale, abbDay, charsetID); sl@0: #ifdef SYMBIAN_OE_ENHANCED_LOCALE_SUPPORT sl@0: } sl@0: #endif sl@0: iTime_locale->wday[aDay + 1] = (const char*) timeLocale; sl@0: timeLocale += strlen((char*) timeLocale) + 1; sl@0: } sl@0: sl@0: } sl@0: sl@0: //Set AM string sl@0: sl@0: const TText16* am = ((reinterpret_cast((const TText*) iData[FnAmPmTable]()))[0]); sl@0: if(am) sl@0: { sl@0: #ifdef SYMBIAN_OE_ENHANCED_LOCALE_SUPPORT sl@0: if(!localeName) sl@0: { sl@0: ConvertToMultiByteCustom((TUint8*)timeLocale, am); sl@0: } sl@0: else sl@0: { sl@0: #endif sl@0: ConvertToMultiByteL((TUint8*)timeLocale, am, charsetID); sl@0: #ifdef SYMBIAN_OE_ENHANCED_LOCALE_SUPPORT sl@0: } sl@0: #endif sl@0: iTime_locale->am = (const char*) timeLocale; sl@0: timeLocale += strlen((char*) timeLocale) + 1; sl@0: } sl@0: sl@0: //Set PM string sl@0: sl@0: const TText16* pm = ((reinterpret_cast((const TText*) iData[FnAmPmTable]()))[1]); sl@0: if(pm) sl@0: { sl@0: #ifdef SYMBIAN_OE_ENHANCED_LOCALE_SUPPORT sl@0: if(!localeName) sl@0: { sl@0: ConvertToMultiByteCustom((TUint8*)timeLocale, pm); sl@0: } sl@0: else sl@0: { sl@0: #endif sl@0: ConvertToMultiByteL((TUint8*)timeLocale, pm, charsetID); sl@0: #ifdef SYMBIAN_OE_ENHANCED_LOCALE_SUPPORT sl@0: } sl@0: #endif sl@0: iTime_locale->pm = (const char*) timeLocale; sl@0: timeLocale += strlen((char*) timeLocale) + 1; sl@0: } sl@0: sl@0: sl@0: Mem::Copy(&iLocaleTimeDateFormat.iTimeFormatSpec[0], (const TAny*) iData[FnTimeFormatSpec](), sizeof(TText) * (KMaxTimeFormatSpec+1)); sl@0: TText* timeForm = iLocaleTimeDateFormat.iTimeFormatSpec; sl@0: sl@0: //Set time format(T_FMT) and am/pm time format(T_FMT_AMPM) string sl@0: if(timeForm) sl@0: { sl@0: const TPtrC time(timeForm); sl@0: TBuf8 timeFormat; sl@0: timeFormat.Copy(time); sl@0: sl@0: TChar timeSeparator = iLocale.TimeSeparator(1); sl@0: TBuf8 timeSeparator1; sl@0: timeSeparator1.Append(timeSeparator); sl@0: sl@0: timeSeparator = iLocale.TimeSeparator(2); sl@0: TBuf8 timeSeparator2; sl@0: timeSeparator2.Append(timeSeparator); sl@0: sl@0: TTimeFormat time12hror24hr = iLocale.TimeFormat(); sl@0: sl@0: if(KErrNotFound != timeFormat.Locate('J')) sl@0: { sl@0: //Check for time format(12/24 hour format) sl@0: if(time12hror24hr == ETime12) sl@0: { sl@0: strcpy((char*) timeLocale,TWELVE_HOUR_STR); sl@0: } sl@0: else sl@0: { sl@0: strcpy((char*) timeLocale,TWENTY_FOUR_HOUR_STR); sl@0: } sl@0: } sl@0: sl@0: else if(KErrNotFound != timeFormat.Locate('I')) sl@0: { sl@0: strcpy((char*) timeLocale,TWELVE_HOUR_STR); sl@0: } sl@0: sl@0: else if(KErrNotFound != timeFormat.Locate('H')) sl@0: { sl@0: strcpy((char*) timeLocale,TWENTY_FOUR_HOUR_STR); sl@0: } sl@0: sl@0: strncat((char*) timeLocale, (char*) timeSeparator1.Ptr(), timeSeparator1.Length()); sl@0: strcat((char*) timeLocale, MINUTE_STR); sl@0: strncat((char*) timeLocale, (char*) timeSeparator2.Ptr(), timeSeparator2.Length()); sl@0: strcat((char*) timeLocale, SECOND_STR); sl@0: sl@0: if(time12hror24hr == ETime12) sl@0: { sl@0: sl@0: if((KErrNotFound != timeFormat.Find(KAMPMSpace12hr)) || (KErrNotFound != timeFormat.Find(KAMPMSpace)) ) sl@0: { sl@0: if((KErrNotFound != timeFormat.Find(KAMPMNoSpace12hr)) || (KErrNotFound != timeFormat.Find(KAMPMNoSpace))) sl@0: { sl@0: strcat((char*) timeLocale, AMPM_NO_SPACE); sl@0: } sl@0: else sl@0: { sl@0: strcat((char*) timeLocale, AMPM_SPACE); sl@0: } sl@0: } sl@0: } sl@0: sl@0: iTime_locale->ampm_fmt = (const char*) timeLocale; sl@0: iTime_locale->X_fmt = iTime_locale->ampm_fmt; sl@0: timeLocale += strlen((char*) timeLocale) + 1; sl@0: } sl@0: sl@0: TDateFormat aDateFormat = iLocale.DateFormat(); sl@0: //Set date fromat string(D_FMT) sl@0: TChar dateSeparator = iLocale.DateSeparator(1); sl@0: TBuf8 dateSeparator1; sl@0: dateSeparator1.Append(dateSeparator); sl@0: sl@0: TBuf8 dateSeparator2; sl@0: dateSeparator = iLocale.DateSeparator(2); sl@0: dateSeparator2.Append(dateSeparator); sl@0: sl@0: //Americal date formt(mm/dd/YYYY) sl@0: if(EDateAmerican == aDateFormat) sl@0: { sl@0: strcpy((char*) timeLocale, MONTH_STR); sl@0: strncat((char*) timeLocale, (char*) dateSeparator1.Ptr(), dateSeparator1.Length()); sl@0: strcat((char*) timeLocale, DAY_STR); sl@0: strncat((char*) timeLocale, (char*) dateSeparator2.Ptr(), dateSeparator2.Length()); sl@0: strcat((char*) timeLocale, YEAR_STR); sl@0: iTime_locale->x_fmt = (const char*) timeLocale; sl@0: } sl@0: sl@0: //European date format(dd/mm/YYYY) sl@0: if(EDateEuropean == aDateFormat) sl@0: { sl@0: strcpy((char*) timeLocale, DAY_STR); sl@0: strncat((char*) timeLocale, (char*) dateSeparator1.Ptr(), dateSeparator1.Length()); sl@0: strcat((char*) timeLocale, MONTH_STR); sl@0: strncat((char*) timeLocale, (char*) dateSeparator2.Ptr(), dateSeparator2.Length()); sl@0: strcat((char*) timeLocale, YEAR_STR); sl@0: iTime_locale->x_fmt = (const char*) timeLocale; sl@0: } sl@0: sl@0: //Japanese date format(YYYY/mm/dd) sl@0: if(EDateJapanese == aDateFormat) sl@0: { sl@0: strcpy((char*) timeLocale, YEAR_STR); sl@0: strncat((char*) timeLocale, (char*) dateSeparator1.Ptr(), dateSeparator1.Length()); sl@0: strcat((char*) timeLocale, MONTH_STR); sl@0: strncat((char*) timeLocale, (char*) dateSeparator2.Ptr(), dateSeparator2.Length()); sl@0: strcat((char*) timeLocale, DAY_STR); sl@0: iTime_locale->x_fmt = (const char*) timeLocale; sl@0: } sl@0: sl@0: iTime_locale->md_order = iTime_locale->c_fmt = iTime_locale->date_fmt = (const char*) L""; sl@0: ; sl@0: timeLocale = startAddress; sl@0: return 0; sl@0: sl@0: } sl@0: sl@0: struct lc_numeric_T* CLocale::GetCurrentNumericLocale(void) sl@0: { sl@0: sl@0: if(NULL != iNumeric_locale) sl@0: { sl@0: return iNumeric_locale; sl@0: } sl@0: return NULL; sl@0: sl@0: } sl@0: sl@0: struct lc_monetary_T* CLocale::GetCurrentMonetaryLocale(void) sl@0: { sl@0: if(NULL != iMonetary_locale) sl@0: { sl@0: return iMonetary_locale; sl@0: } sl@0: return NULL; sl@0: } sl@0: sl@0: struct lc_time_T* CLocale::GetCurrentTimeLocale(void) sl@0: { sl@0: if(NULL != iTime_locale) sl@0: { sl@0: return iTime_locale; sl@0: } sl@0: sl@0: return NULL; sl@0: } sl@0: sl@0: sl@0: TInt CLocale::LoadLocale(TDesC& aLocale) sl@0: { sl@0: TPtrC src(aLocale); sl@0: TBuf8 locale_name; sl@0: locale_name.Copy(src); sl@0: char locale[LOCALE_LENGTH]; sl@0: strncpy(locale, (char*) locale_name.Ptr(), locale_name.Length()); sl@0: locale[locale_name.Length()] = '\0'; sl@0: sl@0: if (NULL == strchr(locale, '.')) sl@0: { sl@0: return 0; sl@0: } sl@0: sl@0: // Open the file locale mapping(mapping of POSIX locale string to language variant DLL number) file sl@0: RFile file; sl@0: sl@0: #ifndef __EPOC32__ sl@0: _LIT(localeFile, "\\resource\\openc\\locales.txt"); sl@0: #else sl@0: TFileName localeFile; sl@0: GetInstallationDataDir(localeFile); sl@0: localeFile.Append(_L("locales.txt")); sl@0: #endif //__EPOC32__ sl@0: sl@0: int retVal = file.Open(Backend()->FileSession(), localeFile, EFileRead); sl@0: if(KErrNone != retVal) sl@0: { sl@0: return 0; sl@0: } sl@0: sl@0: int pos = 0; sl@0: TBuf8 localeInfo; sl@0: retVal = ReadALine(file, pos, localeInfo); sl@0: char* buffer = (char*) localeInfo.Ptr(); sl@0: sl@0: //Check whether locale is supported or not sl@0: int i = 0; sl@0: int flag = 0; sl@0: while( retVal > 0) sl@0: { sl@0: char str[LOCALE_LENGTH]; sl@0: while(buffer[i] != '=') sl@0: { sl@0: str[i] = buffer[i]; sl@0: i++; sl@0: } sl@0: str[i] = '\0'; sl@0: if(!strcmp(str,locale)) sl@0: { sl@0: flag = 1; sl@0: break; sl@0: } sl@0: i = 0; sl@0: retVal = ReadALine(file, pos, localeInfo); sl@0: buffer = (char*) localeInfo.Ptr(); sl@0: } sl@0: if(flag) sl@0: { sl@0: DllName.Copy(KDllName); sl@0: DllName.Append('.'); sl@0: i++; sl@0: int len = localeInfo.Length(); sl@0: while(i < len) sl@0: { sl@0: DllName.Append(buffer[i]); sl@0: i++; sl@0: } sl@0: file.Close(); sl@0: return 1; sl@0: } sl@0: sl@0: file.Close(); sl@0: return 0; sl@0: sl@0: } sl@0: sl@0: sl@0: TInt CLocale::ConvertToMultiByteL(TUint8* aNarrowCharString, const TText16* aWideCharString, TInt aCharsetUID) sl@0: { sl@0: //Create a handle to a file server session and connect to the file server. sl@0: //Push it on to cleanup stack sl@0: RFs fileSession; sl@0: User::LeaveIfError(fileSession.Connect()); sl@0: CleanupClosePushL(fileSession); sl@0: sl@0: //Allocate and constructs a CCnvCharacterSetConverter object sl@0: CCnvCharacterSetConverter* conv = CCnvCharacterSetConverter::NewLC(); sl@0: sl@0: //Search the character set array containing all of the character sets for which conversion is available sl@0: CCnvCharacterSetConverter::TAvailability avail = conv->PrepareToConvertToOrFromL(aCharsetUID, fileSession); sl@0: if(CCnvCharacterSetConverter::ENotAvailable == avail) sl@0: { sl@0: CleanupStack::PopAndDestroy(2); sl@0: *aNarrowCharString = '\0'; sl@0: return -1; sl@0: } sl@0: sl@0: const TPtrC16 unicodeText(aWideCharString); sl@0: TBuf8 nativeText; sl@0: sl@0: TInt retVal = KErrNone; sl@0: TInt aNumberOfUnconvertibleCharacters = 0; sl@0: TInt aIndexOfFirstByteOfFirstUnconvertibleCharacter = 0; sl@0: sl@0: //Convert text encoded in the Unicode character set (UCS-2) into other character sets sl@0: retVal = conv->ConvertFromUnicode(nativeText,unicodeText, aNumberOfUnconvertibleCharacters, aIndexOfFirstByteOfFirstUnconvertibleCharacter); sl@0: TInt returnCode = 0; sl@0: //Check for illegal characters in the input sl@0: if(retVal == CCnvCharacterSetConverter::EErrorIllFormedInput) sl@0: { sl@0: *aNarrowCharString = '\0'; sl@0: returnCode = -1; sl@0: } sl@0: sl@0: //Check for incomplete characters in the input, set the errno accordingly sl@0: else if(aNumberOfUnconvertibleCharacters) sl@0: { sl@0: *aNarrowCharString = '\0'; sl@0: returnCode = -1; sl@0: } sl@0: else sl@0: { sl@0: strncpy((char*) aNarrowCharString, (char*) nativeText.Ptr(), nativeText.Length()); sl@0: aNarrowCharString[nativeText.Length()] = '\0'; sl@0: returnCode = 0; sl@0: } sl@0: CleanupStack::PopAndDestroy(2); // conv, fileSession sl@0: return returnCode; sl@0: sl@0: } sl@0: sl@0: TInt CLocale::GetCharcaterSetIDL(const char* aLocaleName) sl@0: { sl@0: //extract the charcate set name from locale string sl@0: char* temp = strchr(aLocaleName, '.'); sl@0: char locale[LOCALE_LENGTH]; sl@0: if(NULL == temp) sl@0: { sl@0: return -1; sl@0: } sl@0: temp++; sl@0: int j= 0; sl@0: while((*temp != '@') && *temp != '\0') sl@0: { sl@0: locale[j++] = *temp++; sl@0: } sl@0: locale[j++] = '\0'; sl@0: sl@0: //Create a handle to a file server session and connect to the file server. sl@0: //Push it on to cleanup stack sl@0: RFs fileSession; sl@0: User::LeaveIfError(fileSession.Connect()); sl@0: CleanupClosePushL(fileSession); sl@0: sl@0: TInt characterSetUID = 0; sl@0: sl@0: //Allocate and constructs a CCnvCharacterSetConverter object sl@0: CCnvCharacterSetConverter* conv = CCnvCharacterSetConverter::NewLC() ; sl@0: sl@0: //Create an array identifying all the character sets for which conversion is available sl@0: CArrayFix *charSet = CCnvCharacterSetConverter::CreateArrayOfCharacterSetsAvailableL(fileSession); sl@0: CleanupStack::PushL( charSet ); sl@0: sl@0: TInt i = 0; sl@0: //Get the number of character sets for which conversion is available sl@0: TInt count = charSet->Count(); sl@0: while(i < count) sl@0: { sl@0: CCnvCharacterSetConverter::SCharacterSet characterSet = charSet->At(i); sl@0: i++; sl@0: //Get the UID of character set for which conversion is available sl@0: TUint charSetUID = characterSet.Identifier(); sl@0: sl@0: const TBufC charSetName = characterSet.NameIsFileName()?TParsePtrC(characterSet.Name()).Name():characterSet.Name(); sl@0: TBuf8 aCharSetname; sl@0: aCharSetname.Copy(charSetName); sl@0: sl@0: //Assign the character set UID sl@0: if(!aCharSetname.Compare(TPtrC8((const TText8*) locale))) sl@0: { sl@0: characterSetUID = charSetUID; sl@0: break; sl@0: } sl@0: sl@0: HBufC8* stdInterName = conv->ConvertCharacterSetIdentifierToStandardNameL(charSetUID, fileSession); sl@0: if(NULL != stdInterName) sl@0: { sl@0: if(!stdInterName->Compare(TPtrC8((const TText8*) locale))) sl@0: { sl@0: characterSetUID = charSetUID; sl@0: delete stdInterName; sl@0: stdInterName = NULL; sl@0: break; sl@0: } sl@0: delete stdInterName; sl@0: stdInterName = NULL; sl@0: } sl@0: } sl@0: sl@0: if(!characterSetUID) sl@0: { sl@0: characterSetUID = -1; sl@0: } sl@0: sl@0: CleanupStack::PopAndDestroy(3); //charSet, conv, fileSession sl@0: return characterSetUID; sl@0: } sl@0: sl@0: /* ReadALine : Reads one line at a time from specified file */ sl@0: inline TInt ReadALine(RFile& aFile, TInt& aPos, TDes8& aDesc) sl@0: { sl@0: TInt ret = aFile.Read(aPos, aDesc); sl@0: TChar delimOne = '\r'; sl@0: TChar delimTwo = '\n'; sl@0: sl@0: TInt len = aDesc.Length(); sl@0: if(!ret && len) sl@0: { sl@0: //Always assumes that each line will end with "\r\n" except the last line sl@0: TInt pos = aDesc.Locate(delimOne); sl@0: pos = aDesc.Locate(delimTwo); sl@0: sl@0: if(KErrNotFound != pos) sl@0: { sl@0: aPos = aPos + pos + 1; sl@0: len = pos - 1; sl@0: aDesc.SetLength(len); sl@0: } sl@0: else sl@0: { sl@0: aPos = aPos + len; sl@0: } sl@0: } sl@0: return len; sl@0: } sl@0: #ifdef SYMBIAN_OE_ENHANCED_LOCALE_SUPPORT sl@0: sl@0: void CLocale::ConvertToMultiByteCustom(TUint8* aNarrowCharString, const TText16* aWideCharString) sl@0: { sl@0: const TPtrC unicodeText(aWideCharString); sl@0: TBuf8 nativeText; sl@0: nativeText.Copy(unicodeText); sl@0: strncpy((char*) aNarrowCharString, (char*) nativeText.Ptr(), nativeText.Length()); sl@0: aNarrowCharString[nativeText.Length()] = '\0'; sl@0: } sl@0: sl@0: TInt CLocale::SyncLocale(TLocaleAspect aspect) sl@0: { sl@0: #ifdef SYMBIAN_DISTINCT_LOCALE_MODEL sl@0: TBuf reg_dllname; sl@0: #endif sl@0: TBuf Kdname; sl@0: TExtendedLocale locale; sl@0: locale.LoadSystemSettings(); sl@0: locale.GetLocaleDllName(aspect,Kdname); sl@0: #ifdef SYMBIAN_DISTINCT_LOCALE_MODEL sl@0: // check if the new dlls is present then load it or go for old dll sl@0: if( Kdname.FindC(_L("elocl.")) == KErrNotFound ) sl@0: { sl@0: iOldDllPresent = 0; sl@0: locale.GetLocaleDllName(ELocaleTimeDateSettings,reg_dllname); sl@0: return (GetSystemLocale(Kdname,reg_dllname )); sl@0: } sl@0: else sl@0: iOldDllPresent = 1; sl@0: #endif sl@0: return (GetSystemLocale(Kdname)); sl@0: } sl@0: sl@0: const TText* CLocale::GetLocaleName(void) sl@0: { sl@0: TPtrC dllname(DllName); sl@0: return dllname.Ptr(); sl@0: } sl@0: sl@0: sl@0: #ifdef SYMBIAN_DISTINCT_LOCALE_MODEL sl@0: sl@0: const TText* CLocale::GetCollateLocaleName(void) sl@0: { sl@0: TPtrC dllname(ColDllName); sl@0: return dllname.Ptr(); sl@0: } sl@0: #endif sl@0: sl@0: sl@0: #endif // SYMBIAN_OE_ENHANCED_LOCALE_SUPPORT sl@0: sl@0: sl@0: sl@0: