Mercurial > projects > dstep
comparison dstep/foundation/NSLocale.d @ 16:19885b43130e
Huge update, the bridge actually works now
author | Jacob Carlborg <doob@me.com> |
---|---|
date | Sun, 03 Jan 2010 22:06:11 +0100 |
parents | 89f3c3ef1fd2 |
children | b9de51448c6b |
comparison
equal
deleted
inserted
replaced
15:7ff919f595d5 | 16:19885b43130e |
---|---|
5 * License: $(LINK2 http://www.boost.org/LICENSE_1_0.txt, Boost Software License 1.0) | 5 * License: $(LINK2 http://www.boost.org/LICENSE_1_0.txt, Boost Software License 1.0) |
6 */ | 6 */ |
7 module dstep.foundation.NSLocale; | 7 module dstep.foundation.NSLocale; |
8 | 8 |
9 import dstep.foundation.NSArray; | 9 import dstep.foundation.NSArray; |
10 import dstep.foundation.NSCoder; | |
10 import dstep.foundation.NSDictionary; | 11 import dstep.foundation.NSDictionary; |
11 import dstep.foundation.NSObject; | 12 import dstep.foundation.NSObject; |
12 import dstep.foundation.NSString; | 13 import dstep.foundation.NSString; |
14 import dstep.foundation.NSZone; | |
13 import dstep.objc.bridge.Bridge; | 15 import dstep.objc.bridge.Bridge; |
14 import dstep.objc.objc : id; | 16 import dstep.objc.objc; |
17 | |
18 | |
15 | 19 |
16 import bindings = dstep.foundation.NSLocale_bindings; | 20 import bindings = dstep.foundation.NSLocale_bindings; |
17 | 21 |
18 const NSString NSCurrentLocaleDidChangeNotification; | 22 private |
19 const NSString NSLocaleIdentifier; | 23 { |
20 const NSString NSLocaleLanguageCode; | 24 NSString NSCurrentLocaleDidChangeNotification_; |
21 const NSString NSLocaleCountryCode; | 25 NSString NSLocaleIdentifier_; |
22 const NSString NSLocaleScriptCode; | 26 NSString NSLocaleLanguageCode_; |
23 const NSString NSLocaleVariantCode; | 27 NSString NSLocaleCountryCode_; |
24 const NSString NSLocaleExemplarCharacterSet; | 28 NSString NSLocaleScriptCode_; |
25 const NSString NSLocaleCalendar; | 29 NSString NSLocaleVariantCode_; |
26 const NSString NSLocaleCollationIdentifier; | 30 NSString NSLocaleExemplarCharacterSet_; |
27 const NSString NSLocaleUsesMetricSystem; | 31 NSString NSLocaleCalendar_; |
28 const NSString NSLocaleMeasurementSystem; | 32 NSString NSLocaleCollationIdentifier_; |
29 const NSString NSLocaleDecimalSeparator; | 33 NSString NSLocaleUsesMetricSystem_; |
30 const NSString NSLocaleGroupingSeparator; | 34 NSString NSLocaleMeasurementSystem_; |
31 const NSString NSLocaleCurrencySymbol; | 35 NSString NSLocaleDecimalSeparator_; |
32 const NSString NSLocaleCurrencyCode; | 36 NSString NSLocaleGroupingSeparator_; |
33 const NSString NSGregorianCalendar; | 37 NSString NSLocaleCurrencySymbol_; |
34 const NSString NSBuddhistCalendar; | 38 NSString NSLocaleCurrencyCode_; |
35 const NSString NSChineseCalendar; | 39 NSString NSGregorianCalendar_; |
36 const NSString NSHebrewCalendar; | 40 NSString NSBuddhistCalendar_; |
37 const NSString NSIslamicCalendar; | 41 NSString NSChineseCalendar_; |
38 const NSString NSIslamicCivilCalendar; | 42 NSString NSHebrewCalendar_; |
39 const NSString NSJapaneseCalendar; | 43 NSString NSIslamicCalendar_; |
40 | 44 NSString NSIslamicCivilCalendar_; |
41 static this () | 45 NSString NSJapaneseCalendar_; |
42 { | 46 } |
43 NSCurrentLocaleDidChangeNotification = new NSString(bindings.NSCurrentLocaleDidChangeNotification); | 47 |
44 NSLocaleIdentifier = new NSString(bindings.NSLocaleIdentifier); | 48 NSString NSCurrentLocaleDidChangeNotification () |
45 NSLocaleLanguageCode = new NSString(bindings.NSLocaleLanguageCode); | 49 { |
46 NSLocaleCountryCode = new NSString(bindings.NSLocaleCountryCode); | 50 if (NSCurrentLocaleDidChangeNotification_) |
47 NSLocaleScriptCode = new NSString(bindings.NSLocaleScriptCode); | 51 return NSCurrentLocaleDidChangeNotification_; |
48 NSLocaleVariantCode = new NSString(bindings.NSLocaleVariantCode); | 52 |
49 NSLocaleExemplarCharacterSet = new NSString(bindings.NSLocaleExemplarCharacterSet); | 53 return NSCurrentLocaleDidChangeNotification_ = new NSString(bindings.NSCurrentLocaleDidChangeNotification); |
50 NSLocaleCalendar = new NSString(bindings.NSLocaleCalendar); | 54 } |
51 NSLocaleCollationIdentifier = new NSString(bindings.NSLocaleCollationIdentifier); | 55 |
52 NSLocaleUsesMetricSystem = new NSString(bindings.NSLocaleUsesMetricSystem); | 56 NSString NSLocaleIdentifier () |
53 NSLocaleMeasurementSystem = new NSString(bindings.NSLocaleMeasurementSystem); | 57 { |
54 NSLocaleDecimalSeparator = new NSString(bindings.NSLocaleDecimalSeparator); | 58 if (NSLocaleIdentifier_) |
55 NSLocaleGroupingSeparator = new NSString(bindings.NSLocaleGroupingSeparator); | 59 return NSLocaleIdentifier_; |
56 NSLocaleCurrencySymbol = new NSString(bindings.NSLocaleCurrencySymbol); | 60 |
57 NSLocaleCurrencyCode = new NSString(bindings.NSLocaleCurrencyCode); | 61 return NSLocaleIdentifier_ = new NSString(bindings.NSLocaleIdentifier); |
58 NSGregorianCalendar = new NSString(bindings.NSGregorianCalendar); | 62 } |
59 NSBuddhistCalendar = new NSString(bindings.NSBuddhistCalendar); | 63 |
60 NSChineseCalendar = new NSString(bindings.NSChineseCalendar); | 64 NSString NSLocaleLanguageCode () |
61 NSHebrewCalendar = new NSString(bindings.NSHebrewCalendar); | 65 { |
62 NSIslamicCalendar = new NSString(bindings.NSIslamicCalendar); | 66 if (NSLocaleLanguageCode_) |
63 NSIslamicCivilCalendar = new NSString(bindings.NSIslamicCivilCalendar); | 67 return NSLocaleLanguageCode_; |
64 NSJapaneseCalendar = new NSString(bindings.NSJapaneseCalendar); | 68 |
65 } | 69 return NSLocaleLanguageCode_ = new NSString(bindings.NSLocaleLanguageCode); |
70 } | |
71 | |
72 NSString NSLocaleCountryCode () | |
73 { | |
74 if (NSLocaleCountryCode_) | |
75 return NSLocaleCountryCode_; | |
76 | |
77 return NSLocaleCountryCode_ = new NSString(bindings.NSLocaleCountryCode); | |
78 } | |
79 | |
80 NSString NSLocaleScriptCode () | |
81 { | |
82 if (NSLocaleScriptCode_) | |
83 return NSLocaleScriptCode_; | |
84 | |
85 return NSLocaleScriptCode_ = new NSString(bindings.NSLocaleScriptCode); | |
86 } | |
87 | |
88 NSString NSLocaleVariantCode () | |
89 { | |
90 if (NSLocaleVariantCode_) | |
91 return NSLocaleVariantCode_; | |
92 | |
93 return NSLocaleVariantCode_ = new NSString(bindings.NSLocaleVariantCode); | |
94 } | |
95 | |
96 NSString NSLocaleExemplarCharacterSet () | |
97 { | |
98 if (NSLocaleExemplarCharacterSet_) | |
99 return NSLocaleExemplarCharacterSet_; | |
100 | |
101 return NSLocaleExemplarCharacterSet_ = new NSString(bindings.NSLocaleExemplarCharacterSet); | |
102 } | |
103 | |
104 NSString NSLocaleCalendar () | |
105 { | |
106 if (NSLocaleCalendar_) | |
107 return NSLocaleCalendar_; | |
108 | |
109 return NSLocaleCalendar_ = new NSString(bindings.NSLocaleCalendar); | |
110 } | |
111 | |
112 NSString NSLocaleCollationIdentifier () | |
113 { | |
114 if (NSLocaleCollationIdentifier_) | |
115 return NSLocaleCollationIdentifier_; | |
116 | |
117 return NSLocaleCollationIdentifier_ = new NSString(bindings.NSLocaleCollationIdentifier); | |
118 } | |
119 | |
120 NSString NSLocaleUsesMetricSystem () | |
121 { | |
122 if (NSLocaleUsesMetricSystem_) | |
123 return NSLocaleUsesMetricSystem_; | |
124 | |
125 return NSLocaleUsesMetricSystem_ = new NSString(bindings.NSLocaleUsesMetricSystem); | |
126 } | |
127 | |
128 NSString NSLocaleMeasurementSystem () | |
129 { | |
130 if (NSLocaleMeasurementSystem_) | |
131 return NSLocaleMeasurementSystem_; | |
132 | |
133 return NSLocaleMeasurementSystem_ = new NSString(bindings.NSLocaleMeasurementSystem); | |
134 } | |
135 | |
136 NSString NSLocaleDecimalSeparator () | |
137 { | |
138 if (NSLocaleDecimalSeparator_) | |
139 return NSLocaleDecimalSeparator_; | |
140 | |
141 return NSLocaleDecimalSeparator_ = new NSString(bindings.NSLocaleDecimalSeparator); | |
142 } | |
143 | |
144 NSString NSLocaleGroupingSeparator () | |
145 { | |
146 if (NSLocaleGroupingSeparator_) | |
147 return NSLocaleGroupingSeparator_; | |
148 | |
149 return NSLocaleGroupingSeparator_ = new NSString(bindings.NSLocaleGroupingSeparator); | |
150 } | |
151 | |
152 NSString NSLocaleCurrencySymbol () | |
153 { | |
154 if (NSLocaleCurrencySymbol_) | |
155 return NSLocaleCurrencySymbol_; | |
156 | |
157 return NSLocaleCurrencySymbol_ = new NSString(bindings.NSLocaleCurrencySymbol); | |
158 } | |
159 | |
160 NSString NSLocaleCurrencyCode () | |
161 { | |
162 if (NSLocaleCurrencyCode_) | |
163 return NSLocaleCurrencyCode_; | |
164 | |
165 return NSLocaleCurrencyCode_ = new NSString(bindings.NSLocaleCurrencyCode); | |
166 } | |
167 | |
168 NSString NSGregorianCalendar () | |
169 { | |
170 if (NSGregorianCalendar_) | |
171 return NSGregorianCalendar_; | |
172 | |
173 return NSGregorianCalendar_ = new NSString(bindings.NSGregorianCalendar); | |
174 } | |
175 | |
176 NSString NSBuddhistCalendar () | |
177 { | |
178 if (NSBuddhistCalendar_) | |
179 return NSBuddhistCalendar_; | |
180 | |
181 return NSBuddhistCalendar_ = new NSString(bindings.NSBuddhistCalendar); | |
182 } | |
183 | |
184 NSString NSChineseCalendar () | |
185 { | |
186 if (NSChineseCalendar_) | |
187 return NSChineseCalendar_; | |
188 | |
189 return NSChineseCalendar_ = new NSString(bindings.NSChineseCalendar); | |
190 } | |
191 | |
192 NSString NSHebrewCalendar () | |
193 { | |
194 if (NSHebrewCalendar_) | |
195 return NSHebrewCalendar_; | |
196 | |
197 return NSHebrewCalendar_ = new NSString(bindings.NSHebrewCalendar); | |
198 } | |
199 | |
200 NSString NSIslamicCalendar () | |
201 { | |
202 if (NSIslamicCalendar_) | |
203 return NSIslamicCalendar_; | |
204 | |
205 return NSIslamicCalendar_ = new NSString(bindings.NSIslamicCalendar); | |
206 } | |
207 | |
208 NSString NSIslamicCivilCalendar () | |
209 { | |
210 if (NSIslamicCivilCalendar_) | |
211 return NSIslamicCivilCalendar_; | |
212 | |
213 return NSIslamicCivilCalendar_ = new NSString(bindings.NSIslamicCivilCalendar); | |
214 } | |
215 | |
216 NSString NSJapaneseCalendar () | |
217 { | |
218 if (NSJapaneseCalendar_) | |
219 return NSJapaneseCalendar_; | |
220 | |
221 return NSJapaneseCalendar_ = new NSString(bindings.NSJapaneseCalendar); | |
222 } | |
223 | |
224 const TNSLocaleCreation = ` | |
225 | |
226 static Object systemLocale () | |
227 { | |
228 return invokeObjcSuperClass!(Object, "systemLocale"); | |
229 } | |
230 | |
231 static Object currentLocale () | |
232 { | |
233 return invokeObjcSuperClass!(Object, "currentLocale"); | |
234 } | |
235 | |
236 static Object autoupdatingCurrentLocale () | |
237 { | |
238 return invokeObjcSuperClass!(Object, "autoupdatingCurrentLocale"); | |
239 } | |
240 | |
241 Object initWithLocaleIdentifier (NSString string) | |
242 { | |
243 return invokeObjcSelf!(Object, "initWithLocaleIdentifier:", NSString)(string); | |
244 } | |
245 | |
246 this (NSString string) | |
247 { | |
248 typeof(this).alloc.initWithLocaleIdentifier(string); | |
249 } | |
250 `; | |
251 | |
252 const TNSLocaleGeneralInfo = ` | |
253 | |
254 static NSArray availableLocaleIdentifiers () | |
255 { | |
256 return invokeObjcSuperClass!(NSArray, "availableLocaleIdentifiers"); | |
257 } | |
258 | |
259 static NSArray ISOLanguageCodes () | |
260 { | |
261 return invokeObjcSuperClass!(NSArray, "ISOLanguageCodes"); | |
262 } | |
263 | |
264 static NSArray ISOCountryCodes () | |
265 { | |
266 return invokeObjcSuperClass!(NSArray, "ISOCountryCodes"); | |
267 } | |
268 | |
269 static NSArray ISOCurrencyCodes () | |
270 { | |
271 return invokeObjcSuperClass!(NSArray, "ISOCurrencyCodes"); | |
272 } | |
273 | |
274 static NSArray commonISOCurrencyCodes () | |
275 { | |
276 return invokeObjcSuperClass!(NSArray, "commonISOCurrencyCodes"); | |
277 } | |
278 | |
279 static NSArray preferredLanguages () | |
280 { | |
281 return invokeObjcSuperClass!(NSArray, "preferredLanguages"); | |
282 } | |
283 | |
284 static NSDictionary componentsFromLocaleIdentifier (NSString string) | |
285 { | |
286 return invokeObjcSuperClass!(NSDictionary, "componentsFromLocaleIdentifier:", NSString)(string); | |
287 } | |
288 | |
289 static NSString localeIdentifierFromComponents (NSDictionary dict) | |
290 { | |
291 return invokeObjcSuperClass!(NSString, "localeIdentifierFromComponents:", NSDictionary)(dict); | |
292 } | |
293 | |
294 static NSString canonicalLocaleIdentifierFromString (NSString string) | |
295 { | |
296 return invokeObjcSuperClass!(NSString, "canonicalLocaleIdentifierFromString:", NSString)(string); | |
297 } | |
298 `; | |
299 | |
300 const TNSExtendedLocale = ` | |
301 | |
302 NSString localeIdentifier () | |
303 { | |
304 return invokeObjcSelf!(NSString, "localeIdentifier"); | |
305 } | |
306 `; | |
66 | 307 |
67 class NSLocale : NSObject, INSCopying, INSCoding | 308 class NSLocale : NSObject, INSCopying, INSCoding |
68 { | 309 { |
69 mixin ObjcWrap; | 310 mixin (ObjcWrap); |
70 mixin TNSLocaleCreation; | 311 |
71 mixin TNSLocaleGeneralInfo; | 312 this () |
72 mixin TNSExtendedLocale; | 313 { |
314 super(typeof(this).alloc.init.objcObject); | |
315 } | |
316 | |
317 typeof(this) init () | |
318 { | |
319 return invokeObjcSelf!(typeof(this), "init"); | |
320 } | |
73 | 321 |
74 Object objectForKey (Object key) | 322 Object objectForKey (Object key) |
75 { | 323 { |
76 return invokeObjcSelf!(Object, "objectForKey:", Object)(key); | 324 return invokeObjcSelf!(Object, "objectForKey:", Object)(key); |
77 } | 325 } |
96 return invokeObjcSelf!(Object, "initWithCoder:", NSCoder)(aDecoder); | 344 return invokeObjcSelf!(Object, "initWithCoder:", NSCoder)(aDecoder); |
97 } | 345 } |
98 | 346 |
99 this (NSCoder aDecoder) | 347 this (NSCoder aDecoder) |
100 { | 348 { |
101 objcObject = Bridge.invokeObjcClassMethod!(id, "alloc")(objcClass); | 349 typeof(this).alloc.initWithCoder(aDecoder); |
102 id result = Bridge.invokeObjcMethod!(id, "initWithCoder:", NSCoder)(objcObject, aDecoder); | 350 } |
103 | 351 |
104 if (result) | 352 // TNSLocaleCreation |
105 objcObject = ret; | |
106 | |
107 dObject = this; | |
108 } | |
109 } | |
110 | |
111 template TNSLocaleCreation () | |
112 { | |
113 static Object systemLocale () | 353 static Object systemLocale () |
114 { | 354 { |
115 return invokeObjcSelfClass!(Object, "systemLocale"); | 355 return invokeObjcSuperClass!(Object, "systemLocale"); |
116 } | 356 } |
117 | 357 |
118 static Object currentLocale () | 358 static Object currentLocale () |
119 { | 359 { |
120 return invokeObjcSelfClass!(Object, "currentLocale"); | 360 return invokeObjcSuperClass!(Object, "currentLocale"); |
121 } | 361 } |
122 | 362 |
123 static Object autoupdatingCurrentLocale () | 363 static Object autoupdatingCurrentLocale () |
124 { | 364 { |
125 return invokeObjcSelfClass!(Object, "autoupdatingCurrentLocale"); | 365 return invokeObjcSuperClass!(Object, "autoupdatingCurrentLocale"); |
126 } | 366 } |
127 | 367 |
128 Object initWithLocaleIdentifier (NSString string) | 368 Object initWithLocaleIdentifier (NSString string) |
129 { | 369 { |
130 return invokeObjcSelf!(Object, "initWithLocaleIdentifier:", NSString)(string); | 370 return invokeObjcSelf!(Object, "initWithLocaleIdentifier:", NSString)(string); |
131 } | 371 } |
132 | 372 |
133 this (NSString string) | 373 this (NSString string) |
134 { | 374 { |
135 objcObject = Bridge.invokeObjcClassMethod!(id, "alloc")(objcClass); | 375 typeof(this).alloc.initWithLocaleIdentifier(string); |
136 id result = Bridge.invokeObjcMethod!(id, "initWithLocaleIdentifier:", NSString)(objcObject, string); | 376 } |
137 | 377 |
138 if (result) | 378 // TNSLocaleGeneralInfo |
139 objcObject = ret; | |
140 | |
141 dObject = this; | |
142 } | |
143 } | |
144 | |
145 template TNSLocaleGeneralInfo () | |
146 { | |
147 static NSArray availableLocaleIdentifiers () | 379 static NSArray availableLocaleIdentifiers () |
148 { | 380 { |
149 return invokeObjcSelfClass!(NSArray, "availableLocaleIdentifiers"); | 381 return invokeObjcSuperClass!(NSArray, "availableLocaleIdentifiers"); |
150 } | 382 } |
151 | 383 |
152 static NSArray ISOLanguageCodes () | 384 static NSArray ISOLanguageCodes () |
153 { | 385 { |
154 return invokeObjcSelfClass!(NSArray, "ISOLanguageCodes"); | 386 return invokeObjcSuperClass!(NSArray, "ISOLanguageCodes"); |
155 } | 387 } |
156 | 388 |
157 static NSArray ISOCountryCodes () | 389 static NSArray ISOCountryCodes () |
158 { | 390 { |
159 return invokeObjcSelfClass!(NSArray, "ISOCountryCodes"); | 391 return invokeObjcSuperClass!(NSArray, "ISOCountryCodes"); |
160 } | 392 } |
161 | 393 |
162 static NSArray ISOCurrencyCodes () | 394 static NSArray ISOCurrencyCodes () |
163 { | 395 { |
164 return invokeObjcSelfClass!(NSArray, "ISOCurrencyCodes"); | 396 return invokeObjcSuperClass!(NSArray, "ISOCurrencyCodes"); |
165 } | 397 } |
166 | 398 |
167 static NSArray commonISOCurrencyCodes () | 399 static NSArray commonISOCurrencyCodes () |
168 { | 400 { |
169 return invokeObjcSelfClass!(NSArray, "commonISOCurrencyCodes"); | 401 return invokeObjcSuperClass!(NSArray, "commonISOCurrencyCodes"); |
170 } | 402 } |
171 | 403 |
172 static NSArray preferredLanguages () | 404 static NSArray preferredLanguages () |
173 { | 405 { |
174 return invokeObjcSelfClass!(NSArray, "preferredLanguages"); | 406 return invokeObjcSuperClass!(NSArray, "preferredLanguages"); |
175 } | 407 } |
176 | 408 |
177 static NSDictionary componentsFromLocaleIdentifier (NSString string) | 409 static NSDictionary componentsFromLocaleIdentifier (NSString string) |
178 { | 410 { |
179 return invokeObjcSelfClass!(NSDictionary, "componentsFromLocaleIdentifier:", NSString)(string); | 411 return invokeObjcSuperClass!(NSDictionary, "componentsFromLocaleIdentifier:", NSString)(string); |
180 } | 412 } |
181 | 413 |
182 static NSString localeIdentifierFromComponents (NSDictionary dict) | 414 static NSString localeIdentifierFromComponents (NSDictionary dict) |
183 { | 415 { |
184 return invokeObjcSelfClass!(NSString, "localeIdentifierFromComponents:", NSDictionary)(dict); | 416 return invokeObjcSuperClass!(NSString, "localeIdentifierFromComponents:", NSDictionary)(dict); |
185 } | 417 } |
186 | 418 |
187 static NSString canonicalLocaleIdentifierFromString (NSString string) | 419 static NSString canonicalLocaleIdentifierFromString (NSString string) |
188 { | 420 { |
189 return invokeObjcSelfClass!(NSString, "canonicalLocaleIdentifierFromString:", NSString)(string); | 421 return invokeObjcSuperClass!(NSString, "canonicalLocaleIdentifierFromString:", NSString)(string); |
190 } | 422 } |
191 } | 423 |
192 | 424 // TNSExtendedLocale |
193 template TNSExtendedLocale () | |
194 { | |
195 NSString localeIdentifier () | 425 NSString localeIdentifier () |
196 { | 426 { |
197 return invokeObjcSelf!(NSString, "localeIdentifier"); | 427 return invokeObjcSelf!(NSString, "localeIdentifier"); |
198 } | 428 } |
199 } | 429 } |
200 |