Update contrib.
2 * Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies).
4 * This component and the accompanying materials are made available
5 * under the terms of "Eclipse Public License v1.0"
6 * which accompanies this distribution, and is available
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
9 * Initial Contributors:
10 * Nokia Corporation - initial contribution.
14 * Description: Contains the source for all locale related functionalities
22 #include "localeinfo.h"
24 #include <e32std_private.h>
25 #include <e32ldr_private.h>
27 typedef void (*TLibFn)(TLocale*);
29 #if (defined(__SYMBIAN32__) && (defined(__WINSCW__) || defined(__WINS__)))
30 #include "libc_wsd_defs.h"
31 #include "localetlsinfo.h"
34 #ifdef SYMBIAN_DISTINCT_LOCALE_MODEL
35 #define NEW_LANG_VARIANT_DLL_NAME 30
39 #define LC_TIME_MEMORY 1024
40 #define LC_MONETARY_MEMORY 50
41 #define LC_NUMERIC_MEMORY 20
44 #define DECIMAL_THOUSAND_DATE_TIME_SEPARATOR 2
45 #define EURO_CURRENCY 4
46 #define LOCALE_LENGTH 50
47 #define CHARACTER_SET_NAME 32
48 #define TIME_FORMAT_LENGTH 32
49 #define NON_UNICODE_TEXT_BUFFER_LENGTH 256
50 #define LANG_VARIANT_DLL_NAME 10
52 #define MONTH_STR "%m"
55 #define TWELVE_HOUR_STR "%I"
56 #define TWENTY_FOUR_HOUR_STR "%H"
57 #define MINUTE_STR "%M"
58 #define SECOND_STR "%S"
59 #define AMPM_SPACE " %p"
60 #define AMPM_NO_SPACE "%p"
63 #ifdef SYMBIAN_DISTINCT_LOCALE_MODEL
66 _LIT(KLanDllName, "elocl_lan.");
67 _LIT(KRegDllName, "elocl_reg.");
68 _LIT(KColDllName, "elocl_col.");
72 _LIT(KDllName, "elocl");
75 #ifndef SYMBIAN_OE_ENHANCED_LOCALE_SUPPORT
76 _LIT(KEuro, "\x20AC");
79 _LIT8(KAMPMSpace12hr, "B");
80 _LIT8(KAMPMSpace, "A");
81 _LIT8(KAMPMNoSpace12hr, "*B");
82 _LIT8(KAMPMNoSpace, "*A");
86 CLocale* CLocale::iNewLocale = NULL;
87 lc_monetary_T* CLocale::iMonetary_locale = NULL;
88 lc_numeric_T* CLocale::iNumeric_locale =NULL;
89 lc_time_T* CLocale::iTime_locale = NULL;
91 TText8* numericLocale = NULL;
92 TText8* monetaryLocale = NULL;
93 TText8* timeLocale = NULL;
95 static TBuf<LANG_VARIANT_DLL_NAME> DllName;
97 #ifdef SYMBIAN_DISTINCT_LOCALE_MODEL
98 static TBuf<NEW_LANG_VARIANT_DLL_NAME> ColDllName;
103 #define iNewLocale ((GetGlobals()->localeptr)->GET_WSD_VAR_NAME(iNewLocale,s))
104 #define iMonetary_locale ((GetGlobals()->localeptr)->GET_WSD_VAR_NAME(iMonetary_locale,s))
105 #define iNumeric_locale ((GetGlobals()->localeptr)->GET_WSD_VAR_NAME(iNumeric_locale,s))
106 #define iTime_locale ((GetGlobals()->localeptr)->GET_WSD_VAR_NAME(iTime_locale,s))
108 #define numericLocale ((GetGlobals()->localeptr)->GET_WSD_VAR_NAME(numericLocale,s))
109 #define monetaryLocale ((GetGlobals()->localeptr)->GET_WSD_VAR_NAME(monetaryLocale,s))
110 #define timeLocale ((GetGlobals()->localeptr)->GET_WSD_VAR_NAME(timeLocale,s))
112 #define DllName ((GetGlobals()->localeptr)->GET_WSD_VAR_NAME(DllName,s))
114 #ifdef SYMBIAN_DISTINCT_LOCALE_MODEL
116 #define ColDllName ((GetGlobals()->localeptr)->GET_WSD_VAR_NAME(ColDllName,s))
123 iMonetary_locale = NULL;
124 iNumeric_locale = NULL;
127 numericLocale = NULL;
128 monetaryLocale = NULL;
130 #ifdef SYMBIAN_DISTINCT_LOCALE_MODEL
137 CLocale* CLocale::New()
139 CLocale* self = new CLocale();
143 TRAPD(result,ret = self->ConstructL());
144 if(KErrNone != (result | ret))
153 TInt CLocale::ConstructL()
155 iMonetary_locale = new lc_monetary_T;
156 if(!iMonetary_locale)
160 iNumeric_locale = new lc_numeric_T;
165 iTime_locale = new (ELeave) lc_time_T;
171 for(TInt i =0 ; i < MONTHS; i++)
173 iTime_locale->mon[i] = NULL;
174 iTime_locale->month[i] = NULL;
175 iTime_locale->alt_month[i] = NULL;
179 for(TInt i =0 ; i < WEEKDAYS; i++)
181 iTime_locale->wday[i] = NULL;
182 iTime_locale->weekday[i] = NULL;
185 iTime_locale->X_fmt = NULL;
186 iTime_locale->x_fmt = NULL;
187 iTime_locale->c_fmt = NULL;
188 iTime_locale->am = NULL;
189 iTime_locale->pm = NULL;
190 iTime_locale->date_fmt = NULL;
191 iTime_locale->md_order = NULL;
192 iTime_locale->ampm_fmt = NULL;
194 iMonetary_locale->int_curr_symbol = NULL;
195 iMonetary_locale->currency_symbol = NULL;
196 iMonetary_locale->mon_decimal_point = NULL;
197 iMonetary_locale->mon_thousands_sep = NULL;
198 iMonetary_locale->mon_grouping = NULL;
199 iMonetary_locale->positive_sign = NULL;
200 iMonetary_locale->negative_sign = NULL;
201 iMonetary_locale->int_frac_digits = iMonetary_locale->frac_digits = NULL;
202 iMonetary_locale->p_cs_precedes = iMonetary_locale->int_p_cs_precedes = NULL;
203 iMonetary_locale->p_sep_by_space = iMonetary_locale->int_p_sep_by_space = NULL;
204 iMonetary_locale->n_cs_precedes = iMonetary_locale->int_n_cs_precedes = NULL;
205 iMonetary_locale->n_sep_by_space = iMonetary_locale->int_n_sep_by_space = NULL;
206 iMonetary_locale->p_sign_posn = iMonetary_locale->int_p_sign_posn = NULL;
207 iMonetary_locale->n_sign_posn = iMonetary_locale->int_n_sign_posn = NULL;
209 iNumeric_locale->decimal_point = NULL;
210 iNumeric_locale->thousands_sep = NULL;
211 iNumeric_locale->grouping = NULL;
216 CLocale* CLocale::GetInstance()
218 // Switch to the backend heap
219 RHeap* oldheap = User::SwitchHeap(Backend()->Heap());
221 if(NULL == iNewLocale)
226 if(numericLocale == NULL )
228 numericLocale = new TText8 [LC_NUMERIC_MEMORY];
231 if(monetaryLocale == NULL)
233 monetaryLocale = new TText8[LC_MONETARY_MEMORY];
236 if(timeLocale == NULL)
238 timeLocale = new TText8[LC_TIME_MEMORY];
243 //Set back the default user heap
244 User::SwitchHeap(oldheap);
249 void CLocale::DeleteInstance()
251 // Switch to the backend heap so that deletes happen from there
252 RHeap* oldheap = User::SwitchHeap(Backend()->Heap());
254 delete [] timeLocale;
257 delete [] numericLocale;
258 numericLocale = NULL;
260 delete [] monetaryLocale;
261 monetaryLocale = NULL;
263 delete iMonetary_locale;
264 iMonetary_locale = NULL;
266 delete iNumeric_locale;
267 iNumeric_locale = NULL;
277 //Set back to the default user heap
278 User::SwitchHeap(oldheap);
282 TText* CLocale::SetLocale(TDesC& aLocale)
284 //Check whether locale is supported
286 TText* retVal = NULL;
288 #ifdef SYMBIAN_DISTINCT_LOCALE_MODEL
290 // load the new locale dll if not present check for the old dll
291 r = LoadNewLocaleDll( aLocale );
294 retVal = (TText*) aLocale.Ptr();
300 if(!LoadLocale(aLocale))
305 r = loader.Connect();
308 //Load the language variant DLL
309 TInt size = KNumLocaleExports * sizeof(TLibraryFunction);
310 TPtr8 functionListBuf((TUint8*) iData, size, size);
311 r = loader.SendReceive(ELoadLocale, TIpcArgs(0, (const TDesC*)&DllName, &functionListBuf) );
314 ((TLibFn)iData[FnLocaleData])(&iLocale);
315 retVal = (TText*) aLocale.Ptr();
316 #ifdef SYMBIAN_DISTINCT_LOCALE_MODEL
325 #ifdef SYMBIAN_OE_ENHANCED_LOCALE_SUPPORT
327 #ifdef SYMBIAN_DISTINCT_LOCALE_MODEL
328 TInt CLocale::GetSystemLocale(TDesC& aLanDllName,TDesC& aRegDllName)
332 TInt r = loader.Connect();
335 TInt size = KNumLocaleExports * sizeof(TLibraryFunction);
336 TPtr8 functionListBuf1((TUint8*) iDataLanguage, size, size);
337 r = loader.SendReceive(ELoadLocale, TIpcArgs(0, (const TDesC*)&aLanDllName, &functionListBuf1) );
340 TPtr8 functionListBuf2((TUint8*) iDataRegion, size, size);
341 r = loader.SendReceive(ELoadLocale, TIpcArgs(0, (const TDesC*)&aRegDllName, &functionListBuf2) );
342 ((TLibFn)iDataRegion[FnLocaleDataV2])(&iLocale);
352 //Load the system dll settings
353 TInt CLocale::GetSystemLocale(TDesC& aDllName)
357 TInt r = loader.Connect();
360 //Load the language variant DLL
361 TInt size = KNumLocaleExports * sizeof(TLibraryFunction);
362 TPtr8 functionListBuf((TUint8*) iData, size, size);
363 r = loader.SendReceive(ELoadLocale, TIpcArgs(0, (const TDesC*)&aDllName, &functionListBuf) );
366 ((TLibFn)iData[FnLocaleData])(&iLocale);
377 TInt CLocale::MonetaryLoadLocaleL(const char* localeName)
379 #ifdef SYMBIAN_OE_ENHANCED_LOCALE_SUPPORT
383 charsetID = GetCharcaterSetIDL(localeName);
390 TInt charsetID = GetCharcaterSetIDL(localeName);
396 #ifdef SYMBIAN_OE_ENHANCED_LOCALE_SUPPORT
399 //update the iLocale with the system locale settings
403 #ifndef SYMBIAN_OE_ENHANCED_LOCALE_SUPPORT
404 //Retreive monetary information from language variant DLL
405 Mem::Copy(&iLocaleSettings.iCurrencySymbol[0], (const TAny*) iData[FnCurrencySymbol](), sizeof(TText) * (KMaxCurrencySymbol+1));
407 TLocalePos aCurrencySymbolPosition = iLocale.CurrencySymbolPosition();
408 TLocale::TNegativeCurrencyFormat aNegativeCurrencyFormat = iLocale.NegativeCurrencyFormat();
409 TBool aCurrencySpaceBetween = iLocale.CurrencySpaceBetween();
410 TBool aNegativeCurrencySymbolOpposite = iLocale.NegativeCurrencySymbolOpposite();
411 TBool aNegativeLoseSpace = iLocale.NegativeLoseSpace();
412 TBool aCurrencyTriadsAllowed = iLocale.CurrencyTriadsAllowed();
414 TInt currencyDecimalPlaces = iLocale.CurrencyDecimalPlaces();
415 iThousandsSeparator= iLocale.ThousandsSeparator();
416 iDecimalSeparator = iLocale.DecimalSeparator();
418 TText8* temp = monetaryLocale;
420 //Set the decimal separator
421 const TText* dec_point = (const TText*) &iDecimalSeparator;
424 const TPtrC dec(dec_point);
425 TBuf8<DECIMAL_THOUSAND_DATE_TIME_SEPARATOR> decimal;
427 strncpy((char*) monetaryLocale, (char*) decimal.Ptr(), decimal.Length());
428 monetaryLocale[decimal.Length()] = '\0';
429 iMonetary_locale->mon_decimal_point = (const char*) monetaryLocale;
430 monetaryLocale += decimal.Length() + 1;
433 //Set thousand separator
434 const TText* thous_sep = (const TText*) &iThousandsSeparator;
437 const TPtrC thousand(thous_sep);
438 TBuf8<DECIMAL_THOUSAND_DATE_TIME_SEPARATOR> thousand_sep;
439 thousand_sep.Copy(thousand);
440 strncpy((char*) monetaryLocale, (char*) thousand_sep.Ptr(), thousand_sep.Length());
441 monetaryLocale[thousand_sep.Length()] = '\0';
442 iMonetary_locale->mon_thousands_sep = (const char*) monetaryLocale;
443 monetaryLocale += thousand_sep.Length() + 1;
445 #ifdef SYMBIAN_OE_ENHANCED_LOCALE_SUPPORT
446 TBuf<KMaxCurrencySymbol> CurrencySymbol;
449 #ifdef SYMBIAN_DISTINCT_LOCALE_MODEL
450 if( iOldDllPresent ) // old style dll is loaded
452 Mem::Copy(&iLocaleSettings.iCurrencySymbol[0], (const TAny*) iData[FnCurrencySymbol](), sizeof(TText) * (KMaxCurrencySymbol+1));
456 Mem::Copy(&iLocaleSettings.iCurrencySymbol[0], (const TAny*) iDataRegion[FnCurrencySymbolV2](), sizeof(TText) * (KMaxCurrencySymbol+1));
459 Mem::Copy(&iLocaleSettings.iCurrencySymbol[0], (const TAny*) iData[FnCurrencySymbol](), sizeof(TText) * (KMaxCurrencySymbol+1));
461 //Set Currency information
462 const TText16* cur = iLocaleSettings.iCurrencySymbol;
463 const TPtrC currency(cur);
464 CurrencySymbol.Copy(currency);
469 const TPtrC currency(cur);
470 CurrencySymbol.Copy(currency);
472 strncpy((char*) monetaryLocale, (char*) CurrencySymbol.Ptr(), CurrencySymbol.Length());
473 monetaryLocale[CurrencySymbol.Length()] = '\0';
474 iMonetary_locale->currency_symbol = (const char*) monetaryLocale;
475 monetaryLocale += strlen((char*) monetaryLocale) + 1;
477 //Set Currency information
478 const TText16* currency = iLocaleSettings.iCurrencySymbol;
481 TBuf<EURO_CURRENCY> euroSymbol(currency);
482 char* temp = strchr(localeName, '.');
485 if(!euroSymbol.Compare(KEuro) && !strcmp(temp, "ISO-8859-1"))
487 strcpy((char*) monetaryLocale,"\x80");
488 monetaryLocale[1] = '\0';
492 ConvertToMultiByteL((TText8*)monetaryLocale, currency, charsetID);
494 iMonetary_locale->currency_symbol = (const char*) monetaryLocale;
495 monetaryLocale += strlen((char*) monetaryLocale) + 1;
499 //Set grouping information
500 strcpy((char*) monetaryLocale,(aCurrencyTriadsAllowed? "\003":""));
501 monetaryLocale[strlen((char*) monetaryLocale)] = '\0';
502 iMonetary_locale->mon_grouping = (const char*) monetaryLocale;
503 monetaryLocale += strlen((char*) monetaryLocale) + 1;
505 //Set currency decimal places
506 iMonetary_locale->int_frac_digits = iMonetary_locale->frac_digits = (const char*) monetaryLocale;
507 *monetaryLocale++ = currencyDecimalPlaces;
508 *monetaryLocale++ = '\0';
510 //Set the currency symbol position for a monetary quantity with non-negative value
511 iMonetary_locale->p_cs_precedes = (const char*) monetaryLocale;
512 iMonetary_locale->int_p_cs_precedes = iMonetary_locale->p_cs_precedes;
513 *monetaryLocale++ = (ELocaleBefore == aCurrencySymbolPosition)?1:0;
514 *monetaryLocale++ = '\0';
516 //Set the currency symbol position for a monetary quantity with negative value
517 iMonetary_locale->n_cs_precedes = (const char*) monetaryLocale;
518 iMonetary_locale->int_n_cs_precedes = iMonetary_locale->n_cs_precedes;
519 *monetaryLocale++ = aNegativeCurrencySymbolOpposite?0:1;
520 *monetaryLocale++ ='\0';
522 //Set the currency symbol separated by space or not for a monetary quantity with non-negative value
523 iMonetary_locale->p_sep_by_space = (const char*) monetaryLocale;
524 iMonetary_locale->int_p_sep_by_space = iMonetary_locale->p_sep_by_space;
525 *monetaryLocale++ = aCurrencySpaceBetween?1:0;
526 *monetaryLocale++ ='\0';
528 //Set the currency symbol separated by space or not for a monetary quantity with negative value
529 iMonetary_locale->n_sep_by_space = (const char*) monetaryLocale;
530 iMonetary_locale->int_n_sep_by_space = iMonetary_locale->n_sep_by_space;
531 *monetaryLocale++ = aNegativeLoseSpace?1:0;
532 *monetaryLocale++ = '\0';
534 //Set the positioning of the negative and positive for a monetary quantity
535 if(TLocale::ELeadingMinusSign == aNegativeCurrencyFormat)
537 iMonetary_locale->n_sign_posn = (const char*) monetaryLocale;
538 *monetaryLocale++ = 1;
539 *monetaryLocale++ = '\0';
541 if(TLocale::EInBrackets == aNegativeCurrencyFormat)
543 iMonetary_locale->n_sign_posn = (const char*) monetaryLocale;
544 *monetaryLocale++ = 0;
545 *monetaryLocale++ = '\0';
548 if(TLocale::ETrailingMinusSign == aNegativeCurrencyFormat)
550 iMonetary_locale->n_sign_posn = (const char*) monetaryLocale;
551 *monetaryLocale++ = 2;
552 *monetaryLocale++ = '\0';
555 if(TLocale::EInterveningMinusSign == aNegativeCurrencyFormat)
557 iMonetary_locale->n_sign_posn = (const char*) monetaryLocale;
558 *monetaryLocale++ = 3;
559 *monetaryLocale++ = '\0';
562 iMonetary_locale->int_n_sign_posn = iMonetary_locale->n_sign_posn;
563 iMonetary_locale->p_sign_posn = iMonetary_locale->int_p_sign_posn = iMonetary_locale->n_sign_posn;
564 //Set the positive sign and negative sign for monetary quantity
565 iMonetary_locale->positive_sign = iMonetary_locale->negative_sign = "";
566 //Set the internationla currency symbol
567 iMonetary_locale->int_curr_symbol = "";
568 monetaryLocale = temp;
573 /* Forward declaration of ReadALine */
574 inline TInt ReadALine(RFile& aFile, TInt& aPos, TDes8& aDesc);
575 extern void GetInstallationDataDir(TFileName& aPath);
576 #ifdef SYMBIAN_DISTINCT_LOCALE_MODEL
578 TInt CLocale::ParseNewLocaleFile( TDesC& aLocale )
580 // open and parse the file
582 TBuf8<LOCALE_LENGTH> locale_name;
583 locale_name.Copy(src);
584 char locale[LOCALE_LENGTH];
585 strncpy(locale, (char*) locale_name.Ptr(), locale_name.Length());
586 locale[locale_name.Length()] = '\0';
588 if (NULL == strchr(locale, '.'))
594 _LIT(localeFileNew,"\\resource\\openc\\locales_new.txt" );
596 TFileName localeFileNew;
597 GetInstallationDataDir(localeFileNew);
598 localeFileNew.Append(_L("locales_new.txt" ));
601 int retValNew = newfile.Open(Backend()->FileSession(), localeFileNew, EFileRead);
602 if( KErrNone != retValNew )
607 TBuf8<LOCALE_LENGTH> localeInfoNew;
608 retValNew = ReadALine(newfile, pos, localeInfoNew);
609 char* buffer = (char*) localeInfoNew.Ptr();
612 while( retValNew > 0)
614 char str1[LOCALE_LENGTH];
615 while(buffer[i] != '=')
621 if(!strcmp(str1,locale))
627 retValNew = ReadALine(newfile, pos, localeInfoNew);
628 buffer = (char*) localeInfoNew.Ptr();
633 iLanDllName.Copy(KLanDllName);
634 iRegDllName.Copy(KRegDllName);
635 ColDllName.Copy(KColDllName);
637 int len = localeInfoNew.Length();
641 localeids.Append(buffer[i]);
644 TLex lex( localeids );
648 while((ch = lex.Get()) != 0 )
650 while (ch != ',' && ch != 0 && ch != '\t' && ch != '\n' && ch != '\r')
655 token[k].Copy(lex.MarkedToken());
660 iLanDllName.Append(token[0]);
661 iRegDllName.Append(token[1]);
662 ColDllName.Append(token[2]);
671 TInt CLocale::LoadNewLocaleDll( TDesC& aLocale )
674 if(!ParseNewLocaleFile( aLocale ))
679 TInt r = loader.Connect();
682 TInt size = KNumLocaleExports * sizeof(TLibraryFunction);
683 TPtr8 functionListBuf((TUint8*) iDataRegion, size, size );
684 r = loader.SendReceive(ELoadLocale, TIpcArgs(0, (const TDesC*)&iRegDllName, &functionListBuf) );
687 ((TLibFn)iDataRegion[FnLocaleDataV2])(&iLocale);
688 // language dll loading
689 TPtr8 functionListBuf_lan((TUint8*) iDataLanguage, size, size);
690 r = loader.SendReceive(ELoadLocale, TIpcArgs(0, (const TDesC*)&iLanDllName, &functionListBuf_lan) );
702 #ifdef SYMBIAN_OE_ENHANCED_LOCALE_SUPPORT
703 TInt CLocale::NumericLoadLocale(const char* localeName)
705 TInt CLocale::NumericLoadLocale(const char* /*localeName*/)
708 #ifdef SYMBIAN_OE_ENHANCED_LOCALE_SUPPORT
711 //update the iLocale with the system settings
716 //Retrive numeric information from language variant DLL
717 TBool aCurrencyTriadsAllowed = iLocale.CurrencyTriadsAllowed();
718 iThousandsSeparator= iLocale.ThousandsSeparator();
719 iDecimalSeparator = iLocale.DecimalSeparator();
721 TText8* temp = numericLocale;
722 //Set the decimal separator
723 const TText* dec_point = (const TText*) &iDecimalSeparator;
726 const TPtrC dec(dec_point);
727 TBuf8<DECIMAL_THOUSAND_DATE_TIME_SEPARATOR> decimal;
729 strncpy((char*) numericLocale, (char*) decimal.Ptr(), decimal.Length());
730 numericLocale[decimal.Length()] ='\0';
731 iNumeric_locale->decimal_point = (const char*) numericLocale;
732 numericLocale += decimal.Length() + 1;
735 //Set thousand separator
736 const TText* thous_sep = (const TText*) &iThousandsSeparator;
739 const TPtrC thousand(thous_sep);
740 TBuf8<DECIMAL_THOUSAND_DATE_TIME_SEPARATOR> thousand_sep;
741 thousand_sep.Copy(thousand);
742 strncpy((char*) numericLocale, (char*) thousand_sep.Ptr(), thousand_sep.Length());
743 numericLocale[thousand_sep.Length()] = '\0';
744 iNumeric_locale->thousands_sep = (const char*) numericLocale;
745 numericLocale += thousand_sep.Length() + 1;
748 //Set grouping information
749 strcpy((char*) numericLocale,(aCurrencyTriadsAllowed? "\003":""));
750 numericLocale[strlen((char*) numericLocale)] = '\0';
751 iNumeric_locale->grouping = (const char*) numericLocale;
752 numericLocale += strlen((char*) numericLocale) + 1;
754 numericLocale = temp;
759 #ifdef SYMBIAN_DISTINCT_LOCALE_MODEL
762 TInt CLocale::TimeLoadNewLocaleL( const char* localeName )
767 charsetID = GetCharcaterSetIDL(localeName);
775 //update the iLocale with the system locale settings
778 TText8* startAddress = timeLocale;
779 //Set month and abbreviated month name information
780 for(TInt aMonth = 0 ; aMonth < MONTHS; aMonth++)
783 const TText16* month = ((reinterpret_cast<TText*const*>((const TText*) iDataLanguage[FnMonthTableV2]()))[aMonth]);
786 #ifdef SYMBIAN_OE_ENHANCED_LOCALE_SUPPORT
789 ConvertToMultiByteCustom((TUint8*)timeLocale, month);
794 ConvertToMultiByteL((TUint8*)timeLocale, month, charsetID);
795 #ifdef SYMBIAN_OE_ENHANCED_LOCALE_SUPPORT
798 iTime_locale->month[aMonth] = (const char*) timeLocale;
799 iTime_locale->alt_month[aMonth] = (const char*) timeLocale;
800 timeLocale += strlen((char*) timeLocale) + 1;
802 const TText16* abbMonth = ((reinterpret_cast<TText*const*>((const TText*) iDataLanguage[FnMonthAbbTableV2]()))[aMonth]);
805 #ifdef SYMBIAN_OE_ENHANCED_LOCALE_SUPPORT
808 ConvertToMultiByteCustom((TUint8*)timeLocale, abbMonth);
813 ConvertToMultiByteL((TUint8*)timeLocale, abbMonth, charsetID);
814 #ifdef SYMBIAN_OE_ENHANCED_LOCALE_SUPPORT
817 iTime_locale->mon[aMonth] = (const char*) timeLocale;
818 timeLocale += strlen((char*) timeLocale) + 1;
823 //Set day and abbreviated day name information
824 const TText16* day = ((reinterpret_cast<TText*const*>((const TText*) iDataLanguage[FnDayTableV2]()))[6]);
827 #ifdef SYMBIAN_OE_ENHANCED_LOCALE_SUPPORT
830 ConvertToMultiByteCustom((TUint8*)timeLocale, day);
835 ConvertToMultiByteL((TUint8*)timeLocale, day, charsetID);
836 #ifdef SYMBIAN_OE_ENHANCED_LOCALE_SUPPORT
839 iTime_locale->weekday[0] = (const char*) timeLocale;
840 timeLocale += strlen((char*) timeLocale) + 1;
842 const TText16* abbDay = ((reinterpret_cast<TText*const*>((const TText*) iDataLanguage[FnDayAbbTableV2]()))[6]);
845 #ifdef SYMBIAN_OE_ENHANCED_LOCALE_SUPPORT
848 ConvertToMultiByteCustom((TUint8*)timeLocale, abbDay);
853 ConvertToMultiByteL((TUint8*)timeLocale, abbDay, charsetID);
854 #ifdef SYMBIAN_OE_ENHANCED_LOCALE_SUPPORT
857 iTime_locale->wday[0] = (const char*) timeLocale;
858 timeLocale += strlen((char*) timeLocale) + 1;
861 for(TInt aDay = 0 ; aDay < WEEKDAYS - 1; aDay++)
863 const TText16* day = ((reinterpret_cast<TText*const*>((const TText*) iDataLanguage[FnDayTableV2]()))[aDay]);
866 #ifdef SYMBIAN_OE_ENHANCED_LOCALE_SUPPORT
869 ConvertToMultiByteCustom((TUint8*)timeLocale, day);
874 ConvertToMultiByteL((TUint8*)timeLocale, day, charsetID);
875 #ifdef SYMBIAN_OE_ENHANCED_LOCALE_SUPPORT
878 iTime_locale->weekday[aDay + 1] = (const char*) timeLocale;
879 timeLocale += strlen((char*) timeLocale) + 1;
881 const TText16* abbDay = ((reinterpret_cast<TText*const*>((const TText*) iDataLanguage[FnDayAbbTableV2]()))[aDay]);
884 #ifdef SYMBIAN_OE_ENHANCED_LOCALE_SUPPORT
887 ConvertToMultiByteCustom((TUint8*)timeLocale, abbDay);
892 ConvertToMultiByteL((TUint8*)timeLocale, abbDay, charsetID);
893 #ifdef SYMBIAN_OE_ENHANCED_LOCALE_SUPPORT
896 iTime_locale->wday[aDay + 1] = (const char*) timeLocale;
897 timeLocale += strlen((char*) timeLocale) + 1;
901 const TText16* am = ((reinterpret_cast<TText*const*>((const TText*) iDataLanguage[FnAmPmTableV2]()))[0]);
904 #ifdef SYMBIAN_OE_ENHANCED_LOCALE_SUPPORT
907 ConvertToMultiByteCustom((TUint8*)timeLocale, am);
912 ConvertToMultiByteL((TUint8*)timeLocale, am, charsetID);
913 #ifdef SYMBIAN_OE_ENHANCED_LOCALE_SUPPORT
916 iTime_locale->am = (const char*) timeLocale;
917 timeLocale += strlen((char*) timeLocale) + 1;
919 const TText16* pm = ((reinterpret_cast<TText*const*>((const TText*) iDataLanguage[FnAmPmTableV2]()))[1]);
922 #ifdef SYMBIAN_OE_ENHANCED_LOCALE_SUPPORT
925 ConvertToMultiByteCustom((TUint8*)timeLocale, pm);
930 ConvertToMultiByteL((TUint8*)timeLocale, pm, charsetID);
931 #ifdef SYMBIAN_OE_ENHANCED_LOCALE_SUPPORT
934 iTime_locale->pm = (const char*) timeLocale;
935 timeLocale += strlen((char*) timeLocale) + 1;
938 Mem::Copy(&iLocaleTimeDateFormat.iTimeFormatSpec[0], (const TAny*) iDataRegion[FnTimeFormatSpecV2](), sizeof(TText) * (KMaxTimeFormatSpec+1));
939 TText* timeForm = iLocaleTimeDateFormat.iTimeFormatSpec;
941 //Set time format(T_FMT) and am/pm time format(T_FMT_AMPM) string
944 const TPtrC time(timeForm);
945 TBuf8<TIME_FORMAT_LENGTH> timeFormat;
946 timeFormat.Copy(time);
948 TChar timeSeparator = iLocale.TimeSeparator(1);
949 TBuf8<DECIMAL_THOUSAND_DATE_TIME_SEPARATOR> timeSeparator1;
950 timeSeparator1.Append(timeSeparator);
952 timeSeparator = iLocale.TimeSeparator(2);
953 TBuf8<DECIMAL_THOUSAND_DATE_TIME_SEPARATOR> timeSeparator2;
954 timeSeparator2.Append(timeSeparator);
956 TTimeFormat time12hror24hr = iLocale.TimeFormat();
958 if(KErrNotFound != timeFormat.Locate('J'))
960 //Check for time format(12/24 hour format)
961 if(time12hror24hr == ETime12)
963 strcpy((char*) timeLocale,TWELVE_HOUR_STR);
967 strcpy((char*) timeLocale,TWENTY_FOUR_HOUR_STR);
971 else if(KErrNotFound != timeFormat.Locate('I'))
973 strcpy((char*) timeLocale,TWELVE_HOUR_STR);
976 else if(KErrNotFound != timeFormat.Locate('H'))
978 strcpy((char*) timeLocale,TWENTY_FOUR_HOUR_STR);
981 strncat((char*) timeLocale, (char*) timeSeparator1.Ptr(), timeSeparator1.Length());
982 strcat((char*) timeLocale, MINUTE_STR);
983 strncat((char*) timeLocale, (char*) timeSeparator2.Ptr(), timeSeparator2.Length());
984 strcat((char*) timeLocale, SECOND_STR);
986 if(time12hror24hr == ETime12)
989 if((KErrNotFound != timeFormat.Find(KAMPMSpace12hr)) || (KErrNotFound != timeFormat.Find(KAMPMSpace)) )
991 if((KErrNotFound != timeFormat.Find(KAMPMNoSpace12hr)) || (KErrNotFound != timeFormat.Find(KAMPMNoSpace)))
993 strcat((char*) timeLocale, AMPM_NO_SPACE);
997 strcat((char*) timeLocale, AMPM_SPACE);
1002 iTime_locale->ampm_fmt = (const char*) timeLocale;
1003 iTime_locale->X_fmt = iTime_locale->ampm_fmt;
1004 timeLocale += strlen((char*) timeLocale) + 1;
1007 TDateFormat aDateFormat = iLocale.DateFormat();
1008 //Set date fromat string(D_FMT)
1009 TChar dateSeparator = iLocale.DateSeparator(1);
1010 TBuf8<DECIMAL_THOUSAND_DATE_TIME_SEPARATOR> dateSeparator1;
1011 dateSeparator1.Append(dateSeparator);
1013 TBuf8<DECIMAL_THOUSAND_DATE_TIME_SEPARATOR> dateSeparator2;
1014 dateSeparator = iLocale.DateSeparator(2);
1015 dateSeparator2.Append(dateSeparator);
1017 //Americal date formt(mm/dd/YYYY)
1018 if(EDateAmerican == aDateFormat)
1020 strcpy((char*) timeLocale, MONTH_STR);
1021 strncat((char*) timeLocale, (char*) dateSeparator1.Ptr(), dateSeparator1.Length());
1022 strcat((char*) timeLocale, DAY_STR);
1023 strncat((char*) timeLocale, (char*) dateSeparator2.Ptr(), dateSeparator2.Length());
1024 strcat((char*) timeLocale, YEAR_STR);
1025 iTime_locale->x_fmt = (const char*) timeLocale;
1028 //European date format(dd/mm/YYYY)
1029 if(EDateEuropean == aDateFormat)
1031 strcpy((char*) timeLocale, DAY_STR);
1032 strncat((char*) timeLocale, (char*) dateSeparator1.Ptr(), dateSeparator1.Length());
1033 strcat((char*) timeLocale, MONTH_STR);
1034 strncat((char*) timeLocale, (char*) dateSeparator2.Ptr(), dateSeparator2.Length());
1035 strcat((char*) timeLocale, YEAR_STR);
1036 iTime_locale->x_fmt = (const char*) timeLocale;
1039 //Japanese date format(YYYY/mm/dd)
1040 if(EDateJapanese == aDateFormat)
1042 strcpy((char*) timeLocale, YEAR_STR);
1043 strncat((char*) timeLocale, (char*) dateSeparator1.Ptr(), dateSeparator1.Length());
1044 strcat((char*) timeLocale, MONTH_STR);
1045 strncat((char*) timeLocale, (char*) dateSeparator2.Ptr(), dateSeparator2.Length());
1046 strcat((char*) timeLocale, DAY_STR);
1047 iTime_locale->x_fmt = (const char*) timeLocale;
1050 iTime_locale->md_order = iTime_locale->c_fmt = iTime_locale->date_fmt = (const char*) L"";
1052 timeLocale = startAddress;
1059 TInt CLocale::TimeLoadLocaleL(const char* localeName)
1061 #ifdef SYMBIAN_DISTINCT_LOCALE_MODEL
1063 if( ! iOldDllPresent)
1065 TInt ret = TimeLoadNewLocaleL( localeName ); // option 2 to load language and region dll both
1071 TText8* startAddress = timeLocale;
1072 #ifdef SYMBIAN_OE_ENHANCED_LOCALE_SUPPORT
1073 TInt charsetID = -1;
1076 charsetID = GetCharcaterSetIDL(localeName);
1083 TInt charsetID = GetCharcaterSetIDL(localeName);
1091 #ifdef SYMBIAN_OE_ENHANCED_LOCALE_SUPPORT
1097 //Set month and abbreviated month name information
1098 for(TInt aMonth = 0 ; aMonth < MONTHS; aMonth++)
1101 const TText16* month = ((reinterpret_cast<TText*const*>((const TText*) iData[FnMonthTable]()))[aMonth]);
1104 #ifdef SYMBIAN_OE_ENHANCED_LOCALE_SUPPORT
1107 ConvertToMultiByteCustom((TUint8*)timeLocale, month);
1112 ConvertToMultiByteL((TUint8*)timeLocale, month, charsetID);
1113 #ifdef SYMBIAN_OE_ENHANCED_LOCALE_SUPPORT
1116 iTime_locale->month[aMonth] = (const char*) timeLocale;
1117 iTime_locale->alt_month[aMonth] = (const char*) timeLocale;
1118 timeLocale += strlen((char*) timeLocale) + 1;
1121 const TText16* abbMonth = ((reinterpret_cast<TText*const*>((const TText*) iData[FnMonthAbbTable]()))[aMonth]);
1124 #ifdef SYMBIAN_OE_ENHANCED_LOCALE_SUPPORT
1127 ConvertToMultiByteCustom((TUint8*)timeLocale, abbMonth);
1132 ConvertToMultiByteL((TUint8*)timeLocale, abbMonth, charsetID);
1133 #ifdef SYMBIAN_OE_ENHANCED_LOCALE_SUPPORT
1136 iTime_locale->mon[aMonth] = (const char*) timeLocale;
1137 timeLocale += strlen((char*) timeLocale) + 1;
1142 //Set day and abbreviated day name information
1144 const TText16* day = ((reinterpret_cast<TText*const*>((const TText*) iData[FnDayTable]()))[6]);
1147 #ifdef SYMBIAN_OE_ENHANCED_LOCALE_SUPPORT
1150 ConvertToMultiByteCustom((TUint8*)timeLocale, day);
1155 ConvertToMultiByteL((TUint8*)timeLocale, day, charsetID);
1156 #ifdef SYMBIAN_OE_ENHANCED_LOCALE_SUPPORT
1159 iTime_locale->weekday[0] = (const char*) timeLocale;
1160 timeLocale += strlen((char*) timeLocale) + 1;
1164 const TText16* abbDay = ((reinterpret_cast<TText*const*>((const TText*) iData[FnDayAbbTable]()))[6]);
1167 #ifdef SYMBIAN_OE_ENHANCED_LOCALE_SUPPORT
1170 ConvertToMultiByteCustom((TUint8*)timeLocale, abbDay);
1176 ConvertToMultiByteL((TUint8*)timeLocale, abbDay, charsetID);
1177 #ifdef SYMBIAN_OE_ENHANCED_LOCALE_SUPPORT
1180 iTime_locale->wday[0] = (const char*) timeLocale;
1181 timeLocale += strlen((char*) timeLocale) + 1;
1184 for(TInt aDay = 0 ; aDay < WEEKDAYS - 1; aDay++)
1187 const TText16* day = ((reinterpret_cast<TText*const*>((const TText*) iData[FnDayTable]()))[aDay]);
1190 #ifdef SYMBIAN_OE_ENHANCED_LOCALE_SUPPORT
1193 ConvertToMultiByteCustom((TUint8*)timeLocale, day);
1198 ConvertToMultiByteL((TUint8*)timeLocale, day, charsetID);
1199 #ifdef SYMBIAN_OE_ENHANCED_LOCALE_SUPPORT
1202 iTime_locale->weekday[aDay + 1] = (const char*) timeLocale;
1203 timeLocale += strlen((char*) timeLocale) + 1;
1207 const TText16* abbDay = ((reinterpret_cast<TText*const*>((const TText*) iData[FnDayAbbTable]()))[aDay]);
1210 #ifdef SYMBIAN_OE_ENHANCED_LOCALE_SUPPORT
1213 ConvertToMultiByteCustom((TUint8*)timeLocale, abbDay);
1218 ConvertToMultiByteL((TUint8*)timeLocale, abbDay, charsetID);
1219 #ifdef SYMBIAN_OE_ENHANCED_LOCALE_SUPPORT
1222 iTime_locale->wday[aDay + 1] = (const char*) timeLocale;
1223 timeLocale += strlen((char*) timeLocale) + 1;
1230 const TText16* am = ((reinterpret_cast<TText*const*>((const TText*) iData[FnAmPmTable]()))[0]);
1233 #ifdef SYMBIAN_OE_ENHANCED_LOCALE_SUPPORT
1236 ConvertToMultiByteCustom((TUint8*)timeLocale, am);
1241 ConvertToMultiByteL((TUint8*)timeLocale, am, charsetID);
1242 #ifdef SYMBIAN_OE_ENHANCED_LOCALE_SUPPORT
1245 iTime_locale->am = (const char*) timeLocale;
1246 timeLocale += strlen((char*) timeLocale) + 1;
1251 const TText16* pm = ((reinterpret_cast<TText*const*>((const TText*) iData[FnAmPmTable]()))[1]);
1254 #ifdef SYMBIAN_OE_ENHANCED_LOCALE_SUPPORT
1257 ConvertToMultiByteCustom((TUint8*)timeLocale, pm);
1262 ConvertToMultiByteL((TUint8*)timeLocale, pm, charsetID);
1263 #ifdef SYMBIAN_OE_ENHANCED_LOCALE_SUPPORT
1266 iTime_locale->pm = (const char*) timeLocale;
1267 timeLocale += strlen((char*) timeLocale) + 1;
1271 Mem::Copy(&iLocaleTimeDateFormat.iTimeFormatSpec[0], (const TAny*) iData[FnTimeFormatSpec](), sizeof(TText) * (KMaxTimeFormatSpec+1));
1272 TText* timeForm = iLocaleTimeDateFormat.iTimeFormatSpec;
1274 //Set time format(T_FMT) and am/pm time format(T_FMT_AMPM) string
1277 const TPtrC time(timeForm);
1278 TBuf8<TIME_FORMAT_LENGTH> timeFormat;
1279 timeFormat.Copy(time);
1281 TChar timeSeparator = iLocale.TimeSeparator(1);
1282 TBuf8<DECIMAL_THOUSAND_DATE_TIME_SEPARATOR> timeSeparator1;
1283 timeSeparator1.Append(timeSeparator);
1285 timeSeparator = iLocale.TimeSeparator(2);
1286 TBuf8<DECIMAL_THOUSAND_DATE_TIME_SEPARATOR> timeSeparator2;
1287 timeSeparator2.Append(timeSeparator);
1289 TTimeFormat time12hror24hr = iLocale.TimeFormat();
1291 if(KErrNotFound != timeFormat.Locate('J'))
1293 //Check for time format(12/24 hour format)
1294 if(time12hror24hr == ETime12)
1296 strcpy((char*) timeLocale,TWELVE_HOUR_STR);
1300 strcpy((char*) timeLocale,TWENTY_FOUR_HOUR_STR);
1304 else if(KErrNotFound != timeFormat.Locate('I'))
1306 strcpy((char*) timeLocale,TWELVE_HOUR_STR);
1309 else if(KErrNotFound != timeFormat.Locate('H'))
1311 strcpy((char*) timeLocale,TWENTY_FOUR_HOUR_STR);
1314 strncat((char*) timeLocale, (char*) timeSeparator1.Ptr(), timeSeparator1.Length());
1315 strcat((char*) timeLocale, MINUTE_STR);
1316 strncat((char*) timeLocale, (char*) timeSeparator2.Ptr(), timeSeparator2.Length());
1317 strcat((char*) timeLocale, SECOND_STR);
1319 if(time12hror24hr == ETime12)
1322 if((KErrNotFound != timeFormat.Find(KAMPMSpace12hr)) || (KErrNotFound != timeFormat.Find(KAMPMSpace)) )
1324 if((KErrNotFound != timeFormat.Find(KAMPMNoSpace12hr)) || (KErrNotFound != timeFormat.Find(KAMPMNoSpace)))
1326 strcat((char*) timeLocale, AMPM_NO_SPACE);
1330 strcat((char*) timeLocale, AMPM_SPACE);
1335 iTime_locale->ampm_fmt = (const char*) timeLocale;
1336 iTime_locale->X_fmt = iTime_locale->ampm_fmt;
1337 timeLocale += strlen((char*) timeLocale) + 1;
1340 TDateFormat aDateFormat = iLocale.DateFormat();
1341 //Set date fromat string(D_FMT)
1342 TChar dateSeparator = iLocale.DateSeparator(1);
1343 TBuf8<DECIMAL_THOUSAND_DATE_TIME_SEPARATOR> dateSeparator1;
1344 dateSeparator1.Append(dateSeparator);
1346 TBuf8<DECIMAL_THOUSAND_DATE_TIME_SEPARATOR> dateSeparator2;
1347 dateSeparator = iLocale.DateSeparator(2);
1348 dateSeparator2.Append(dateSeparator);
1350 //Americal date formt(mm/dd/YYYY)
1351 if(EDateAmerican == aDateFormat)
1353 strcpy((char*) timeLocale, MONTH_STR);
1354 strncat((char*) timeLocale, (char*) dateSeparator1.Ptr(), dateSeparator1.Length());
1355 strcat((char*) timeLocale, DAY_STR);
1356 strncat((char*) timeLocale, (char*) dateSeparator2.Ptr(), dateSeparator2.Length());
1357 strcat((char*) timeLocale, YEAR_STR);
1358 iTime_locale->x_fmt = (const char*) timeLocale;
1361 //European date format(dd/mm/YYYY)
1362 if(EDateEuropean == aDateFormat)
1364 strcpy((char*) timeLocale, DAY_STR);
1365 strncat((char*) timeLocale, (char*) dateSeparator1.Ptr(), dateSeparator1.Length());
1366 strcat((char*) timeLocale, MONTH_STR);
1367 strncat((char*) timeLocale, (char*) dateSeparator2.Ptr(), dateSeparator2.Length());
1368 strcat((char*) timeLocale, YEAR_STR);
1369 iTime_locale->x_fmt = (const char*) timeLocale;
1372 //Japanese date format(YYYY/mm/dd)
1373 if(EDateJapanese == aDateFormat)
1375 strcpy((char*) timeLocale, YEAR_STR);
1376 strncat((char*) timeLocale, (char*) dateSeparator1.Ptr(), dateSeparator1.Length());
1377 strcat((char*) timeLocale, MONTH_STR);
1378 strncat((char*) timeLocale, (char*) dateSeparator2.Ptr(), dateSeparator2.Length());
1379 strcat((char*) timeLocale, DAY_STR);
1380 iTime_locale->x_fmt = (const char*) timeLocale;
1383 iTime_locale->md_order = iTime_locale->c_fmt = iTime_locale->date_fmt = (const char*) L"";
1385 timeLocale = startAddress;
1390 struct lc_numeric_T* CLocale::GetCurrentNumericLocale(void)
1393 if(NULL != iNumeric_locale)
1395 return iNumeric_locale;
1401 struct lc_monetary_T* CLocale::GetCurrentMonetaryLocale(void)
1403 if(NULL != iMonetary_locale)
1405 return iMonetary_locale;
1410 struct lc_time_T* CLocale::GetCurrentTimeLocale(void)
1412 if(NULL != iTime_locale)
1414 return iTime_locale;
1421 TInt CLocale::LoadLocale(TDesC& aLocale)
1424 TBuf8<LOCALE_LENGTH> locale_name;
1425 locale_name.Copy(src);
1426 char locale[LOCALE_LENGTH];
1427 strncpy(locale, (char*) locale_name.Ptr(), locale_name.Length());
1428 locale[locale_name.Length()] = '\0';
1430 if (NULL == strchr(locale, '.'))
1435 // Open the file locale mapping(mapping of POSIX locale string to language variant DLL number) file
1439 _LIT(localeFile, "\\resource\\openc\\locales.txt");
1441 TFileName localeFile;
1442 GetInstallationDataDir(localeFile);
1443 localeFile.Append(_L("locales.txt"));
1446 int retVal = file.Open(Backend()->FileSession(), localeFile, EFileRead);
1447 if(KErrNone != retVal)
1453 TBuf8<LOCALE_LENGTH> localeInfo;
1454 retVal = ReadALine(file, pos, localeInfo);
1455 char* buffer = (char*) localeInfo.Ptr();
1457 //Check whether locale is supported or not
1462 char str[LOCALE_LENGTH];
1463 while(buffer[i] != '=')
1469 if(!strcmp(str,locale))
1475 retVal = ReadALine(file, pos, localeInfo);
1476 buffer = (char*) localeInfo.Ptr();
1480 DllName.Copy(KDllName);
1481 DllName.Append('.');
1483 int len = localeInfo.Length();
1486 DllName.Append(buffer[i]);
1499 TInt CLocale::ConvertToMultiByteL(TUint8* aNarrowCharString, const TText16* aWideCharString, TInt aCharsetUID)
1501 //Create a handle to a file server session and connect to the file server.
1502 //Push it on to cleanup stack
1504 User::LeaveIfError(fileSession.Connect());
1505 CleanupClosePushL(fileSession);
1507 //Allocate and constructs a CCnvCharacterSetConverter object
1508 CCnvCharacterSetConverter* conv = CCnvCharacterSetConverter::NewLC();
1510 //Search the character set array containing all of the character sets for which conversion is available
1511 CCnvCharacterSetConverter::TAvailability avail = conv->PrepareToConvertToOrFromL(aCharsetUID, fileSession);
1512 if(CCnvCharacterSetConverter::ENotAvailable == avail)
1514 CleanupStack::PopAndDestroy(2);
1515 *aNarrowCharString = '\0';
1519 const TPtrC16 unicodeText(aWideCharString);
1520 TBuf8<NON_UNICODE_TEXT_BUFFER_LENGTH> nativeText;
1522 TInt retVal = KErrNone;
1523 TInt aNumberOfUnconvertibleCharacters = 0;
1524 TInt aIndexOfFirstByteOfFirstUnconvertibleCharacter = 0;
1526 //Convert text encoded in the Unicode character set (UCS-2) into other character sets
1527 retVal = conv->ConvertFromUnicode(nativeText,unicodeText, aNumberOfUnconvertibleCharacters, aIndexOfFirstByteOfFirstUnconvertibleCharacter);
1528 TInt returnCode = 0;
1529 //Check for illegal characters in the input
1530 if(retVal == CCnvCharacterSetConverter::EErrorIllFormedInput)
1532 *aNarrowCharString = '\0';
1536 //Check for incomplete characters in the input, set the errno accordingly
1537 else if(aNumberOfUnconvertibleCharacters)
1539 *aNarrowCharString = '\0';
1544 strncpy((char*) aNarrowCharString, (char*) nativeText.Ptr(), nativeText.Length());
1545 aNarrowCharString[nativeText.Length()] = '\0';
1548 CleanupStack::PopAndDestroy(2); // conv, fileSession
1553 TInt CLocale::GetCharcaterSetIDL(const char* aLocaleName)
1555 //extract the charcate set name from locale string
1556 char* temp = strchr(aLocaleName, '.');
1557 char locale[LOCALE_LENGTH];
1564 while((*temp != '@') && *temp != '\0')
1566 locale[j++] = *temp++;
1570 //Create a handle to a file server session and connect to the file server.
1571 //Push it on to cleanup stack
1573 User::LeaveIfError(fileSession.Connect());
1574 CleanupClosePushL(fileSession);
1576 TInt characterSetUID = 0;
1578 //Allocate and constructs a CCnvCharacterSetConverter object
1579 CCnvCharacterSetConverter* conv = CCnvCharacterSetConverter::NewLC() ;
1581 //Create an array identifying all the character sets for which conversion is available
1582 CArrayFix<CCnvCharacterSetConverter::SCharacterSet> *charSet = CCnvCharacterSetConverter::CreateArrayOfCharacterSetsAvailableL(fileSession);
1583 CleanupStack::PushL( charSet );
1586 //Get the number of character sets for which conversion is available
1587 TInt count = charSet->Count();
1590 CCnvCharacterSetConverter::SCharacterSet characterSet = charSet->At(i);
1592 //Get the UID of character set for which conversion is available
1593 TUint charSetUID = characterSet.Identifier();
1595 const TBufC<CHARACTER_SET_NAME> charSetName = characterSet.NameIsFileName()?TParsePtrC(characterSet.Name()).Name():characterSet.Name();
1596 TBuf8<CHARACTER_SET_NAME> aCharSetname;
1597 aCharSetname.Copy(charSetName);
1599 //Assign the character set UID
1600 if(!aCharSetname.Compare(TPtrC8((const TText8*) locale)))
1602 characterSetUID = charSetUID;
1606 HBufC8* stdInterName = conv->ConvertCharacterSetIdentifierToStandardNameL(charSetUID, fileSession);
1607 if(NULL != stdInterName)
1609 if(!stdInterName->Compare(TPtrC8((const TText8*) locale)))
1611 characterSetUID = charSetUID;
1612 delete stdInterName;
1613 stdInterName = NULL;
1616 delete stdInterName;
1617 stdInterName = NULL;
1621 if(!characterSetUID)
1623 characterSetUID = -1;
1626 CleanupStack::PopAndDestroy(3); //charSet, conv, fileSession
1627 return characterSetUID;
1630 /* ReadALine : Reads one line at a time from specified file */
1631 inline TInt ReadALine(RFile& aFile, TInt& aPos, TDes8& aDesc)
1633 TInt ret = aFile.Read(aPos, aDesc);
1634 TChar delimOne = '\r';
1635 TChar delimTwo = '\n';
1637 TInt len = aDesc.Length();
1640 //Always assumes that each line will end with "\r\n" except the last line
1641 TInt pos = aDesc.Locate(delimOne);
1642 pos = aDesc.Locate(delimTwo);
1644 if(KErrNotFound != pos)
1646 aPos = aPos + pos + 1;
1648 aDesc.SetLength(len);
1657 #ifdef SYMBIAN_OE_ENHANCED_LOCALE_SUPPORT
1659 void CLocale::ConvertToMultiByteCustom(TUint8* aNarrowCharString, const TText16* aWideCharString)
1661 const TPtrC unicodeText(aWideCharString);
1662 TBuf8<NON_UNICODE_TEXT_BUFFER_LENGTH> nativeText;
1663 nativeText.Copy(unicodeText);
1664 strncpy((char*) aNarrowCharString, (char*) nativeText.Ptr(), nativeText.Length());
1665 aNarrowCharString[nativeText.Length()] = '\0';
1668 TInt CLocale::SyncLocale(TLocaleAspect aspect)
1670 #ifdef SYMBIAN_DISTINCT_LOCALE_MODEL
1671 TBuf<NON_UNICODE_TEXT_BUFFER_LENGTH> reg_dllname;
1673 TBuf<NON_UNICODE_TEXT_BUFFER_LENGTH> Kdname;
1674 TExtendedLocale locale;
1675 locale.LoadSystemSettings();
1676 locale.GetLocaleDllName(aspect,Kdname);
1677 #ifdef SYMBIAN_DISTINCT_LOCALE_MODEL
1678 // check if the new dlls is present then load it or go for old dll
1679 if( Kdname.FindC(_L("elocl.")) == KErrNotFound )
1682 locale.GetLocaleDllName(ELocaleTimeDateSettings,reg_dllname);
1683 return (GetSystemLocale(Kdname,reg_dllname ));
1688 return (GetSystemLocale(Kdname));
1691 const TText* CLocale::GetLocaleName(void)
1693 TPtrC dllname(DllName);
1694 return dllname.Ptr();
1698 #ifdef SYMBIAN_DISTINCT_LOCALE_MODEL
1700 const TText* CLocale::GetCollateLocaleName(void)
1702 TPtrC dllname(ColDllName);
1703 return dllname.Ptr();
1708 #endif // SYMBIAN_OE_ENHANCED_LOCALE_SUPPORT