Mercurial > projects > dwt-addons
comparison dwtx/dwtxhelper/mangoicu/ULocale.d @ 89:040da1cb0d76
Add a local copy of the mango ICU binding to work out the utf8 usability. Will hopefully go back into mango.
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Sun, 22 Jun 2008 22:57:31 +0200 |
parents | |
children | 11e8159caf7a |
comparison
equal
deleted
inserted
replaced
88:cd18fa3b71f1 | 89:040da1cb0d76 |
---|---|
1 /******************************************************************************* | |
2 | |
3 @file ULocale.d | |
4 | |
5 Copyright (c) 2004 Kris Bell | |
6 | |
7 This software is provided 'as-is', without any express or implied | |
8 warranty. In no event will the authors be held liable for damages | |
9 of any kind arising from the use of this software. | |
10 | |
11 Permission is hereby granted to anyone to use this software for any | |
12 purpose, including commercial applications, and to alter it and/or | |
13 redistribute it freely, subject to the following restrictions: | |
14 | |
15 1. The origin of this software must not be misrepresented; you must | |
16 not claim that you wrote the original software. If you use this | |
17 software in a product, an acknowledgment within documentation of | |
18 said product would be appreciated but is not required. | |
19 | |
20 2. Altered source versions must be plainly marked as such, and must | |
21 not be misrepresented as being the original software. | |
22 | |
23 3. This notice may not be removed or altered from any distribution | |
24 of the source. | |
25 | |
26 4. Derivative works are permitted, but they must carry this notice | |
27 in full and credit the original source. | |
28 | |
29 | |
30 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | |
31 | |
32 | |
33 @version Initial version, October 2004 | |
34 @author Kris | |
35 | |
36 Note that this package and documentation is built around the ICU | |
37 project (http://oss.software.ibm.com/icu/). Below is the license | |
38 statement as specified by that software: | |
39 | |
40 | |
41 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | |
42 | |
43 | |
44 ICU License - ICU 1.8.1 and later | |
45 | |
46 COPYRIGHT AND PERMISSION NOTICE | |
47 | |
48 Copyright (c) 1995-2003 International Business Machines Corporation and | |
49 others. | |
50 | |
51 All rights reserved. | |
52 | |
53 Permission is hereby granted, free of charge, to any person obtaining a | |
54 copy of this software and associated documentation files (the | |
55 "Software"), to deal in the Software without restriction, including | |
56 without limitation the rights to use, copy, modify, merge, publish, | |
57 distribute, and/or sell copies of the Software, and to permit persons | |
58 to whom the Software is furnished to do so, provided that the above | |
59 copyright notice(s) and this permission notice appear in all copies of | |
60 the Software and that both the above copyright notice(s) and this | |
61 permission notice appear in supporting documentation. | |
62 | |
63 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS | |
64 OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | |
65 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT | |
66 OF THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR | |
67 HOLDERS INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL | |
68 INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING | |
69 FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, | |
70 NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION | |
71 WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | |
72 | |
73 Except as contained in this notice, the name of a copyright holder | |
74 shall not be used in advertising or otherwise to promote the sale, use | |
75 or other dealings in this Software without prior written authorization | |
76 of the copyright holder. | |
77 | |
78 ---------------------------------------------------------------------- | |
79 | |
80 All trademarks and registered trademarks mentioned herein are the | |
81 property of their respective owners. | |
82 | |
83 *******************************************************************************/ | |
84 | |
85 module dwtx.dwthelper.mangoicu.ULocale; | |
86 | |
87 private import dwtx.dwthelper.mangoicu.ICU; | |
88 | |
89 /******************************************************************************* | |
90 | |
91 Note that this is a struct rather than a class. This is so | |
92 that one can easily construct these on the stack, plus the | |
93 'convenience' instances can be created statically. | |
94 | |
95 *******************************************************************************/ | |
96 | |
97 struct ULocale | |
98 { | |
99 public char[] name; | |
100 | |
101 /*********************************************************************** | |
102 | |
103 ***********************************************************************/ | |
104 | |
105 public static ULocale Root = {""}; | |
106 public static ULocale Default = {null}; | |
107 public static ULocale English = {"en"}; | |
108 public static ULocale Chinese = {"zh"}; | |
109 public static ULocale French = {"fr"}; | |
110 public static ULocale German = {"de"}; | |
111 public static ULocale Italian = {"it"}; | |
112 public static ULocale Japanese = {"ja"}; | |
113 public static ULocale Korean = {"ko"}; | |
114 public static ULocale SimplifiedChinese = {"zh_CN"}; | |
115 public static ULocale TraditionalChinese = {"zh_TW"}; | |
116 public static ULocale Canada = {"en_CA"}; | |
117 public static ULocale CanadaFrench = {"fr_CA"}; | |
118 public static ULocale China = {"zh_CN"}; | |
119 public static ULocale PRC = {"zh_CN"}; | |
120 public static ULocale France = {"fr_FR"}; | |
121 public static ULocale Germany = {"de_DE"}; | |
122 public static ULocale Italy = {"it_IT"}; | |
123 public static ULocale Japan = {"jp_JP"}; | |
124 public static ULocale Korea = {"ko_KR"}; | |
125 public static ULocale Taiwan = {"zh_TW"}; | |
126 public static ULocale UK = {"en_GB"}; | |
127 public static ULocale US = {"en_US"}; | |
128 | |
129 /*********************************************************************** | |
130 | |
131 ***********************************************************************/ | |
132 | |
133 public enum Type | |
134 { | |
135 Actual = 0, | |
136 Valid = 1, | |
137 Requested = 2, | |
138 } | |
139 | |
140 /*********************************************************************** | |
141 | |
142 ***********************************************************************/ | |
143 | |
144 public const uint LanguageCapacity = 12; | |
145 public const uint CountryCapacity = 4; | |
146 public const uint FullNameCapacity = 56; | |
147 public const uint ScriptCapacity = 6; | |
148 public const uint KeywordsCapacity = 50; | |
149 public const uint KeywordAndValuesCapacity = 100; | |
150 public const char KeywordItemSeparator = ':'; | |
151 public const char KeywordSeparator = '@'; | |
152 public const char KeywordAssign = '='; | |
153 | |
154 | |
155 /*********************************************************************** | |
156 | |
157 ***********************************************************************/ | |
158 | |
159 static void getDefault (inout ULocale locale) | |
160 { | |
161 locale.name = ICU.toArray (uloc_getDefault()); | |
162 if (! locale.name) | |
163 ICU.exception ("failed to get default locale"); | |
164 } | |
165 | |
166 /*********************************************************************** | |
167 | |
168 ***********************************************************************/ | |
169 | |
170 static void setDefault (inout ULocale locale) | |
171 { | |
172 ICU.Error e; | |
173 | |
174 uloc_setDefault (ICU.toString(locale.name), e); | |
175 | |
176 if (ICU.isError (e)) | |
177 ICU.exception ("invalid locale '"~locale.name~"'"); | |
178 } | |
179 | |
180 | |
181 | |
182 /*********************************************************************** | |
183 | |
184 Bind the ICU functions from a shared library. This is | |
185 complicated by the issues regarding D and DLLs on the | |
186 Windows platform | |
187 | |
188 ***********************************************************************/ | |
189 | |
190 private static void* library; | |
191 | |
192 /*********************************************************************** | |
193 | |
194 ***********************************************************************/ | |
195 | |
196 private static extern (C) | |
197 { | |
198 char* function () uloc_getDefault; | |
199 void function (char*, inout ICU.Error) uloc_setDefault; | |
200 } | |
201 | |
202 /********************************************************************** | |
203 | |
204 ***********************************************************************/ | |
205 | |
206 static FunctionLoader.Bind[] targets = | |
207 [ | |
208 {cast(void**) &uloc_getDefault, "uloc_getDefault"}, | |
209 {cast(void**) &uloc_setDefault, "uloc_setDefault"}, | |
210 ]; | |
211 | |
212 /*********************************************************************** | |
213 | |
214 ***********************************************************************/ | |
215 | |
216 static this () | |
217 { | |
218 library = FunctionLoader.bind (ICU.icuuc, targets); | |
219 } | |
220 | |
221 /*********************************************************************** | |
222 | |
223 ***********************************************************************/ | |
224 | |
225 static ~this () | |
226 { | |
227 FunctionLoader.unbind (library); | |
228 } | |
229 } |