1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/ossrv/genericopenlibs/openenvcore/libc/src/localeinfo.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,1712 @@
1.4 +/*
1.5 +* Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies).
1.6 +* All rights reserved.
1.7 +* This component and the accompanying materials are made available
1.8 +* under the terms of "Eclipse Public License v1.0"
1.9 +* which accompanies this distribution, and is available
1.10 +* at the URL "http://www.eclipse.org/legal/epl-v10.html".
1.11 +*
1.12 +* Initial Contributors:
1.13 +* Nokia Corporation - initial contribution.
1.14 +*
1.15 +* Contributors:
1.16 +*
1.17 +* Description: Contains the source for all locale related functionalities
1.18 + *
1.19 + *
1.20 +*/
1.21 +
1.22 +
1.23 +#include <stdlib.h>
1.24 +#include <f32file.h>
1.25 +#include "localeinfo.h"
1.26 +#include "sysif.h"
1.27 +#include <e32std_private.h>
1.28 +#include <e32ldr_private.h>
1.29 +
1.30 +typedef void (*TLibFn)(TLocale*);
1.31 +
1.32 +#if (defined(__SYMBIAN32__) && (defined(__WINSCW__) || defined(__WINS__)))
1.33 +#include "libc_wsd_defs.h"
1.34 +#include "localetlsinfo.h"
1.35 +#else
1.36 +
1.37 +#ifdef SYMBIAN_DISTINCT_LOCALE_MODEL
1.38 +#define NEW_LANG_VARIANT_DLL_NAME 30
1.39 +#endif
1.40 +
1.41 +#endif
1.42 +#define LC_TIME_MEMORY 1024
1.43 +#define LC_MONETARY_MEMORY 50
1.44 +#define LC_NUMERIC_MEMORY 20
1.45 +#define MONTHS 12
1.46 +#define WEEKDAYS 7
1.47 +#define DECIMAL_THOUSAND_DATE_TIME_SEPARATOR 2
1.48 +#define EURO_CURRENCY 4
1.49 +#define LOCALE_LENGTH 50
1.50 +#define CHARACTER_SET_NAME 32
1.51 +#define TIME_FORMAT_LENGTH 32
1.52 +#define NON_UNICODE_TEXT_BUFFER_LENGTH 256
1.53 +#define LANG_VARIANT_DLL_NAME 10
1.54 +
1.55 +#define MONTH_STR "%m"
1.56 +#define DAY_STR "%d"
1.57 +#define YEAR_STR "%Y"
1.58 +#define TWELVE_HOUR_STR "%I"
1.59 +#define TWENTY_FOUR_HOUR_STR "%H"
1.60 +#define MINUTE_STR "%M"
1.61 +#define SECOND_STR "%S"
1.62 +#define AMPM_SPACE " %p"
1.63 +#define AMPM_NO_SPACE "%p"
1.64 +
1.65 +
1.66 +#ifdef SYMBIAN_DISTINCT_LOCALE_MODEL
1.67 +
1.68 +
1.69 +_LIT(KLanDllName, "elocl_lan.");
1.70 +_LIT(KRegDllName, "elocl_reg.");
1.71 +_LIT(KColDllName, "elocl_col.");
1.72 +
1.73 +#endif
1.74 +
1.75 +_LIT(KDllName, "elocl");
1.76 +
1.77 +
1.78 +#ifndef SYMBIAN_OE_ENHANCED_LOCALE_SUPPORT
1.79 +_LIT(KEuro, "\x20AC");
1.80 +#endif
1.81 +
1.82 +_LIT8(KAMPMSpace12hr, "B");
1.83 +_LIT8(KAMPMSpace, "A");
1.84 +_LIT8(KAMPMNoSpace12hr, "*B");
1.85 +_LIT8(KAMPMNoSpace, "*A");
1.86 +
1.87 +#ifndef EMULATOR
1.88 +
1.89 +CLocale* CLocale::iNewLocale = NULL;
1.90 +lc_monetary_T* CLocale::iMonetary_locale = NULL;
1.91 +lc_numeric_T* CLocale::iNumeric_locale =NULL;
1.92 +lc_time_T* CLocale::iTime_locale = NULL;
1.93 +
1.94 +TText8* numericLocale = NULL;
1.95 +TText8* monetaryLocale = NULL;
1.96 +TText8* timeLocale = NULL;
1.97 +
1.98 +static TBuf<LANG_VARIANT_DLL_NAME> DllName;
1.99 +
1.100 +#ifdef SYMBIAN_DISTINCT_LOCALE_MODEL
1.101 +static TBuf<NEW_LANG_VARIANT_DLL_NAME> ColDllName;
1.102 +#endif
1.103 +
1.104 +#else //EMULATOR
1.105 +
1.106 +#define iNewLocale ((GetGlobals()->localeptr)->GET_WSD_VAR_NAME(iNewLocale,s))
1.107 +#define iMonetary_locale ((GetGlobals()->localeptr)->GET_WSD_VAR_NAME(iMonetary_locale,s))
1.108 +#define iNumeric_locale ((GetGlobals()->localeptr)->GET_WSD_VAR_NAME(iNumeric_locale,s))
1.109 +#define iTime_locale ((GetGlobals()->localeptr)->GET_WSD_VAR_NAME(iTime_locale,s))
1.110 +
1.111 +#define numericLocale ((GetGlobals()->localeptr)->GET_WSD_VAR_NAME(numericLocale,s))
1.112 +#define monetaryLocale ((GetGlobals()->localeptr)->GET_WSD_VAR_NAME(monetaryLocale,s))
1.113 +#define timeLocale ((GetGlobals()->localeptr)->GET_WSD_VAR_NAME(timeLocale,s))
1.114 +
1.115 +#define DllName ((GetGlobals()->localeptr)->GET_WSD_VAR_NAME(DllName,s))
1.116 +
1.117 +#ifdef SYMBIAN_DISTINCT_LOCALE_MODEL
1.118 +
1.119 +#define ColDllName ((GetGlobals()->localeptr)->GET_WSD_VAR_NAME(ColDllName,s))
1.120 +#endif
1.121 +
1.122 +#endif //EMULATOR
1.123 +
1.124 +CLocale::CLocale()
1.125 + {
1.126 + iMonetary_locale = NULL;
1.127 + iNumeric_locale = NULL;
1.128 + iTime_locale = NULL;
1.129 +
1.130 + numericLocale = NULL;
1.131 + monetaryLocale = NULL;
1.132 + timeLocale = NULL;
1.133 +#ifdef SYMBIAN_DISTINCT_LOCALE_MODEL
1.134 + iOldDllPresent = 0;
1.135 +#endif
1.136 + }
1.137 +
1.138 +
1.139 +
1.140 +CLocale* CLocale::New()
1.141 + {
1.142 + CLocale* self = new CLocale();
1.143 + if(self)
1.144 + {
1.145 + TInt ret=KErrNone;
1.146 + TRAPD(result,ret = self->ConstructL());
1.147 + if(KErrNone != (result | ret))
1.148 + {
1.149 + delete self;
1.150 + self = NULL;
1.151 + }
1.152 + }
1.153 + return self;
1.154 + }
1.155 +
1.156 +TInt CLocale::ConstructL()
1.157 + {
1.158 + iMonetary_locale = new lc_monetary_T;
1.159 + if(!iMonetary_locale)
1.160 + {
1.161 + return KErrNoMemory;
1.162 + }
1.163 + iNumeric_locale = new lc_numeric_T;
1.164 + if(!iNumeric_locale)
1.165 + {
1.166 + return KErrNoMemory;
1.167 + }
1.168 + iTime_locale = new (ELeave) lc_time_T;
1.169 + if(!iTime_locale)
1.170 + {
1.171 + return KErrNoMemory;
1.172 + }
1.173 +
1.174 + for(TInt i =0 ; i < MONTHS; i++)
1.175 + {
1.176 + iTime_locale->mon[i] = NULL;
1.177 + iTime_locale->month[i] = NULL;
1.178 + iTime_locale->alt_month[i] = NULL;
1.179 + }
1.180 +
1.181 +
1.182 + for(TInt i =0 ; i < WEEKDAYS; i++)
1.183 + {
1.184 + iTime_locale->wday[i] = NULL;
1.185 + iTime_locale->weekday[i] = NULL;
1.186 + }
1.187 +
1.188 + iTime_locale->X_fmt = NULL;
1.189 + iTime_locale->x_fmt = NULL;
1.190 + iTime_locale->c_fmt = NULL;
1.191 + iTime_locale->am = NULL;
1.192 + iTime_locale->pm = NULL;
1.193 + iTime_locale->date_fmt = NULL;
1.194 + iTime_locale->md_order = NULL;
1.195 + iTime_locale->ampm_fmt = NULL;
1.196 +
1.197 + iMonetary_locale->int_curr_symbol = NULL;
1.198 + iMonetary_locale->currency_symbol = NULL;
1.199 + iMonetary_locale->mon_decimal_point = NULL;
1.200 + iMonetary_locale->mon_thousands_sep = NULL;
1.201 + iMonetary_locale->mon_grouping = NULL;
1.202 + iMonetary_locale->positive_sign = NULL;
1.203 + iMonetary_locale->negative_sign = NULL;
1.204 + iMonetary_locale->int_frac_digits = iMonetary_locale->frac_digits = NULL;
1.205 + iMonetary_locale->p_cs_precedes = iMonetary_locale->int_p_cs_precedes = NULL;
1.206 + iMonetary_locale->p_sep_by_space = iMonetary_locale->int_p_sep_by_space = NULL;
1.207 + iMonetary_locale->n_cs_precedes = iMonetary_locale->int_n_cs_precedes = NULL;
1.208 + iMonetary_locale->n_sep_by_space = iMonetary_locale->int_n_sep_by_space = NULL;
1.209 + iMonetary_locale->p_sign_posn = iMonetary_locale->int_p_sign_posn = NULL;
1.210 + iMonetary_locale->n_sign_posn = iMonetary_locale->int_n_sign_posn = NULL;
1.211 +
1.212 + iNumeric_locale->decimal_point = NULL;
1.213 + iNumeric_locale->thousands_sep = NULL;
1.214 + iNumeric_locale->grouping = NULL;
1.215 +
1.216 + return KErrNone;
1.217 + }
1.218 +
1.219 +CLocale* CLocale::GetInstance()
1.220 + {
1.221 + // Switch to the backend heap
1.222 + RHeap* oldheap = User::SwitchHeap(Backend()->Heap());
1.223 +
1.224 + if(NULL == iNewLocale)
1.225 + {
1.226 + iNewLocale = New();
1.227 + }
1.228 +
1.229 + if(numericLocale == NULL )
1.230 + {
1.231 + numericLocale = new TText8 [LC_NUMERIC_MEMORY];
1.232 + }
1.233 +
1.234 + if(monetaryLocale == NULL)
1.235 + {
1.236 + monetaryLocale = new TText8[LC_MONETARY_MEMORY];
1.237 + }
1.238 +
1.239 + if(timeLocale == NULL)
1.240 + {
1.241 + timeLocale = new TText8[LC_TIME_MEMORY];
1.242 + }
1.243 +
1.244 +
1.245 +
1.246 + //Set back the default user heap
1.247 + User::SwitchHeap(oldheap);
1.248 + return iNewLocale;
1.249 + }
1.250 +
1.251 +
1.252 +void CLocale::DeleteInstance()
1.253 + {
1.254 + // Switch to the backend heap so that deletes happen from there
1.255 + RHeap* oldheap = User::SwitchHeap(Backend()->Heap());
1.256 +
1.257 + delete [] timeLocale;
1.258 + timeLocale =NULL;
1.259 +
1.260 + delete [] numericLocale;
1.261 + numericLocale = NULL;
1.262 +
1.263 + delete [] monetaryLocale;
1.264 + monetaryLocale = NULL;
1.265 +
1.266 + delete iMonetary_locale;
1.267 + iMonetary_locale = NULL;
1.268 +
1.269 + delete iNumeric_locale;
1.270 + iNumeric_locale = NULL;
1.271 +
1.272 + delete iTime_locale;
1.273 + iTime_locale = NULL;
1.274 +
1.275 + delete iNewLocale;
1.276 + iNewLocale = NULL;
1.277 +
1.278 +
1.279 +
1.280 + //Set back to the default user heap
1.281 + User::SwitchHeap(oldheap);
1.282 + }
1.283 +
1.284 +
1.285 +TText* CLocale::SetLocale(TDesC& aLocale)
1.286 + {
1.287 + //Check whether locale is supported
1.288 +
1.289 + TText* retVal = NULL;
1.290 + TInt r;
1.291 +#ifdef SYMBIAN_DISTINCT_LOCALE_MODEL
1.292 +
1.293 + // load the new locale dll if not present check for the old dll
1.294 + r = LoadNewLocaleDll( aLocale );
1.295 + if ( r == KErrNone )
1.296 + {
1.297 + retVal = (TText*) aLocale.Ptr();
1.298 + iOldDllPresent = 0;
1.299 + return retVal;
1.300 + }
1.301 +#endif
1.302 +
1.303 + if(!LoadLocale(aLocale))
1.304 + {
1.305 + return NULL;
1.306 + }
1.307 + RLoader loader;
1.308 + r = loader.Connect();
1.309 + if(KErrNone == r)
1.310 + {
1.311 + //Load the language variant DLL
1.312 + TInt size = KNumLocaleExports * sizeof(TLibraryFunction);
1.313 + TPtr8 functionListBuf((TUint8*) iData, size, size);
1.314 + r = loader.SendReceive(ELoadLocale, TIpcArgs(0, (const TDesC*)&DllName, &functionListBuf) );
1.315 + if(KErrNone == r)
1.316 + {
1.317 + ((TLibFn)iData[FnLocaleData])(&iLocale);
1.318 + retVal = (TText*) aLocale.Ptr();
1.319 +#ifdef SYMBIAN_DISTINCT_LOCALE_MODEL
1.320 + iOldDllPresent = 1;
1.321 +#endif
1.322 + }
1.323 + loader.Close();
1.324 + }
1.325 + return retVal;
1.326 +}
1.327 +
1.328 +#ifdef SYMBIAN_OE_ENHANCED_LOCALE_SUPPORT
1.329 +
1.330 +#ifdef SYMBIAN_DISTINCT_LOCALE_MODEL
1.331 +TInt CLocale::GetSystemLocale(TDesC& aLanDllName,TDesC& aRegDllName)
1.332 + {
1.333 + RLoader loader;
1.334 + TInt retVal = -1;
1.335 + TInt r = loader.Connect();
1.336 + if(KErrNone == r)
1.337 + {
1.338 + TInt size = KNumLocaleExports * sizeof(TLibraryFunction);
1.339 + TPtr8 functionListBuf1((TUint8*) iDataLanguage, size, size);
1.340 + r = loader.SendReceive(ELoadLocale, TIpcArgs(0, (const TDesC*)&aLanDllName, &functionListBuf1) );
1.341 + if(KErrNone != r)
1.342 + return retVal;
1.343 + TPtr8 functionListBuf2((TUint8*) iDataRegion, size, size);
1.344 + r = loader.SendReceive(ELoadLocale, TIpcArgs(0, (const TDesC*)&aRegDllName, &functionListBuf2) );
1.345 + ((TLibFn)iDataRegion[FnLocaleDataV2])(&iLocale);
1.346 + if(KErrNone != r)
1.347 + return retVal;
1.348 + retVal = 0;
1.349 + loader.Close();
1.350 + }
1.351 + return retVal;
1.352 +
1.353 + }
1.354 +#endif
1.355 +//Load the system dll settings
1.356 +TInt CLocale::GetSystemLocale(TDesC& aDllName)
1.357 + {
1.358 + RLoader loader;
1.359 + TInt retVal = -1;
1.360 + TInt r = loader.Connect();
1.361 + if(KErrNone == r)
1.362 + {
1.363 + //Load the language variant DLL
1.364 + TInt size = KNumLocaleExports * sizeof(TLibraryFunction);
1.365 + TPtr8 functionListBuf((TUint8*) iData, size, size);
1.366 + r = loader.SendReceive(ELoadLocale, TIpcArgs(0, (const TDesC*)&aDllName, &functionListBuf) );
1.367 + if(KErrNone == r)
1.368 + {
1.369 + ((TLibFn)iData[FnLocaleData])(&iLocale);
1.370 + retVal = 0;
1.371 + }
1.372 + loader.Close();
1.373 + }
1.374 + return retVal;
1.375 + }
1.376 +
1.377 +#endif
1.378 +
1.379 +
1.380 +TInt CLocale::MonetaryLoadLocaleL(const char* localeName)
1.381 +{
1.382 + #ifdef SYMBIAN_OE_ENHANCED_LOCALE_SUPPORT
1.383 + TInt charsetID=-1;
1.384 + if(localeName)
1.385 + {
1.386 + charsetID = GetCharcaterSetIDL(localeName);
1.387 + if(charsetID == -1)
1.388 + {
1.389 + return -1;
1.390 + }
1.391 + }
1.392 + #else
1.393 + TInt charsetID = GetCharcaterSetIDL(localeName);
1.394 + if(charsetID == -1)
1.395 + {
1.396 + return -1;
1.397 + }
1.398 + #endif
1.399 + #ifdef SYMBIAN_OE_ENHANCED_LOCALE_SUPPORT
1.400 + else
1.401 + {
1.402 + //update the iLocale with the system locale settings
1.403 + iLocale.Refresh();
1.404 + }
1.405 + #endif
1.406 + #ifndef SYMBIAN_OE_ENHANCED_LOCALE_SUPPORT
1.407 + //Retreive monetary information from language variant DLL
1.408 + Mem::Copy(&iLocaleSettings.iCurrencySymbol[0], (const TAny*) iData[FnCurrencySymbol](), sizeof(TText) * (KMaxCurrencySymbol+1));
1.409 + #endif
1.410 + TLocalePos aCurrencySymbolPosition = iLocale.CurrencySymbolPosition();
1.411 + TLocale::TNegativeCurrencyFormat aNegativeCurrencyFormat = iLocale.NegativeCurrencyFormat();
1.412 + TBool aCurrencySpaceBetween = iLocale.CurrencySpaceBetween();
1.413 + TBool aNegativeCurrencySymbolOpposite = iLocale.NegativeCurrencySymbolOpposite();
1.414 + TBool aNegativeLoseSpace = iLocale.NegativeLoseSpace();
1.415 + TBool aCurrencyTriadsAllowed = iLocale.CurrencyTriadsAllowed();
1.416 +
1.417 + TInt currencyDecimalPlaces = iLocale.CurrencyDecimalPlaces();
1.418 + iThousandsSeparator= iLocale.ThousandsSeparator();
1.419 + iDecimalSeparator = iLocale.DecimalSeparator();
1.420 +
1.421 + TText8* temp = monetaryLocale;
1.422 +
1.423 + //Set the decimal separator
1.424 + const TText* dec_point = (const TText*) &iDecimalSeparator;
1.425 + if(dec_point)
1.426 + {
1.427 + const TPtrC dec(dec_point);
1.428 + TBuf8<DECIMAL_THOUSAND_DATE_TIME_SEPARATOR> decimal;
1.429 + decimal.Copy(dec);
1.430 + strncpy((char*) monetaryLocale, (char*) decimal.Ptr(), decimal.Length());
1.431 + monetaryLocale[decimal.Length()] = '\0';
1.432 + iMonetary_locale->mon_decimal_point = (const char*) monetaryLocale;
1.433 + monetaryLocale += decimal.Length() + 1;
1.434 + }
1.435 +
1.436 + //Set thousand separator
1.437 + const TText* thous_sep = (const TText*) &iThousandsSeparator;
1.438 + if(thous_sep)
1.439 + {
1.440 + const TPtrC thousand(thous_sep);
1.441 + TBuf8<DECIMAL_THOUSAND_DATE_TIME_SEPARATOR> thousand_sep;
1.442 + thousand_sep.Copy(thousand);
1.443 + strncpy((char*) monetaryLocale, (char*) thousand_sep.Ptr(), thousand_sep.Length());
1.444 + monetaryLocale[thousand_sep.Length()] = '\0';
1.445 + iMonetary_locale->mon_thousands_sep = (const char*) monetaryLocale;
1.446 + monetaryLocale += thousand_sep.Length() + 1;
1.447 + }
1.448 + #ifdef SYMBIAN_OE_ENHANCED_LOCALE_SUPPORT
1.449 + TBuf<KMaxCurrencySymbol> CurrencySymbol;
1.450 + if(localeName)
1.451 + {
1.452 +#ifdef SYMBIAN_DISTINCT_LOCALE_MODEL
1.453 + if( iOldDllPresent ) // old style dll is loaded
1.454 + {
1.455 + Mem::Copy(&iLocaleSettings.iCurrencySymbol[0], (const TAny*) iData[FnCurrencySymbol](), sizeof(TText) * (KMaxCurrencySymbol+1));
1.456 + }
1.457 + else
1.458 + {
1.459 + Mem::Copy(&iLocaleSettings.iCurrencySymbol[0], (const TAny*) iDataRegion[FnCurrencySymbolV2](), sizeof(TText) * (KMaxCurrencySymbol+1));
1.460 + }
1.461 +#else
1.462 + Mem::Copy(&iLocaleSettings.iCurrencySymbol[0], (const TAny*) iData[FnCurrencySymbol](), sizeof(TText) * (KMaxCurrencySymbol+1));
1.463 +#endif
1.464 + //Set Currency information
1.465 + const TText16* cur = iLocaleSettings.iCurrencySymbol;
1.466 + const TPtrC currency(cur);
1.467 + CurrencySymbol.Copy(currency);
1.468 + }
1.469 + else
1.470 + {
1.471 + TCurrencySymbol cur;
1.472 + const TPtrC currency(cur);
1.473 + CurrencySymbol.Copy(currency);
1.474 + }
1.475 + strncpy((char*) monetaryLocale, (char*) CurrencySymbol.Ptr(), CurrencySymbol.Length());
1.476 + monetaryLocale[CurrencySymbol.Length()] = '\0';
1.477 + iMonetary_locale->currency_symbol = (const char*) monetaryLocale;
1.478 + monetaryLocale += strlen((char*) monetaryLocale) + 1;
1.479 + #else
1.480 + //Set Currency information
1.481 + const TText16* currency = iLocaleSettings.iCurrencySymbol;
1.482 + if(currency)
1.483 + {
1.484 + TBuf<EURO_CURRENCY> euroSymbol(currency);
1.485 + char* temp = strchr(localeName, '.');
1.486 + temp = temp + 1;
1.487 +
1.488 + if(!euroSymbol.Compare(KEuro) && !strcmp(temp, "ISO-8859-1"))
1.489 + {
1.490 + strcpy((char*) monetaryLocale,"\x80");
1.491 + monetaryLocale[1] = '\0';
1.492 + }
1.493 + else
1.494 + {
1.495 + ConvertToMultiByteL((TText8*)monetaryLocale, currency, charsetID);
1.496 + }
1.497 + iMonetary_locale->currency_symbol = (const char*) monetaryLocale;
1.498 + monetaryLocale += strlen((char*) monetaryLocale) + 1;
1.499 + }
1.500 + #endif
1.501 +
1.502 + //Set grouping information
1.503 + strcpy((char*) monetaryLocale,(aCurrencyTriadsAllowed? "\003":""));
1.504 + monetaryLocale[strlen((char*) monetaryLocale)] = '\0';
1.505 + iMonetary_locale->mon_grouping = (const char*) monetaryLocale;
1.506 + monetaryLocale += strlen((char*) monetaryLocale) + 1;
1.507 +
1.508 + //Set currency decimal places
1.509 + iMonetary_locale->int_frac_digits = iMonetary_locale->frac_digits = (const char*) monetaryLocale;
1.510 + *monetaryLocale++ = currencyDecimalPlaces;
1.511 + *monetaryLocale++ = '\0';
1.512 +
1.513 + //Set the currency symbol position for a monetary quantity with non-negative value
1.514 + iMonetary_locale->p_cs_precedes = (const char*) monetaryLocale;
1.515 + iMonetary_locale->int_p_cs_precedes = iMonetary_locale->p_cs_precedes;
1.516 + *monetaryLocale++ = (ELocaleBefore == aCurrencySymbolPosition)?1:0;
1.517 + *monetaryLocale++ = '\0';
1.518 +
1.519 + //Set the currency symbol position for a monetary quantity with negative value
1.520 + iMonetary_locale->n_cs_precedes = (const char*) monetaryLocale;
1.521 + iMonetary_locale->int_n_cs_precedes = iMonetary_locale->n_cs_precedes;
1.522 + *monetaryLocale++ = aNegativeCurrencySymbolOpposite?0:1;
1.523 + *monetaryLocale++ ='\0';
1.524 +
1.525 + //Set the currency symbol separated by space or not for a monetary quantity with non-negative value
1.526 + iMonetary_locale->p_sep_by_space = (const char*) monetaryLocale;
1.527 + iMonetary_locale->int_p_sep_by_space = iMonetary_locale->p_sep_by_space;
1.528 + *monetaryLocale++ = aCurrencySpaceBetween?1:0;
1.529 + *monetaryLocale++ ='\0';
1.530 +
1.531 + //Set the currency symbol separated by space or not for a monetary quantity with negative value
1.532 + iMonetary_locale->n_sep_by_space = (const char*) monetaryLocale;
1.533 + iMonetary_locale->int_n_sep_by_space = iMonetary_locale->n_sep_by_space;
1.534 + *monetaryLocale++ = aNegativeLoseSpace?1:0;
1.535 + *monetaryLocale++ = '\0';
1.536 +
1.537 + //Set the positioning of the negative and positive for a monetary quantity
1.538 + if(TLocale::ELeadingMinusSign == aNegativeCurrencyFormat)
1.539 + {
1.540 + iMonetary_locale->n_sign_posn = (const char*) monetaryLocale;
1.541 + *monetaryLocale++ = 1;
1.542 + *monetaryLocale++ = '\0';
1.543 + }
1.544 + if(TLocale::EInBrackets == aNegativeCurrencyFormat)
1.545 + {
1.546 + iMonetary_locale->n_sign_posn = (const char*) monetaryLocale;
1.547 + *monetaryLocale++ = 0;
1.548 + *monetaryLocale++ = '\0';
1.549 + }
1.550 +
1.551 + if(TLocale::ETrailingMinusSign == aNegativeCurrencyFormat)
1.552 + {
1.553 + iMonetary_locale->n_sign_posn = (const char*) monetaryLocale;
1.554 + *monetaryLocale++ = 2;
1.555 + *monetaryLocale++ = '\0';
1.556 + }
1.557 +
1.558 + if(TLocale::EInterveningMinusSign == aNegativeCurrencyFormat)
1.559 + {
1.560 + iMonetary_locale->n_sign_posn = (const char*) monetaryLocale;
1.561 + *monetaryLocale++ = 3;
1.562 + *monetaryLocale++ = '\0';
1.563 + }
1.564 +
1.565 + iMonetary_locale->int_n_sign_posn = iMonetary_locale->n_sign_posn;
1.566 + iMonetary_locale->p_sign_posn = iMonetary_locale->int_p_sign_posn = iMonetary_locale->n_sign_posn;
1.567 + //Set the positive sign and negative sign for monetary quantity
1.568 + iMonetary_locale->positive_sign = iMonetary_locale->negative_sign = "";
1.569 + //Set the internationla currency symbol
1.570 + iMonetary_locale->int_curr_symbol = "";
1.571 + monetaryLocale = temp;
1.572 + return 0;
1.573 +
1.574 +
1.575 +}
1.576 +/* Forward declaration of ReadALine */
1.577 +inline TInt ReadALine(RFile& aFile, TInt& aPos, TDes8& aDesc);
1.578 +extern void GetInstallationDataDir(TFileName& aPath);
1.579 +#ifdef SYMBIAN_DISTINCT_LOCALE_MODEL
1.580 +
1.581 +TInt CLocale::ParseNewLocaleFile( TDesC& aLocale )
1.582 +{
1.583 +// open and parse the file
1.584 + TPtrC src(aLocale);
1.585 + TBuf8<LOCALE_LENGTH> locale_name;
1.586 + locale_name.Copy(src);
1.587 + char locale[LOCALE_LENGTH];
1.588 + strncpy(locale, (char*) locale_name.Ptr(), locale_name.Length());
1.589 + locale[locale_name.Length()] = '\0';
1.590 +
1.591 + if (NULL == strchr(locale, '.'))
1.592 + {
1.593 + return 0;
1.594 + }
1.595 + RFile newfile;
1.596 +#ifndef __EPOC32__
1.597 + _LIT(localeFileNew,"\\resource\\openc\\locales_new.txt" );
1.598 +#else
1.599 + TFileName localeFileNew;
1.600 + GetInstallationDataDir(localeFileNew);
1.601 + localeFileNew.Append(_L("locales_new.txt" ));
1.602 +#endif
1.603 +
1.604 + int retValNew = newfile.Open(Backend()->FileSession(), localeFileNew, EFileRead);
1.605 + if( KErrNone != retValNew )
1.606 + {
1.607 + return 0;
1.608 + }
1.609 + int pos = 0;
1.610 + TBuf8<LOCALE_LENGTH> localeInfoNew;
1.611 + retValNew = ReadALine(newfile, pos, localeInfoNew);
1.612 + char* buffer = (char*) localeInfoNew.Ptr();
1.613 + int i = 0;
1.614 + int flag = 0;
1.615 + while( retValNew > 0)
1.616 + {
1.617 + char str1[LOCALE_LENGTH];
1.618 + while(buffer[i] != '=')
1.619 + {
1.620 + str1[i] = buffer[i];
1.621 + i++;
1.622 + }
1.623 + str1[i] = '\0';
1.624 + if(!strcmp(str1,locale))
1.625 + {
1.626 + flag = 1;
1.627 + break;
1.628 + }
1.629 + i = 0;
1.630 + retValNew = ReadALine(newfile, pos, localeInfoNew);
1.631 + buffer = (char*) localeInfoNew.Ptr();
1.632 + }
1.633 + if(flag)
1.634 + {
1.635 +
1.636 + iLanDllName.Copy(KLanDllName);
1.637 + iRegDllName.Copy(KRegDllName);
1.638 + ColDllName.Copy(KColDllName);
1.639 + i++;
1.640 + int len = localeInfoNew.Length();
1.641 + TBuf<50> localeids;
1.642 + while(i < len )
1.643 + {
1.644 + localeids.Append(buffer[i]);
1.645 + i++;
1.646 + }
1.647 + TLex lex( localeids );
1.648 + TChar ch;
1.649 + TInt k = 0;
1.650 + TBuf<10> token[3];
1.651 + while((ch = lex.Get()) != 0 )
1.652 + {
1.653 + while (ch != ',' && ch != 0 && ch != '\t' && ch != '\n' && ch != '\r')
1.654 + {
1.655 + lex.Inc();
1.656 + ch = lex.Peek();
1.657 + }
1.658 + token[k].Copy(lex.MarkedToken());
1.659 + k++;
1.660 + lex.Inc();
1.661 + lex.Mark();
1.662 + }
1.663 + iLanDllName.Append(token[0]);
1.664 + iRegDllName.Append(token[1]);
1.665 + ColDllName.Append(token[2]);
1.666 + newfile.Close();
1.667 + return 1;
1.668 +
1.669 + }
1.670 + newfile.Close();
1.671 + return 0;
1.672 +}
1.673 +
1.674 +TInt CLocale::LoadNewLocaleDll( TDesC& aLocale )
1.675 + {
1.676 +
1.677 + if(!ParseNewLocaleFile( aLocale ))
1.678 + {
1.679 + return -1;
1.680 + }
1.681 + RLoader loader;
1.682 + TInt r = loader.Connect();
1.683 + if( KErrNone != r)
1.684 + return -1;
1.685 + TInt size = KNumLocaleExports * sizeof(TLibraryFunction);
1.686 + TPtr8 functionListBuf((TUint8*) iDataRegion, size, size );
1.687 + r = loader.SendReceive(ELoadLocale, TIpcArgs(0, (const TDesC*)&iRegDllName, &functionListBuf) );
1.688 + if( KErrNone != r)
1.689 + return -1;
1.690 + ((TLibFn)iDataRegion[FnLocaleDataV2])(&iLocale);
1.691 + // language dll loading
1.692 + TPtr8 functionListBuf_lan((TUint8*) iDataLanguage, size, size);
1.693 + r = loader.SendReceive(ELoadLocale, TIpcArgs(0, (const TDesC*)&iLanDllName, &functionListBuf_lan) );
1.694 + if( KErrNone != r)
1.695 + return -1;
1.696 +
1.697 + return r;
1.698 +
1.699 + }
1.700 +
1.701 +#endif
1.702 +
1.703 +
1.704 +
1.705 +#ifdef SYMBIAN_OE_ENHANCED_LOCALE_SUPPORT
1.706 +TInt CLocale::NumericLoadLocale(const char* localeName)
1.707 +#else
1.708 +TInt CLocale::NumericLoadLocale(const char* /*localeName*/)
1.709 +#endif
1.710 +{
1.711 + #ifdef SYMBIAN_OE_ENHANCED_LOCALE_SUPPORT
1.712 + if(!localeName)
1.713 + {
1.714 + //update the iLocale with the system settings
1.715 + iLocale.Refresh();
1.716 +
1.717 + }
1.718 + #endif
1.719 + //Retrive numeric information from language variant DLL
1.720 + TBool aCurrencyTriadsAllowed = iLocale.CurrencyTriadsAllowed();
1.721 + iThousandsSeparator= iLocale.ThousandsSeparator();
1.722 + iDecimalSeparator = iLocale.DecimalSeparator();
1.723 +
1.724 + TText8* temp = numericLocale;
1.725 + //Set the decimal separator
1.726 + const TText* dec_point = (const TText*) &iDecimalSeparator;
1.727 + if(dec_point)
1.728 + {
1.729 + const TPtrC dec(dec_point);
1.730 + TBuf8<DECIMAL_THOUSAND_DATE_TIME_SEPARATOR> decimal;
1.731 + decimal.Copy(dec);
1.732 + strncpy((char*) numericLocale, (char*) decimal.Ptr(), decimal.Length());
1.733 + numericLocale[decimal.Length()] ='\0';
1.734 + iNumeric_locale->decimal_point = (const char*) numericLocale;
1.735 + numericLocale += decimal.Length() + 1;
1.736 + }
1.737 +
1.738 + //Set thousand separator
1.739 + const TText* thous_sep = (const TText*) &iThousandsSeparator;
1.740 + if(thous_sep)
1.741 + {
1.742 + const TPtrC thousand(thous_sep);
1.743 + TBuf8<DECIMAL_THOUSAND_DATE_TIME_SEPARATOR> thousand_sep;
1.744 + thousand_sep.Copy(thousand);
1.745 + strncpy((char*) numericLocale, (char*) thousand_sep.Ptr(), thousand_sep.Length());
1.746 + numericLocale[thousand_sep.Length()] = '\0';
1.747 + iNumeric_locale->thousands_sep = (const char*) numericLocale;
1.748 + numericLocale += thousand_sep.Length() + 1;
1.749 + }
1.750 +
1.751 + //Set grouping information
1.752 + strcpy((char*) numericLocale,(aCurrencyTriadsAllowed? "\003":""));
1.753 + numericLocale[strlen((char*) numericLocale)] = '\0';
1.754 + iNumeric_locale->grouping = (const char*) numericLocale;
1.755 + numericLocale += strlen((char*) numericLocale) + 1;
1.756 +
1.757 + numericLocale = temp;
1.758 + return 0;
1.759 +
1.760 +}
1.761 +
1.762 +#ifdef SYMBIAN_DISTINCT_LOCALE_MODEL
1.763 +
1.764 +
1.765 +TInt CLocale::TimeLoadNewLocaleL( const char* localeName )
1.766 +{
1.767 + TInt charsetID = -1;
1.768 + if( localeName )
1.769 + {
1.770 + charsetID = GetCharcaterSetIDL(localeName);
1.771 + if(charsetID == -1)
1.772 + {
1.773 + return -1;
1.774 + }
1.775 + }
1.776 + else
1.777 + {
1.778 + //update the iLocale with the system locale settings
1.779 + iLocale.Refresh();
1.780 + }
1.781 + TText8* startAddress = timeLocale;
1.782 + //Set month and abbreviated month name information
1.783 + for(TInt aMonth = 0 ; aMonth < MONTHS; aMonth++)
1.784 + {
1.785 +
1.786 + const TText16* month = ((reinterpret_cast<TText*const*>((const TText*) iDataLanguage[FnMonthTableV2]()))[aMonth]);
1.787 + if(month)
1.788 + {
1.789 +#ifdef SYMBIAN_OE_ENHANCED_LOCALE_SUPPORT
1.790 + if(!localeName)
1.791 + {
1.792 + ConvertToMultiByteCustom((TUint8*)timeLocale, month);
1.793 + }
1.794 + else
1.795 + {
1.796 +#endif
1.797 + ConvertToMultiByteL((TUint8*)timeLocale, month, charsetID);
1.798 +#ifdef SYMBIAN_OE_ENHANCED_LOCALE_SUPPORT
1.799 + }
1.800 +#endif
1.801 + iTime_locale->month[aMonth] = (const char*) timeLocale;
1.802 + iTime_locale->alt_month[aMonth] = (const char*) timeLocale;
1.803 + timeLocale += strlen((char*) timeLocale) + 1;
1.804 + }
1.805 + const TText16* abbMonth = ((reinterpret_cast<TText*const*>((const TText*) iDataLanguage[FnMonthAbbTableV2]()))[aMonth]);
1.806 + if(abbMonth)
1.807 + {
1.808 +#ifdef SYMBIAN_OE_ENHANCED_LOCALE_SUPPORT
1.809 + if(!localeName)
1.810 + {
1.811 + ConvertToMultiByteCustom((TUint8*)timeLocale, abbMonth);
1.812 + }
1.813 + else
1.814 + {
1.815 +#endif
1.816 + ConvertToMultiByteL((TUint8*)timeLocale, abbMonth, charsetID);
1.817 +#ifdef SYMBIAN_OE_ENHANCED_LOCALE_SUPPORT
1.818 + }
1.819 +#endif
1.820 + iTime_locale->mon[aMonth] = (const char*) timeLocale;
1.821 + timeLocale += strlen((char*) timeLocale) + 1;
1.822 + }
1.823 +
1.824 + }
1.825 +
1.826 + //Set day and abbreviated day name information
1.827 + const TText16* day = ((reinterpret_cast<TText*const*>((const TText*) iDataLanguage[FnDayTableV2]()))[6]);
1.828 + if(day)
1.829 + {
1.830 +#ifdef SYMBIAN_OE_ENHANCED_LOCALE_SUPPORT
1.831 + if(!localeName)
1.832 + {
1.833 + ConvertToMultiByteCustom((TUint8*)timeLocale, day);
1.834 + }
1.835 + else
1.836 + {
1.837 +#endif
1.838 + ConvertToMultiByteL((TUint8*)timeLocale, day, charsetID);
1.839 +#ifdef SYMBIAN_OE_ENHANCED_LOCALE_SUPPORT
1.840 + }
1.841 +#endif
1.842 + iTime_locale->weekday[0] = (const char*) timeLocale;
1.843 + timeLocale += strlen((char*) timeLocale) + 1;
1.844 + }
1.845 + const TText16* abbDay = ((reinterpret_cast<TText*const*>((const TText*) iDataLanguage[FnDayAbbTableV2]()))[6]);
1.846 + if(abbDay)
1.847 + {
1.848 +#ifdef SYMBIAN_OE_ENHANCED_LOCALE_SUPPORT
1.849 + if(!localeName)
1.850 + {
1.851 + ConvertToMultiByteCustom((TUint8*)timeLocale, abbDay);
1.852 + }
1.853 + else
1.854 + {
1.855 +#endif
1.856 + ConvertToMultiByteL((TUint8*)timeLocale, abbDay, charsetID);
1.857 +#ifdef SYMBIAN_OE_ENHANCED_LOCALE_SUPPORT
1.858 + }
1.859 +#endif
1.860 + iTime_locale->wday[0] = (const char*) timeLocale;
1.861 + timeLocale += strlen((char*) timeLocale) + 1;
1.862 + }
1.863 +
1.864 + for(TInt aDay = 0 ; aDay < WEEKDAYS - 1; aDay++)
1.865 + {
1.866 + const TText16* day = ((reinterpret_cast<TText*const*>((const TText*) iDataLanguage[FnDayTableV2]()))[aDay]);
1.867 + if(day)
1.868 + {
1.869 +#ifdef SYMBIAN_OE_ENHANCED_LOCALE_SUPPORT
1.870 + if(!localeName)
1.871 + {
1.872 + ConvertToMultiByteCustom((TUint8*)timeLocale, day);
1.873 + }
1.874 + else
1.875 + {
1.876 +#endif
1.877 + ConvertToMultiByteL((TUint8*)timeLocale, day, charsetID);
1.878 +#ifdef SYMBIAN_OE_ENHANCED_LOCALE_SUPPORT
1.879 + }
1.880 +#endif
1.881 + iTime_locale->weekday[aDay + 1] = (const char*) timeLocale;
1.882 + timeLocale += strlen((char*) timeLocale) + 1;
1.883 + }
1.884 + const TText16* abbDay = ((reinterpret_cast<TText*const*>((const TText*) iDataLanguage[FnDayAbbTableV2]()))[aDay]);
1.885 + if(abbDay)
1.886 + {
1.887 +#ifdef SYMBIAN_OE_ENHANCED_LOCALE_SUPPORT
1.888 + if(!localeName)
1.889 + {
1.890 + ConvertToMultiByteCustom((TUint8*)timeLocale, abbDay);
1.891 + }
1.892 + else
1.893 + {
1.894 +#endif
1.895 + ConvertToMultiByteL((TUint8*)timeLocale, abbDay, charsetID);
1.896 +#ifdef SYMBIAN_OE_ENHANCED_LOCALE_SUPPORT
1.897 + }
1.898 +#endif
1.899 + iTime_locale->wday[aDay + 1] = (const char*) timeLocale;
1.900 + timeLocale += strlen((char*) timeLocale) + 1;
1.901 + }
1.902 +
1.903 + }
1.904 + const TText16* am = ((reinterpret_cast<TText*const*>((const TText*) iDataLanguage[FnAmPmTableV2]()))[0]);
1.905 + if(am)
1.906 + {
1.907 +#ifdef SYMBIAN_OE_ENHANCED_LOCALE_SUPPORT
1.908 + if(!localeName)
1.909 + {
1.910 + ConvertToMultiByteCustom((TUint8*)timeLocale, am);
1.911 + }
1.912 + else
1.913 + {
1.914 +#endif
1.915 + ConvertToMultiByteL((TUint8*)timeLocale, am, charsetID);
1.916 +#ifdef SYMBIAN_OE_ENHANCED_LOCALE_SUPPORT
1.917 + }
1.918 +#endif
1.919 + iTime_locale->am = (const char*) timeLocale;
1.920 + timeLocale += strlen((char*) timeLocale) + 1;
1.921 + }
1.922 + const TText16* pm = ((reinterpret_cast<TText*const*>((const TText*) iDataLanguage[FnAmPmTableV2]()))[1]);
1.923 + if(pm)
1.924 + {
1.925 +#ifdef SYMBIAN_OE_ENHANCED_LOCALE_SUPPORT
1.926 + if(!localeName)
1.927 + {
1.928 + ConvertToMultiByteCustom((TUint8*)timeLocale, pm);
1.929 + }
1.930 + else
1.931 + {
1.932 +#endif
1.933 + ConvertToMultiByteL((TUint8*)timeLocale, pm, charsetID);
1.934 +#ifdef SYMBIAN_OE_ENHANCED_LOCALE_SUPPORT
1.935 + }
1.936 +#endif
1.937 + iTime_locale->pm = (const char*) timeLocale;
1.938 + timeLocale += strlen((char*) timeLocale) + 1;
1.939 + }
1.940 +
1.941 + Mem::Copy(&iLocaleTimeDateFormat.iTimeFormatSpec[0], (const TAny*) iDataRegion[FnTimeFormatSpecV2](), sizeof(TText) * (KMaxTimeFormatSpec+1));
1.942 + TText* timeForm = iLocaleTimeDateFormat.iTimeFormatSpec;
1.943 +
1.944 + //Set time format(T_FMT) and am/pm time format(T_FMT_AMPM) string
1.945 + if(timeForm)
1.946 + {
1.947 + const TPtrC time(timeForm);
1.948 + TBuf8<TIME_FORMAT_LENGTH> timeFormat;
1.949 + timeFormat.Copy(time);
1.950 +
1.951 + TChar timeSeparator = iLocale.TimeSeparator(1);
1.952 + TBuf8<DECIMAL_THOUSAND_DATE_TIME_SEPARATOR> timeSeparator1;
1.953 + timeSeparator1.Append(timeSeparator);
1.954 +
1.955 + timeSeparator = iLocale.TimeSeparator(2);
1.956 + TBuf8<DECIMAL_THOUSAND_DATE_TIME_SEPARATOR> timeSeparator2;
1.957 + timeSeparator2.Append(timeSeparator);
1.958 +
1.959 + TTimeFormat time12hror24hr = iLocale.TimeFormat();
1.960 +
1.961 + if(KErrNotFound != timeFormat.Locate('J'))
1.962 + {
1.963 + //Check for time format(12/24 hour format)
1.964 + if(time12hror24hr == ETime12)
1.965 + {
1.966 + strcpy((char*) timeLocale,TWELVE_HOUR_STR);
1.967 + }
1.968 + else
1.969 + {
1.970 + strcpy((char*) timeLocale,TWENTY_FOUR_HOUR_STR);
1.971 + }
1.972 + }
1.973 +
1.974 + else if(KErrNotFound != timeFormat.Locate('I'))
1.975 + {
1.976 + strcpy((char*) timeLocale,TWELVE_HOUR_STR);
1.977 + }
1.978 +
1.979 + else if(KErrNotFound != timeFormat.Locate('H'))
1.980 + {
1.981 + strcpy((char*) timeLocale,TWENTY_FOUR_HOUR_STR);
1.982 + }
1.983 +
1.984 + strncat((char*) timeLocale, (char*) timeSeparator1.Ptr(), timeSeparator1.Length());
1.985 + strcat((char*) timeLocale, MINUTE_STR);
1.986 + strncat((char*) timeLocale, (char*) timeSeparator2.Ptr(), timeSeparator2.Length());
1.987 + strcat((char*) timeLocale, SECOND_STR);
1.988 +
1.989 + if(time12hror24hr == ETime12)
1.990 + {
1.991 +
1.992 + if((KErrNotFound != timeFormat.Find(KAMPMSpace12hr)) || (KErrNotFound != timeFormat.Find(KAMPMSpace)) )
1.993 + {
1.994 + if((KErrNotFound != timeFormat.Find(KAMPMNoSpace12hr)) || (KErrNotFound != timeFormat.Find(KAMPMNoSpace)))
1.995 + {
1.996 + strcat((char*) timeLocale, AMPM_NO_SPACE);
1.997 + }
1.998 + else
1.999 + {
1.1000 + strcat((char*) timeLocale, AMPM_SPACE);
1.1001 + }
1.1002 + }
1.1003 + }
1.1004 +
1.1005 + iTime_locale->ampm_fmt = (const char*) timeLocale;
1.1006 + iTime_locale->X_fmt = iTime_locale->ampm_fmt;
1.1007 + timeLocale += strlen((char*) timeLocale) + 1;
1.1008 + }
1.1009 +
1.1010 + TDateFormat aDateFormat = iLocale.DateFormat();
1.1011 + //Set date fromat string(D_FMT)
1.1012 + TChar dateSeparator = iLocale.DateSeparator(1);
1.1013 + TBuf8<DECIMAL_THOUSAND_DATE_TIME_SEPARATOR> dateSeparator1;
1.1014 + dateSeparator1.Append(dateSeparator);
1.1015 +
1.1016 + TBuf8<DECIMAL_THOUSAND_DATE_TIME_SEPARATOR> dateSeparator2;
1.1017 + dateSeparator = iLocale.DateSeparator(2);
1.1018 + dateSeparator2.Append(dateSeparator);
1.1019 +
1.1020 + //Americal date formt(mm/dd/YYYY)
1.1021 + if(EDateAmerican == aDateFormat)
1.1022 + {
1.1023 + strcpy((char*) timeLocale, MONTH_STR);
1.1024 + strncat((char*) timeLocale, (char*) dateSeparator1.Ptr(), dateSeparator1.Length());
1.1025 + strcat((char*) timeLocale, DAY_STR);
1.1026 + strncat((char*) timeLocale, (char*) dateSeparator2.Ptr(), dateSeparator2.Length());
1.1027 + strcat((char*) timeLocale, YEAR_STR);
1.1028 + iTime_locale->x_fmt = (const char*) timeLocale;
1.1029 + }
1.1030 +
1.1031 + //European date format(dd/mm/YYYY)
1.1032 + if(EDateEuropean == aDateFormat)
1.1033 + {
1.1034 + strcpy((char*) timeLocale, DAY_STR);
1.1035 + strncat((char*) timeLocale, (char*) dateSeparator1.Ptr(), dateSeparator1.Length());
1.1036 + strcat((char*) timeLocale, MONTH_STR);
1.1037 + strncat((char*) timeLocale, (char*) dateSeparator2.Ptr(), dateSeparator2.Length());
1.1038 + strcat((char*) timeLocale, YEAR_STR);
1.1039 + iTime_locale->x_fmt = (const char*) timeLocale;
1.1040 + }
1.1041 +
1.1042 + //Japanese date format(YYYY/mm/dd)
1.1043 + if(EDateJapanese == aDateFormat)
1.1044 + {
1.1045 + strcpy((char*) timeLocale, YEAR_STR);
1.1046 + strncat((char*) timeLocale, (char*) dateSeparator1.Ptr(), dateSeparator1.Length());
1.1047 + strcat((char*) timeLocale, MONTH_STR);
1.1048 + strncat((char*) timeLocale, (char*) dateSeparator2.Ptr(), dateSeparator2.Length());
1.1049 + strcat((char*) timeLocale, DAY_STR);
1.1050 + iTime_locale->x_fmt = (const char*) timeLocale;
1.1051 + }
1.1052 +
1.1053 + iTime_locale->md_order = iTime_locale->c_fmt = iTime_locale->date_fmt = (const char*) L"";
1.1054 + ;
1.1055 + timeLocale = startAddress;
1.1056 +
1.1057 +
1.1058 +
1.1059 +return 0;
1.1060 +}
1.1061 +#endif
1.1062 +TInt CLocale::TimeLoadLocaleL(const char* localeName)
1.1063 +{
1.1064 +#ifdef SYMBIAN_DISTINCT_LOCALE_MODEL
1.1065 +
1.1066 + if( ! iOldDllPresent)
1.1067 + {
1.1068 + TInt ret = TimeLoadNewLocaleL( localeName ); // option 2 to load language and region dll both
1.1069 + if( ret == -1 )
1.1070 + return -1;
1.1071 + return ret;
1.1072 + }
1.1073 +#endif
1.1074 + TText8* startAddress = timeLocale;
1.1075 + #ifdef SYMBIAN_OE_ENHANCED_LOCALE_SUPPORT
1.1076 + TInt charsetID = -1;
1.1077 + if(localeName)
1.1078 + {
1.1079 + charsetID = GetCharcaterSetIDL(localeName);
1.1080 + if(charsetID == -1)
1.1081 + {
1.1082 + return -1;
1.1083 + }
1.1084 + }
1.1085 + #else
1.1086 + TInt charsetID = GetCharcaterSetIDL(localeName);
1.1087 + if(charsetID == -1)
1.1088 + {
1.1089 + return -1;
1.1090 + }
1.1091 + #endif
1.1092 +
1.1093 +
1.1094 + #ifdef SYMBIAN_OE_ENHANCED_LOCALE_SUPPORT
1.1095 + else
1.1096 + {
1.1097 + iLocale.Refresh();
1.1098 + }
1.1099 + #endif
1.1100 + //Set month and abbreviated month name information
1.1101 + for(TInt aMonth = 0 ; aMonth < MONTHS; aMonth++)
1.1102 + {
1.1103 +
1.1104 + const TText16* month = ((reinterpret_cast<TText*const*>((const TText*) iData[FnMonthTable]()))[aMonth]);
1.1105 + if(month)
1.1106 + {
1.1107 + #ifdef SYMBIAN_OE_ENHANCED_LOCALE_SUPPORT
1.1108 + if(!localeName)
1.1109 + {
1.1110 + ConvertToMultiByteCustom((TUint8*)timeLocale, month);
1.1111 + }
1.1112 + else
1.1113 + {
1.1114 + #endif
1.1115 + ConvertToMultiByteL((TUint8*)timeLocale, month, charsetID);
1.1116 + #ifdef SYMBIAN_OE_ENHANCED_LOCALE_SUPPORT
1.1117 + }
1.1118 + #endif
1.1119 + iTime_locale->month[aMonth] = (const char*) timeLocale;
1.1120 + iTime_locale->alt_month[aMonth] = (const char*) timeLocale;
1.1121 + timeLocale += strlen((char*) timeLocale) + 1;
1.1122 + }
1.1123 +
1.1124 + const TText16* abbMonth = ((reinterpret_cast<TText*const*>((const TText*) iData[FnMonthAbbTable]()))[aMonth]);
1.1125 + if(abbMonth)
1.1126 + {
1.1127 + #ifdef SYMBIAN_OE_ENHANCED_LOCALE_SUPPORT
1.1128 + if(!localeName)
1.1129 + {
1.1130 + ConvertToMultiByteCustom((TUint8*)timeLocale, abbMonth);
1.1131 + }
1.1132 + else
1.1133 + {
1.1134 + #endif
1.1135 + ConvertToMultiByteL((TUint8*)timeLocale, abbMonth, charsetID);
1.1136 + #ifdef SYMBIAN_OE_ENHANCED_LOCALE_SUPPORT
1.1137 + }
1.1138 + #endif
1.1139 + iTime_locale->mon[aMonth] = (const char*) timeLocale;
1.1140 + timeLocale += strlen((char*) timeLocale) + 1;
1.1141 + }
1.1142 +
1.1143 + }
1.1144 +
1.1145 + //Set day and abbreviated day name information
1.1146 +
1.1147 + const TText16* day = ((reinterpret_cast<TText*const*>((const TText*) iData[FnDayTable]()))[6]);
1.1148 + if(day)
1.1149 + {
1.1150 + #ifdef SYMBIAN_OE_ENHANCED_LOCALE_SUPPORT
1.1151 + if(!localeName)
1.1152 + {
1.1153 + ConvertToMultiByteCustom((TUint8*)timeLocale, day);
1.1154 + }
1.1155 + else
1.1156 + {
1.1157 + #endif
1.1158 + ConvertToMultiByteL((TUint8*)timeLocale, day, charsetID);
1.1159 + #ifdef SYMBIAN_OE_ENHANCED_LOCALE_SUPPORT
1.1160 + }
1.1161 + #endif
1.1162 + iTime_locale->weekday[0] = (const char*) timeLocale;
1.1163 + timeLocale += strlen((char*) timeLocale) + 1;
1.1164 + }
1.1165 +
1.1166 +
1.1167 + const TText16* abbDay = ((reinterpret_cast<TText*const*>((const TText*) iData[FnDayAbbTable]()))[6]);
1.1168 + if(abbDay)
1.1169 + {
1.1170 + #ifdef SYMBIAN_OE_ENHANCED_LOCALE_SUPPORT
1.1171 + if(!localeName)
1.1172 + {
1.1173 + ConvertToMultiByteCustom((TUint8*)timeLocale, abbDay);
1.1174 + }
1.1175 + else
1.1176 + {
1.1177 + #endif
1.1178 +
1.1179 + ConvertToMultiByteL((TUint8*)timeLocale, abbDay, charsetID);
1.1180 + #ifdef SYMBIAN_OE_ENHANCED_LOCALE_SUPPORT
1.1181 + }
1.1182 + #endif
1.1183 + iTime_locale->wday[0] = (const char*) timeLocale;
1.1184 + timeLocale += strlen((char*) timeLocale) + 1;
1.1185 + }
1.1186 +
1.1187 + for(TInt aDay = 0 ; aDay < WEEKDAYS - 1; aDay++)
1.1188 + {
1.1189 +
1.1190 + const TText16* day = ((reinterpret_cast<TText*const*>((const TText*) iData[FnDayTable]()))[aDay]);
1.1191 + if(day)
1.1192 + {
1.1193 + #ifdef SYMBIAN_OE_ENHANCED_LOCALE_SUPPORT
1.1194 + if(!localeName)
1.1195 + {
1.1196 + ConvertToMultiByteCustom((TUint8*)timeLocale, day);
1.1197 + }
1.1198 + else
1.1199 + {
1.1200 + #endif
1.1201 + ConvertToMultiByteL((TUint8*)timeLocale, day, charsetID);
1.1202 + #ifdef SYMBIAN_OE_ENHANCED_LOCALE_SUPPORT
1.1203 + }
1.1204 + #endif
1.1205 + iTime_locale->weekday[aDay + 1] = (const char*) timeLocale;
1.1206 + timeLocale += strlen((char*) timeLocale) + 1;
1.1207 + }
1.1208 +
1.1209 +
1.1210 + const TText16* abbDay = ((reinterpret_cast<TText*const*>((const TText*) iData[FnDayAbbTable]()))[aDay]);
1.1211 + if(abbDay)
1.1212 + {
1.1213 + #ifdef SYMBIAN_OE_ENHANCED_LOCALE_SUPPORT
1.1214 + if(!localeName)
1.1215 + {
1.1216 + ConvertToMultiByteCustom((TUint8*)timeLocale, abbDay);
1.1217 + }
1.1218 + else
1.1219 + {
1.1220 + #endif
1.1221 + ConvertToMultiByteL((TUint8*)timeLocale, abbDay, charsetID);
1.1222 + #ifdef SYMBIAN_OE_ENHANCED_LOCALE_SUPPORT
1.1223 + }
1.1224 + #endif
1.1225 + iTime_locale->wday[aDay + 1] = (const char*) timeLocale;
1.1226 + timeLocale += strlen((char*) timeLocale) + 1;
1.1227 + }
1.1228 +
1.1229 + }
1.1230 +
1.1231 + //Set AM string
1.1232 +
1.1233 + const TText16* am = ((reinterpret_cast<TText*const*>((const TText*) iData[FnAmPmTable]()))[0]);
1.1234 + if(am)
1.1235 + {
1.1236 + #ifdef SYMBIAN_OE_ENHANCED_LOCALE_SUPPORT
1.1237 + if(!localeName)
1.1238 + {
1.1239 + ConvertToMultiByteCustom((TUint8*)timeLocale, am);
1.1240 + }
1.1241 + else
1.1242 + {
1.1243 + #endif
1.1244 + ConvertToMultiByteL((TUint8*)timeLocale, am, charsetID);
1.1245 + #ifdef SYMBIAN_OE_ENHANCED_LOCALE_SUPPORT
1.1246 + }
1.1247 + #endif
1.1248 + iTime_locale->am = (const char*) timeLocale;
1.1249 + timeLocale += strlen((char*) timeLocale) + 1;
1.1250 + }
1.1251 +
1.1252 + //Set PM string
1.1253 +
1.1254 + const TText16* pm = ((reinterpret_cast<TText*const*>((const TText*) iData[FnAmPmTable]()))[1]);
1.1255 + if(pm)
1.1256 + {
1.1257 + #ifdef SYMBIAN_OE_ENHANCED_LOCALE_SUPPORT
1.1258 + if(!localeName)
1.1259 + {
1.1260 + ConvertToMultiByteCustom((TUint8*)timeLocale, pm);
1.1261 + }
1.1262 + else
1.1263 + {
1.1264 + #endif
1.1265 + ConvertToMultiByteL((TUint8*)timeLocale, pm, charsetID);
1.1266 + #ifdef SYMBIAN_OE_ENHANCED_LOCALE_SUPPORT
1.1267 + }
1.1268 + #endif
1.1269 + iTime_locale->pm = (const char*) timeLocale;
1.1270 + timeLocale += strlen((char*) timeLocale) + 1;
1.1271 + }
1.1272 +
1.1273 +
1.1274 + Mem::Copy(&iLocaleTimeDateFormat.iTimeFormatSpec[0], (const TAny*) iData[FnTimeFormatSpec](), sizeof(TText) * (KMaxTimeFormatSpec+1));
1.1275 + TText* timeForm = iLocaleTimeDateFormat.iTimeFormatSpec;
1.1276 +
1.1277 + //Set time format(T_FMT) and am/pm time format(T_FMT_AMPM) string
1.1278 + if(timeForm)
1.1279 + {
1.1280 + const TPtrC time(timeForm);
1.1281 + TBuf8<TIME_FORMAT_LENGTH> timeFormat;
1.1282 + timeFormat.Copy(time);
1.1283 +
1.1284 + TChar timeSeparator = iLocale.TimeSeparator(1);
1.1285 + TBuf8<DECIMAL_THOUSAND_DATE_TIME_SEPARATOR> timeSeparator1;
1.1286 + timeSeparator1.Append(timeSeparator);
1.1287 +
1.1288 + timeSeparator = iLocale.TimeSeparator(2);
1.1289 + TBuf8<DECIMAL_THOUSAND_DATE_TIME_SEPARATOR> timeSeparator2;
1.1290 + timeSeparator2.Append(timeSeparator);
1.1291 +
1.1292 + TTimeFormat time12hror24hr = iLocale.TimeFormat();
1.1293 +
1.1294 + if(KErrNotFound != timeFormat.Locate('J'))
1.1295 + {
1.1296 + //Check for time format(12/24 hour format)
1.1297 + if(time12hror24hr == ETime12)
1.1298 + {
1.1299 + strcpy((char*) timeLocale,TWELVE_HOUR_STR);
1.1300 + }
1.1301 + else
1.1302 + {
1.1303 + strcpy((char*) timeLocale,TWENTY_FOUR_HOUR_STR);
1.1304 + }
1.1305 + }
1.1306 +
1.1307 + else if(KErrNotFound != timeFormat.Locate('I'))
1.1308 + {
1.1309 + strcpy((char*) timeLocale,TWELVE_HOUR_STR);
1.1310 + }
1.1311 +
1.1312 + else if(KErrNotFound != timeFormat.Locate('H'))
1.1313 + {
1.1314 + strcpy((char*) timeLocale,TWENTY_FOUR_HOUR_STR);
1.1315 + }
1.1316 +
1.1317 + strncat((char*) timeLocale, (char*) timeSeparator1.Ptr(), timeSeparator1.Length());
1.1318 + strcat((char*) timeLocale, MINUTE_STR);
1.1319 + strncat((char*) timeLocale, (char*) timeSeparator2.Ptr(), timeSeparator2.Length());
1.1320 + strcat((char*) timeLocale, SECOND_STR);
1.1321 +
1.1322 + if(time12hror24hr == ETime12)
1.1323 + {
1.1324 +
1.1325 + if((KErrNotFound != timeFormat.Find(KAMPMSpace12hr)) || (KErrNotFound != timeFormat.Find(KAMPMSpace)) )
1.1326 + {
1.1327 + if((KErrNotFound != timeFormat.Find(KAMPMNoSpace12hr)) || (KErrNotFound != timeFormat.Find(KAMPMNoSpace)))
1.1328 + {
1.1329 + strcat((char*) timeLocale, AMPM_NO_SPACE);
1.1330 + }
1.1331 + else
1.1332 + {
1.1333 + strcat((char*) timeLocale, AMPM_SPACE);
1.1334 + }
1.1335 + }
1.1336 + }
1.1337 +
1.1338 + iTime_locale->ampm_fmt = (const char*) timeLocale;
1.1339 + iTime_locale->X_fmt = iTime_locale->ampm_fmt;
1.1340 + timeLocale += strlen((char*) timeLocale) + 1;
1.1341 + }
1.1342 +
1.1343 + TDateFormat aDateFormat = iLocale.DateFormat();
1.1344 + //Set date fromat string(D_FMT)
1.1345 + TChar dateSeparator = iLocale.DateSeparator(1);
1.1346 + TBuf8<DECIMAL_THOUSAND_DATE_TIME_SEPARATOR> dateSeparator1;
1.1347 + dateSeparator1.Append(dateSeparator);
1.1348 +
1.1349 + TBuf8<DECIMAL_THOUSAND_DATE_TIME_SEPARATOR> dateSeparator2;
1.1350 + dateSeparator = iLocale.DateSeparator(2);
1.1351 + dateSeparator2.Append(dateSeparator);
1.1352 +
1.1353 + //Americal date formt(mm/dd/YYYY)
1.1354 + if(EDateAmerican == aDateFormat)
1.1355 + {
1.1356 + strcpy((char*) timeLocale, MONTH_STR);
1.1357 + strncat((char*) timeLocale, (char*) dateSeparator1.Ptr(), dateSeparator1.Length());
1.1358 + strcat((char*) timeLocale, DAY_STR);
1.1359 + strncat((char*) timeLocale, (char*) dateSeparator2.Ptr(), dateSeparator2.Length());
1.1360 + strcat((char*) timeLocale, YEAR_STR);
1.1361 + iTime_locale->x_fmt = (const char*) timeLocale;
1.1362 + }
1.1363 +
1.1364 + //European date format(dd/mm/YYYY)
1.1365 + if(EDateEuropean == aDateFormat)
1.1366 + {
1.1367 + strcpy((char*) timeLocale, DAY_STR);
1.1368 + strncat((char*) timeLocale, (char*) dateSeparator1.Ptr(), dateSeparator1.Length());
1.1369 + strcat((char*) timeLocale, MONTH_STR);
1.1370 + strncat((char*) timeLocale, (char*) dateSeparator2.Ptr(), dateSeparator2.Length());
1.1371 + strcat((char*) timeLocale, YEAR_STR);
1.1372 + iTime_locale->x_fmt = (const char*) timeLocale;
1.1373 + }
1.1374 +
1.1375 + //Japanese date format(YYYY/mm/dd)
1.1376 + if(EDateJapanese == aDateFormat)
1.1377 + {
1.1378 + strcpy((char*) timeLocale, YEAR_STR);
1.1379 + strncat((char*) timeLocale, (char*) dateSeparator1.Ptr(), dateSeparator1.Length());
1.1380 + strcat((char*) timeLocale, MONTH_STR);
1.1381 + strncat((char*) timeLocale, (char*) dateSeparator2.Ptr(), dateSeparator2.Length());
1.1382 + strcat((char*) timeLocale, DAY_STR);
1.1383 + iTime_locale->x_fmt = (const char*) timeLocale;
1.1384 + }
1.1385 +
1.1386 + iTime_locale->md_order = iTime_locale->c_fmt = iTime_locale->date_fmt = (const char*) L"";
1.1387 + ;
1.1388 + timeLocale = startAddress;
1.1389 + return 0;
1.1390 +
1.1391 +}
1.1392 +
1.1393 +struct lc_numeric_T* CLocale::GetCurrentNumericLocale(void)
1.1394 +{
1.1395 +
1.1396 + if(NULL != iNumeric_locale)
1.1397 + {
1.1398 + return iNumeric_locale;
1.1399 + }
1.1400 + return NULL;
1.1401 +
1.1402 +}
1.1403 +
1.1404 +struct lc_monetary_T* CLocale::GetCurrentMonetaryLocale(void)
1.1405 +{
1.1406 + if(NULL != iMonetary_locale)
1.1407 + {
1.1408 + return iMonetary_locale;
1.1409 + }
1.1410 + return NULL;
1.1411 +}
1.1412 +
1.1413 +struct lc_time_T* CLocale::GetCurrentTimeLocale(void)
1.1414 +{
1.1415 + if(NULL != iTime_locale)
1.1416 + {
1.1417 + return iTime_locale;
1.1418 + }
1.1419 +
1.1420 + return NULL;
1.1421 +}
1.1422 +
1.1423 +
1.1424 +TInt CLocale::LoadLocale(TDesC& aLocale)
1.1425 +{
1.1426 + TPtrC src(aLocale);
1.1427 + TBuf8<LOCALE_LENGTH> locale_name;
1.1428 + locale_name.Copy(src);
1.1429 + char locale[LOCALE_LENGTH];
1.1430 + strncpy(locale, (char*) locale_name.Ptr(), locale_name.Length());
1.1431 + locale[locale_name.Length()] = '\0';
1.1432 +
1.1433 + if (NULL == strchr(locale, '.'))
1.1434 + {
1.1435 + return 0;
1.1436 + }
1.1437 +
1.1438 + // Open the file locale mapping(mapping of POSIX locale string to language variant DLL number) file
1.1439 + RFile file;
1.1440 +
1.1441 +#ifndef __EPOC32__
1.1442 + _LIT(localeFile, "\\resource\\openc\\locales.txt");
1.1443 +#else
1.1444 + TFileName localeFile;
1.1445 + GetInstallationDataDir(localeFile);
1.1446 + localeFile.Append(_L("locales.txt"));
1.1447 +#endif //__EPOC32__
1.1448 +
1.1449 + int retVal = file.Open(Backend()->FileSession(), localeFile, EFileRead);
1.1450 + if(KErrNone != retVal)
1.1451 + {
1.1452 + return 0;
1.1453 + }
1.1454 +
1.1455 + int pos = 0;
1.1456 + TBuf8<LOCALE_LENGTH> localeInfo;
1.1457 + retVal = ReadALine(file, pos, localeInfo);
1.1458 + char* buffer = (char*) localeInfo.Ptr();
1.1459 +
1.1460 + //Check whether locale is supported or not
1.1461 + int i = 0;
1.1462 + int flag = 0;
1.1463 + while( retVal > 0)
1.1464 + {
1.1465 + char str[LOCALE_LENGTH];
1.1466 + while(buffer[i] != '=')
1.1467 + {
1.1468 + str[i] = buffer[i];
1.1469 + i++;
1.1470 + }
1.1471 + str[i] = '\0';
1.1472 + if(!strcmp(str,locale))
1.1473 + {
1.1474 + flag = 1;
1.1475 + break;
1.1476 + }
1.1477 + i = 0;
1.1478 + retVal = ReadALine(file, pos, localeInfo);
1.1479 + buffer = (char*) localeInfo.Ptr();
1.1480 + }
1.1481 + if(flag)
1.1482 + {
1.1483 + DllName.Copy(KDllName);
1.1484 + DllName.Append('.');
1.1485 + i++;
1.1486 + int len = localeInfo.Length();
1.1487 + while(i < len)
1.1488 + {
1.1489 + DllName.Append(buffer[i]);
1.1490 + i++;
1.1491 + }
1.1492 + file.Close();
1.1493 + return 1;
1.1494 + }
1.1495 +
1.1496 + file.Close();
1.1497 + return 0;
1.1498 +
1.1499 +}
1.1500 +
1.1501 +
1.1502 +TInt CLocale::ConvertToMultiByteL(TUint8* aNarrowCharString, const TText16* aWideCharString, TInt aCharsetUID)
1.1503 +{
1.1504 + //Create a handle to a file server session and connect to the file server.
1.1505 + //Push it on to cleanup stack
1.1506 + RFs fileSession;
1.1507 + User::LeaveIfError(fileSession.Connect());
1.1508 + CleanupClosePushL(fileSession);
1.1509 +
1.1510 + //Allocate and constructs a CCnvCharacterSetConverter object
1.1511 + CCnvCharacterSetConverter* conv = CCnvCharacterSetConverter::NewLC();
1.1512 +
1.1513 + //Search the character set array containing all of the character sets for which conversion is available
1.1514 + CCnvCharacterSetConverter::TAvailability avail = conv->PrepareToConvertToOrFromL(aCharsetUID, fileSession);
1.1515 + if(CCnvCharacterSetConverter::ENotAvailable == avail)
1.1516 + {
1.1517 + CleanupStack::PopAndDestroy(2);
1.1518 + *aNarrowCharString = '\0';
1.1519 + return -1;
1.1520 + }
1.1521 +
1.1522 + const TPtrC16 unicodeText(aWideCharString);
1.1523 + TBuf8<NON_UNICODE_TEXT_BUFFER_LENGTH> nativeText;
1.1524 +
1.1525 + TInt retVal = KErrNone;
1.1526 + TInt aNumberOfUnconvertibleCharacters = 0;
1.1527 + TInt aIndexOfFirstByteOfFirstUnconvertibleCharacter = 0;
1.1528 +
1.1529 + //Convert text encoded in the Unicode character set (UCS-2) into other character sets
1.1530 + retVal = conv->ConvertFromUnicode(nativeText,unicodeText, aNumberOfUnconvertibleCharacters, aIndexOfFirstByteOfFirstUnconvertibleCharacter);
1.1531 + TInt returnCode = 0;
1.1532 + //Check for illegal characters in the input
1.1533 + if(retVal == CCnvCharacterSetConverter::EErrorIllFormedInput)
1.1534 + {
1.1535 + *aNarrowCharString = '\0';
1.1536 + returnCode = -1;
1.1537 + }
1.1538 +
1.1539 + //Check for incomplete characters in the input, set the errno accordingly
1.1540 + else if(aNumberOfUnconvertibleCharacters)
1.1541 + {
1.1542 + *aNarrowCharString = '\0';
1.1543 + returnCode = -1;
1.1544 + }
1.1545 + else
1.1546 + {
1.1547 + strncpy((char*) aNarrowCharString, (char*) nativeText.Ptr(), nativeText.Length());
1.1548 + aNarrowCharString[nativeText.Length()] = '\0';
1.1549 + returnCode = 0;
1.1550 + }
1.1551 + CleanupStack::PopAndDestroy(2); // conv, fileSession
1.1552 + return returnCode;
1.1553 +
1.1554 +}
1.1555 +
1.1556 +TInt CLocale::GetCharcaterSetIDL(const char* aLocaleName)
1.1557 +{
1.1558 + //extract the charcate set name from locale string
1.1559 + char* temp = strchr(aLocaleName, '.');
1.1560 + char locale[LOCALE_LENGTH];
1.1561 + if(NULL == temp)
1.1562 + {
1.1563 + return -1;
1.1564 + }
1.1565 + temp++;
1.1566 + int j= 0;
1.1567 + while((*temp != '@') && *temp != '\0')
1.1568 + {
1.1569 + locale[j++] = *temp++;
1.1570 + }
1.1571 + locale[j++] = '\0';
1.1572 +
1.1573 + //Create a handle to a file server session and connect to the file server.
1.1574 + //Push it on to cleanup stack
1.1575 + RFs fileSession;
1.1576 + User::LeaveIfError(fileSession.Connect());
1.1577 + CleanupClosePushL(fileSession);
1.1578 +
1.1579 + TInt characterSetUID = 0;
1.1580 +
1.1581 + //Allocate and constructs a CCnvCharacterSetConverter object
1.1582 + CCnvCharacterSetConverter* conv = CCnvCharacterSetConverter::NewLC() ;
1.1583 +
1.1584 + //Create an array identifying all the character sets for which conversion is available
1.1585 + CArrayFix<CCnvCharacterSetConverter::SCharacterSet> *charSet = CCnvCharacterSetConverter::CreateArrayOfCharacterSetsAvailableL(fileSession);
1.1586 + CleanupStack::PushL( charSet );
1.1587 +
1.1588 + TInt i = 0;
1.1589 + //Get the number of character sets for which conversion is available
1.1590 + TInt count = charSet->Count();
1.1591 + while(i < count)
1.1592 + {
1.1593 + CCnvCharacterSetConverter::SCharacterSet characterSet = charSet->At(i);
1.1594 + i++;
1.1595 + //Get the UID of character set for which conversion is available
1.1596 + TUint charSetUID = characterSet.Identifier();
1.1597 +
1.1598 + const TBufC<CHARACTER_SET_NAME> charSetName = characterSet.NameIsFileName()?TParsePtrC(characterSet.Name()).Name():characterSet.Name();
1.1599 + TBuf8<CHARACTER_SET_NAME> aCharSetname;
1.1600 + aCharSetname.Copy(charSetName);
1.1601 +
1.1602 + //Assign the character set UID
1.1603 + if(!aCharSetname.Compare(TPtrC8((const TText8*) locale)))
1.1604 + {
1.1605 + characterSetUID = charSetUID;
1.1606 + break;
1.1607 + }
1.1608 +
1.1609 + HBufC8* stdInterName = conv->ConvertCharacterSetIdentifierToStandardNameL(charSetUID, fileSession);
1.1610 + if(NULL != stdInterName)
1.1611 + {
1.1612 + if(!stdInterName->Compare(TPtrC8((const TText8*) locale)))
1.1613 + {
1.1614 + characterSetUID = charSetUID;
1.1615 + delete stdInterName;
1.1616 + stdInterName = NULL;
1.1617 + break;
1.1618 + }
1.1619 + delete stdInterName;
1.1620 + stdInterName = NULL;
1.1621 + }
1.1622 + }
1.1623 +
1.1624 + if(!characterSetUID)
1.1625 + {
1.1626 + characterSetUID = -1;
1.1627 + }
1.1628 +
1.1629 + CleanupStack::PopAndDestroy(3); //charSet, conv, fileSession
1.1630 + return characterSetUID;
1.1631 +}
1.1632 +
1.1633 +/* ReadALine : Reads one line at a time from specified file */
1.1634 +inline TInt ReadALine(RFile& aFile, TInt& aPos, TDes8& aDesc)
1.1635 + {
1.1636 + TInt ret = aFile.Read(aPos, aDesc);
1.1637 + TChar delimOne = '\r';
1.1638 + TChar delimTwo = '\n';
1.1639 +
1.1640 + TInt len = aDesc.Length();
1.1641 + if(!ret && len)
1.1642 + {
1.1643 + //Always assumes that each line will end with "\r\n" except the last line
1.1644 + TInt pos = aDesc.Locate(delimOne);
1.1645 + pos = aDesc.Locate(delimTwo);
1.1646 +
1.1647 + if(KErrNotFound != pos)
1.1648 + {
1.1649 + aPos = aPos + pos + 1;
1.1650 + len = pos - 1;
1.1651 + aDesc.SetLength(len);
1.1652 + }
1.1653 + else
1.1654 + {
1.1655 + aPos = aPos + len;
1.1656 + }
1.1657 + }
1.1658 + return len;
1.1659 + }
1.1660 +#ifdef SYMBIAN_OE_ENHANCED_LOCALE_SUPPORT
1.1661 +
1.1662 +void CLocale::ConvertToMultiByteCustom(TUint8* aNarrowCharString, const TText16* aWideCharString)
1.1663 + {
1.1664 + const TPtrC unicodeText(aWideCharString);
1.1665 + TBuf8<NON_UNICODE_TEXT_BUFFER_LENGTH> nativeText;
1.1666 + nativeText.Copy(unicodeText);
1.1667 + strncpy((char*) aNarrowCharString, (char*) nativeText.Ptr(), nativeText.Length());
1.1668 + aNarrowCharString[nativeText.Length()] = '\0';
1.1669 + }
1.1670 +
1.1671 +TInt CLocale::SyncLocale(TLocaleAspect aspect)
1.1672 + {
1.1673 +#ifdef SYMBIAN_DISTINCT_LOCALE_MODEL
1.1674 + TBuf<NON_UNICODE_TEXT_BUFFER_LENGTH> reg_dllname;
1.1675 +#endif
1.1676 + TBuf<NON_UNICODE_TEXT_BUFFER_LENGTH> Kdname;
1.1677 + TExtendedLocale locale;
1.1678 + locale.LoadSystemSettings();
1.1679 + locale.GetLocaleDllName(aspect,Kdname);
1.1680 +#ifdef SYMBIAN_DISTINCT_LOCALE_MODEL
1.1681 + // check if the new dlls is present then load it or go for old dll
1.1682 + if( Kdname.FindC(_L("elocl.")) == KErrNotFound )
1.1683 + {
1.1684 + iOldDllPresent = 0;
1.1685 + locale.GetLocaleDllName(ELocaleTimeDateSettings,reg_dllname);
1.1686 + return (GetSystemLocale(Kdname,reg_dllname ));
1.1687 + }
1.1688 + else
1.1689 + iOldDllPresent = 1;
1.1690 +#endif
1.1691 + return (GetSystemLocale(Kdname));
1.1692 + }
1.1693 +
1.1694 +const TText* CLocale::GetLocaleName(void)
1.1695 + {
1.1696 + TPtrC dllname(DllName);
1.1697 + return dllname.Ptr();
1.1698 + }
1.1699 +
1.1700 +
1.1701 +#ifdef SYMBIAN_DISTINCT_LOCALE_MODEL
1.1702 +
1.1703 +const TText* CLocale::GetCollateLocaleName(void)
1.1704 + {
1.1705 + TPtrC dllname(ColDllName);
1.1706 + return dllname.Ptr();
1.1707 + }
1.1708 +#endif
1.1709 +
1.1710 +
1.1711 +#endif // SYMBIAN_OE_ENHANCED_LOCALE_SUPPORT
1.1712 +
1.1713 +
1.1714 +
1.1715 +