|
1 // Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
2 // All rights reserved. |
|
3 // This component and the accompanying materials are made available |
|
4 // under the terms of "Eclipse Public License v1.0" |
|
5 // which accompanies this distribution, and is available |
|
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // Name : lnumeric.CPP |
|
15 // Part of : LIBC |
|
16 // Contains the source for LC_NUMERIC category |
|
17 // Version : |
|
18 // This material, including documentation and any related |
|
19 // computer programs, is protected by copyright controlled by |
|
20 // Nokia Corporation. All rights are reserved. Copying, |
|
21 // including reproducing, storing, adapting or translating, any |
|
22 // or all of this material requires the prior written consent of |
|
23 // Nokia Corporation. This material also contains confidential |
|
24 // information which may not be disclosed to others without the |
|
25 // prior written consent of Nokia Corporation. |
|
26 // |
|
27 |
|
28 #include <limits.h> |
|
29 #include <sys/cdefs.h> |
|
30 #include "localeinfo.h" |
|
31 #include "lnumeric.h" |
|
32 |
|
33 #if (defined(__SYMBIAN32__) && (defined(__WINSCW__) || defined(__WINS__))) |
|
34 #include "libc_wsd_defs.h" |
|
35 #endif |
|
36 __BEGIN_DECLS |
|
37 extern int __nlocale_changed; |
|
38 #ifdef EMULATOR |
|
39 int *GET_WSD_VAR_NAME(__nlocale_changed, g)(); |
|
40 #define __nlocale_changed (*GET_WSD_VAR_NAME(__nlocale_changed, g)()) |
|
41 #endif //EMULATOR |
|
42 __END_DECLS |
|
43 |
|
44 #ifdef SYMBIAN_OE_ENHANCED_LOCALE_SUPPORT |
|
45 extern unsigned char __clocale_set; |
|
46 #ifdef EMULATOR |
|
47 unsigned char *GET_WSD_VAR_NAME(__clocale_set, g)(); |
|
48 #define __clocale_set (*GET_WSD_VAR_NAME(__clocale_set, g)()) |
|
49 #endif //EMULATOR |
|
50 #endif |
|
51 #ifndef EMULATOR |
|
52 int _numeric_using_locale; |
|
53 #else //EMULATOR |
|
54 |
|
55 GET_GLOBAL_VAR_FROM_TLS(_numeric_using_locale, int) |
|
56 #define _numeric_using_locale (*GET_WSD_VAR_NAME(_numeric_using_locale, g)()) |
|
57 #endif //EMULATOR |
|
58 |
|
59 #ifndef EMULATOR |
|
60 static char numempty[] = { CHAR_MAX, '\0' }; |
|
61 #else //EMULATOR |
|
62 static const char numempty[] = { CHAR_MAX, '\0'}; |
|
63 #endif //EMULATOR |
|
64 |
|
65 |
|
66 static const struct lc_numeric_T _C_numeric_locale = { |
|
67 ".", /* decimal_point */ |
|
68 "", /* thousands_sep */ |
|
69 numempty /* grouping */ |
|
70 }; |
|
71 |
|
72 |
|
73 int __numeric_load_locale(const char* localeName) |
|
74 { |
|
75 //Get an instance of locale object |
|
76 CLocale* locale = CLocale::GetInstance(); |
|
77 //Load numeric(LC_NUMERIC category) information |
|
78 if (locale->NumericLoadLocale(localeName) == -1) |
|
79 { |
|
80 return -1; |
|
81 } |
|
82 __nlocale_changed = 1; |
|
83 _numeric_using_locale = 1; |
|
84 |
|
85 return 0; |
|
86 } |
|
87 |
|
88 struct lc_numeric_T* __get_current_numeric_locale(void) |
|
89 { |
|
90 //Retrieve numeric(LC_NUMERIC category) information |
|
91 if(_numeric_using_locale) |
|
92 { |
|
93 return (CLocale::GetCurrentNumericLocale()); |
|
94 } |
|
95 #ifdef SYMBIAN_OE_ENHANCED_LOCALE_SUPPORT |
|
96 else if(__clocale_set) |
|
97 #endif |
|
98 //retrieve POSIX locale numeric(LC_NUMERIC category) information |
|
99 return ((struct lc_numeric_T *)&_C_numeric_locale); |
|
100 #ifdef SYMBIAN_OE_ENHANCED_LOCALE_SUPPORT |
|
101 else |
|
102 { |
|
103 CLocale *l=CLocale::GetInstance(); |
|
104 l->NumericLoadLocale(NULL); |
|
105 return (CLocale::GetCurrentNumericLocale()); |
|
106 } |
|
107 #endif |
|
108 } |
|
109 |
|
110 #ifdef LOCALE_DEBUG |
|
111 void |
|
112 numericdebug(void) { |
|
113 printf( "decimal_point = %s\n" |
|
114 "thousands_sep = %s\n" |
|
115 "grouping = %s\n", |
|
116 _numeric_locale.decimal_point, |
|
117 _numeric_locale.thousands_sep, |
|
118 _numeric_locale.grouping |
|
119 ); |
|
120 } |
|
121 #endif /* LOCALE_DEBUG */ |