Mercurial > projects > dwt-addons
comparison dwtx/dwtxhelper/mangoicu/UBreakIterator.d @ 91:11e8159caf7a
make the mango icu fork work.
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Mon, 07 Jul 2008 15:53:07 +0200 |
parents | 040da1cb0d76 |
children | f05207c07a98 |
comparison
equal
deleted
inserted
replaced
90:7ffeace6c47f | 91:11e8159caf7a |
---|---|
1 /******************************************************************************* | 1 /******************************************************************************* |
2 | 2 |
3 @file UBreakIterator.d | 3 @file UBreakIterator.d |
4 | 4 |
5 Copyright (c) 2004 Kris Bell | 5 Copyright (c) 2004 Kris Bell |
6 | 6 |
7 This software is provided 'as-is', without any express or implied | 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 | 8 warranty. In no event will the authors be held liable for damages |
9 of any kind arising from the use of this software. | 9 of any kind arising from the use of this software. |
10 | 10 |
11 Permission is hereby granted to anyone to use this software for any | 11 Permission is hereby granted to anyone to use this software for any |
12 purpose, including commercial applications, and to alter it and/or | 12 purpose, including commercial applications, and to alter it and/or |
13 redistribute it freely, subject to the following restrictions: | 13 redistribute it freely, subject to the following restrictions: |
14 | 14 |
15 1. The origin of this software must not be misrepresented; you must | 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 | 16 not claim that you wrote the original software. If you use this |
17 software in a product, an acknowledgment within documentation of | 17 software in a product, an acknowledgment within documentation of |
18 said product would be appreciated but is not required. | 18 said product would be appreciated but is not required. |
19 | 19 |
20 2. Altered source versions must be plainly marked as such, and must | 20 2. Altered source versions must be plainly marked as such, and must |
21 not be misrepresented as being the original software. | 21 not be misrepresented as being the original software. |
22 | 22 |
23 3. This notice may not be removed or altered from any distribution | 23 3. This notice may not be removed or altered from any distribution |
24 of the source. | 24 of the source. |
25 | 25 |
28 | 28 |
29 | 29 |
30 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | 30 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
31 | 31 |
32 | 32 |
33 @version Initial version, November 2004 | 33 @version Initial version, November 2004 |
34 @author Kris | 34 @author Kris |
35 | 35 |
36 Note that this package and documentation is built around the ICU | 36 Note that this package and documentation is built around the ICU |
37 project (http://oss.software.ibm.com/icu/). Below is the license | 37 project (http://oss.software.ibm.com/icu/). Below is the license |
38 statement as specified by that software: | 38 statement as specified by that software: |
39 | 39 |
40 | 40 |
41 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | 41 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
42 | 42 |
43 | 43 |
44 ICU License - ICU 1.8.1 and later | 44 ICU License - ICU 1.8.1 and later |
45 | 45 |
46 COPYRIGHT AND PERMISSION NOTICE | 46 COPYRIGHT AND PERMISSION NOTICE |
47 | 47 |
48 Copyright (c) 1995-2003 International Business Machines Corporation and | 48 Copyright (c) 1995-2003 International Business Machines Corporation and |
49 others. | 49 others. |
50 | 50 |
51 All rights reserved. | 51 All rights reserved. |
52 | 52 |
53 Permission is hereby granted, free of charge, to any person obtaining a | 53 Permission is hereby granted, free of charge, to any person obtaining a |
75 or other dealings in this Software without prior written authorization | 75 or other dealings in this Software without prior written authorization |
76 of the copyright holder. | 76 of the copyright holder. |
77 | 77 |
78 ---------------------------------------------------------------------- | 78 ---------------------------------------------------------------------- |
79 | 79 |
80 All trademarks and registered trademarks mentioned herein are the | 80 All trademarks and registered trademarks mentioned herein are the |
81 property of their respective owners. | 81 property of their respective owners. |
82 | 82 |
83 *******************************************************************************/ | 83 *******************************************************************************/ |
84 | 84 |
85 module dwtx.dwthelper.mangoicu.UBreakIterator; | 85 module dwtx.dwtxhelper.mangoicu.UBreakIterator; |
86 | 86 |
87 private import dwtx.dwthelper.mangoicu.ICU; | 87 private import dwtx.dwtxhelper.mangoicu.ICU; |
88 | 88 |
89 public import dwtx.dwthelper.mangoicu.ULocale, | 89 public import dwtx.dwtxhelper.mangoicu.ULocale, |
90 dwtx.dwthelper.mangoicu.UString; | 90 dwtx.dwtxhelper.mangoicu.UText, |
91 dwtx.dwtxhelper.mangoicu.UString; | |
92 | |
93 | |
94 | |
95 // /******************************************************************************* | |
96 // | |
97 // *******************************************************************************/ | |
98 // | |
99 // class UCharacterIterator : UBreakIterator | |
100 // { | |
101 // /*********************************************************************** | |
102 // | |
103 // ***********************************************************************/ | |
104 // | |
105 // this (inout ULocale locale, UStringView text = null) | |
106 // { | |
107 // super (Type.Character, locale, text); | |
108 // } | |
109 // } | |
110 // | |
111 // | |
112 // /******************************************************************************* | |
113 // | |
114 // *******************************************************************************/ | |
115 // | |
116 // class UWordIterator : UBreakIterator | |
117 // { | |
118 // public enum Break | |
119 // { | |
120 // None = 0, | |
121 // NoneLimit = 100, | |
122 // Number = 100, | |
123 // NumberLimit = 200, | |
124 // Letter = 200, | |
125 // LetterLimit = 300, | |
126 // Kana = 300, | |
127 // KanaLimit = 400, | |
128 // Ideo = 400, | |
129 // IdeoLimit = 500 | |
130 // } | |
131 // | |
132 // /*********************************************************************** | |
133 // | |
134 // ***********************************************************************/ | |
135 // | |
136 // this (inout ULocale locale, UStringView text = null) | |
137 // { | |
138 // super (Type.Word, locale, text); | |
139 // } | |
140 // | |
141 // /*********************************************************************** | |
142 // | |
143 // Return the status from the break rule that determined | |
144 // the most recently returned break position. | |
145 // | |
146 // ***********************************************************************/ | |
147 // | |
148 // void getStatus (inout Break b) | |
149 // { | |
150 // b = cast(Break) super.getStatus(); | |
151 // } | |
152 // } | |
153 // | |
154 // | |
155 // /******************************************************************************* | |
156 // | |
157 // *******************************************************************************/ | |
158 // | |
159 // class ULineIterator : UBreakIterator | |
160 // { | |
161 // public enum Break | |
162 // { | |
163 // Soft = 0, | |
164 // SoftLimit = 100, | |
165 // Hard = 100, | |
166 // HardLimit = 200 | |
167 // } | |
168 // | |
169 // /*********************************************************************** | |
170 // | |
171 // ***********************************************************************/ | |
172 // | |
173 // this (inout ULocale locale, UStringView text = null) | |
174 // { | |
175 // super (Type.Line, locale, text); | |
176 // } | |
177 // | |
178 // /*********************************************************************** | |
179 // | |
180 // Return the status from the break rule that determined | |
181 // the most recently returned break position. | |
182 // | |
183 // ***********************************************************************/ | |
184 // | |
185 // void getStatus (inout Break b) | |
186 // { | |
187 // b = cast(Break) super.getStatus(); | |
188 // } | |
189 // } | |
190 // | |
191 // | |
192 // /******************************************************************************* | |
193 // | |
194 // *******************************************************************************/ | |
195 // | |
196 // class USentenceIterator : UBreakIterator | |
197 // { | |
198 // public enum Break | |
199 // { | |
200 // Term = 0, | |
201 // TermLimit = 100, | |
202 // Sep = 100, | |
203 // Limit = 200 | |
204 // } | |
205 // | |
206 // /*********************************************************************** | |
207 // | |
208 // ***********************************************************************/ | |
209 // | |
210 // this (inout ULocale locale, UStringView text = null) | |
211 // { | |
212 // super (Type.Sentence, locale, text); | |
213 // } | |
214 // | |
215 // /*********************************************************************** | |
216 // | |
217 // Return the status from the break rule that determined | |
218 // the most recently returned break position. | |
219 // | |
220 // ***********************************************************************/ | |
221 // | |
222 // void getStatus (inout Break b) | |
223 // { | |
224 // b = cast(Break) super.getStatus(); | |
225 // } | |
226 // } | |
227 // | |
228 // | |
229 // /******************************************************************************* | |
230 // | |
231 // *******************************************************************************/ | |
232 // | |
233 // class UTitleIterator : UBreakIterator | |
234 // { | |
235 // /*********************************************************************** | |
236 // | |
237 // ***********************************************************************/ | |
238 // | |
239 // this (inout ULocale locale, UStringView text = null) | |
240 // { | |
241 // super (Type.Title, locale, text); | |
242 // } | |
243 // } | |
244 // | |
245 // | |
246 // /******************************************************************************* | |
247 // | |
248 // *******************************************************************************/ | |
249 // | |
250 // class URuleIterator : UBreakIterator | |
251 // { | |
252 // /*********************************************************************** | |
253 // | |
254 // Open a new UBreakIterator for locating text boundaries | |
255 // using specified breaking rules | |
256 // | |
257 // ***********************************************************************/ | |
258 // | |
259 // this (UStringView rules, UStringView text = null) | |
260 // { | |
261 // UErrorCode e; | |
262 // | |
263 // handle = ubrk_openRules (rules.get.ptr, rules.length, text.get.ptr, text.length, null, e); | |
264 // testError (e, "failed to open rule iterator"); | |
265 // } | |
266 // } | |
267 | |
91 | 268 |
92 /******************************************************************************* | 269 /******************************************************************************* |
93 | 270 |
94 *******************************************************************************/ | 271 BreakIterator defines methods for finding the location of boundaries |
95 | 272 in text. Pointer to a UBreakIterator maintain a current position and |
96 class UCharacterIterator : UBreakIterator | |
97 { | |
98 /*********************************************************************** | |
99 | |
100 ***********************************************************************/ | |
101 | |
102 this (inout ULocale locale, UText text = null) | |
103 { | |
104 super (Type.Character, locale, text); | |
105 } | |
106 } | |
107 | |
108 | |
109 /******************************************************************************* | |
110 | |
111 *******************************************************************************/ | |
112 | |
113 class UWordIterator : UBreakIterator | |
114 { | |
115 public enum Break | |
116 { | |
117 None = 0, | |
118 NoneLimit = 100, | |
119 Number = 100, | |
120 NumberLimit = 200, | |
121 Letter = 200, | |
122 LetterLimit = 300, | |
123 Kana = 300, | |
124 KanaLimit = 400, | |
125 Ideo = 400, | |
126 IdeoLimit = 500 | |
127 } | |
128 | |
129 /*********************************************************************** | |
130 | |
131 ***********************************************************************/ | |
132 | |
133 this (inout ULocale locale, UText text = null) | |
134 { | |
135 super (Type.Word, locale, text); | |
136 } | |
137 | |
138 /*********************************************************************** | |
139 | |
140 Return the status from the break rule that determined | |
141 the most recently returned break position. | |
142 | |
143 ***********************************************************************/ | |
144 | |
145 void getStatus (inout Break b) | |
146 { | |
147 b = cast(Break) super.getStatus(); | |
148 } | |
149 } | |
150 | |
151 | |
152 /******************************************************************************* | |
153 | |
154 *******************************************************************************/ | |
155 | |
156 class ULineIterator : UBreakIterator | |
157 { | |
158 public enum Break | |
159 { | |
160 Soft = 0, | |
161 SoftLimit = 100, | |
162 Hard = 100, | |
163 HardLimit = 200 | |
164 } | |
165 | |
166 /*********************************************************************** | |
167 | |
168 ***********************************************************************/ | |
169 | |
170 this (inout ULocale locale, UText text = null) | |
171 { | |
172 super (Type.Line, locale, text); | |
173 } | |
174 | |
175 /*********************************************************************** | |
176 | |
177 Return the status from the break rule that determined | |
178 the most recently returned break position. | |
179 | |
180 ***********************************************************************/ | |
181 | |
182 void getStatus (inout Break b) | |
183 { | |
184 b = cast(Break) super.getStatus(); | |
185 } | |
186 } | |
187 | |
188 | |
189 /******************************************************************************* | |
190 | |
191 *******************************************************************************/ | |
192 | |
193 class USentenceIterator : UBreakIterator | |
194 { | |
195 public enum Break | |
196 { | |
197 Term = 0, | |
198 TermLimit = 100, | |
199 Sep = 100, | |
200 Limit = 200 | |
201 } | |
202 | |
203 /*********************************************************************** | |
204 | |
205 ***********************************************************************/ | |
206 | |
207 this (inout ULocale locale, UText text = null) | |
208 { | |
209 super (Type.Sentence, locale, text); | |
210 } | |
211 | |
212 /*********************************************************************** | |
213 | |
214 Return the status from the break rule that determined | |
215 the most recently returned break position. | |
216 | |
217 ***********************************************************************/ | |
218 | |
219 void getStatus (inout Break b) | |
220 { | |
221 b = cast(Break) super.getStatus(); | |
222 } | |
223 } | |
224 | |
225 | |
226 /******************************************************************************* | |
227 | |
228 *******************************************************************************/ | |
229 | |
230 class UTitleIterator : UBreakIterator | |
231 { | |
232 /*********************************************************************** | |
233 | |
234 ***********************************************************************/ | |
235 | |
236 this (inout ULocale locale, UText text = null) | |
237 { | |
238 super (Type.Title, locale, text); | |
239 } | |
240 } | |
241 | |
242 | |
243 /******************************************************************************* | |
244 | |
245 *******************************************************************************/ | |
246 | |
247 class URuleIterator : UBreakIterator | |
248 { | |
249 /*********************************************************************** | |
250 | |
251 Open a new UBreakIterator for locating text boundaries | |
252 using specified breaking rules | |
253 | |
254 ***********************************************************************/ | |
255 | |
256 this (UText rules, UText text = null) | |
257 { | |
258 Error e; | |
259 | |
260 handle = ubrk_openRules (rules.get.ptr, rules.length, text.get.ptr, text.length, null, e); | |
261 testError (e, "failed to open rule iterator"); | |
262 } | |
263 } | |
264 | |
265 | |
266 /******************************************************************************* | |
267 | |
268 BreakIterator defines methods for finding the location of boundaries | |
269 in text. Pointer to a UBreakIterator maintain a current position and | |
270 scan over text returning the index of characters where boundaries occur. | 273 scan over text returning the index of characters where boundaries occur. |
271 | 274 |
272 Line boundary analysis determines where a text string can be broken | 275 Line boundary analysis determines where a text string can be broken |
273 when line-wrapping. The mechanism correctly handles punctuation and | 276 when line-wrapping. The mechanism correctly handles punctuation and |
274 hyphenated words. | 277 hyphenated words. |
275 | 278 |
276 Sentence boundary analysis allows selection with correct interpretation | 279 Sentence boundary analysis allows selection with correct interpretation |
277 of periods within numbers and abbreviations, and trailing punctuation | 280 of periods within numbers and abbreviations, and trailing punctuation |
278 marks such as quotation marks and parentheses. | 281 marks such as quotation marks and parentheses. |
279 | 282 |
280 Word boundary analysis is used by search and replace functions, as well | 283 Word boundary analysis is used by search and replace functions, as well |
281 as within text editing applications that allow the user to select words | 284 as within text editing applications that allow the user to select words |
282 with a double click. Word selection provides correct interpretation of | 285 with a double click. Word selection provides correct interpretation of |
283 punctuation marks within and following words. Characters that are not | 286 punctuation marks within and following words. Characters that are not |
284 part of a word, such as symbols or punctuation marks, have word-breaks | 287 part of a word, such as symbols or punctuation marks, have word-breaks |
285 on both sides. | 288 on both sides. |
286 | 289 |
287 Character boundary analysis allows users to interact with characters | 290 Character boundary analysis allows users to interact with characters |
288 as they expect to, for example, when moving the cursor through a text | 291 as they expect to, for example, when moving the cursor through a text |
289 string. Character boundary analysis provides correct navigation of | 292 string. Character boundary analysis provides correct navigation of |
290 through character strings, regardless of how the character is stored. | 293 through character strings, regardless of how the character is stored. |
291 For example, an accented character might be stored as a base character | 294 For example, an accented character might be stored as a base character |
292 and a diacritical mark. What users consider to be a character can differ | 295 and a diacritical mark. What users consider to be a character can differ |
293 between languages. | 296 between languages. |
294 | 297 |
295 Title boundary analysis locates all positions, typically starts of | 298 Title boundary analysis locates all positions, typically starts of |
296 words, that should be set to Title Case when title casing the text. | 299 words, that should be set to Title Case when title casing the text. |
297 | 300 |
298 See <A HREF="http://oss.software.ibm.com/icu/apiref/ubrk_8h.html"> | 301 See <A HREF="http://oss.software.ibm.com/icu/apiref/ubrk_8h.html"> |
299 this page</A> for full details. | 302 this page</A> for full details. |
300 | 303 |
301 *******************************************************************************/ | 304 *******************************************************************************/ |
302 | 305 |
303 private class UBreakIterator : ICU | 306 struct UBreakIterator |
304 { | 307 { |
305 package Handle handle; | 308 typedef void _UBreakIterator; |
309 alias _UBreakIterator* Handle; | |
310 Handle handle; | |
311 UText ut; | |
306 | 312 |
307 // this is returned by next(), previous() etc ... | 313 // this is returned by next(), previous() etc ... |
308 const uint Done = uint.max; | 314 const uint Done = uint.max; |
309 | 315 |
310 /*********************************************************************** | 316 /*********************************************************************** |
311 | 317 |
312 internal types passed to C API | 318 internal types passed to C API |
313 | 319 |
314 ***********************************************************************/ | 320 ***********************************************************************/ |
315 | 321 |
316 private enum Type | 322 private enum Type |
317 { | 323 { |
318 Character, | 324 Character, |
319 Word, | 325 Word, |
320 Line, | 326 Line, |
321 Sentence, | 327 Sentence, |
322 Title | 328 Title |
323 } | 329 } |
324 | 330 |
325 | 331 |
326 /*********************************************************************** | 332 public enum WordBreak |
327 | 333 { |
328 Internal use only! | 334 None = 0, |
329 | 335 NoneLimit = 100, |
330 ***********************************************************************/ | 336 Number = 100, |
331 | 337 NumberLimit = 200, |
332 private this () | 338 Letter = 200, |
333 { | 339 LetterLimit = 300, |
334 } | 340 Kana = 300, |
335 | 341 KanaLimit = 400, |
336 /*********************************************************************** | 342 Ideo = 400, |
337 | 343 IdeoLimit = 500 |
338 Open a new UBreakIterator for locating text boundaries for | 344 } |
339 a specified locale. A UBreakIterator may be used for detecting | 345 public enum LineBreak |
340 character, line, word, and sentence breaks in text. | 346 { |
341 | 347 Soft = 0, |
342 ***********************************************************************/ | 348 SoftLimit = 100, |
343 | 349 Hard = 100, |
344 this (Type type, inout ULocale locale, UText text) | 350 HardLimit = 200 |
345 { | 351 } |
346 Error e; | 352 public enum SentenceBreak |
347 | 353 { |
348 handle = ubrk_open (type, toString(locale.name), text.get.ptr, text.length, e); | 354 Term = 0, |
349 testError (e, "failed to create break iterator"); | 355 TermLimit = 100, |
350 } | 356 Sep = 100, |
351 | 357 Limit = 200 |
352 /*********************************************************************** | 358 } |
353 | 359 |
360 | |
361 /*********************************************************************** | |
362 | |
363 Open a new UBreakIterator for locating text boundaries for | |
364 a specified locale. A UBreakIterator may be used for detecting | |
365 character, line, word, and sentence breaks in text. | |
366 | |
367 ***********************************************************************/ | |
368 | |
369 static UBreakIterator openWordIterator( ULocale locale, char[] str ){ | |
370 UBreakIterator res; | |
371 res.ut.openUTF8(str); | |
372 auto e = ICU.UErrorCode.OK; | |
373 res.handle = ubrk_open( Type.Word, locale.name.ptr, null, 0, e); | |
374 ICU.testError (e, "failed to open word iterator"); | |
375 ubrk_setUText( res.handle, & res.ut, e); | |
376 ICU.testError (e, "failed to set text in iterator"); | |
377 return res; | |
378 } | |
379 | |
380 static UBreakIterator openLineIterator( ULocale locale, char[] str ){ | |
381 UBreakIterator res; | |
382 res.ut.openUTF8(str); | |
383 auto e = ICU.UErrorCode.OK; | |
384 res.handle = ubrk_open( Type.Line, locale.name.ptr, null, 0, e); | |
385 ICU.testError (e, "failed to open line iterator"); | |
386 ubrk_setUText( res.handle, & res.ut, e); | |
387 ICU.testError (e, "failed to set text in iterator"); | |
388 return res; | |
389 } | |
390 | |
391 /*********************************************************************** | |
392 | |
354 Close a UBreakIterator | 393 Close a UBreakIterator |
355 | 394 |
356 ***********************************************************************/ | 395 ***********************************************************************/ |
357 | 396 |
358 ~this () | 397 void close () |
359 { | 398 { |
399 ut.close(); | |
360 ubrk_close (handle); | 400 ubrk_close (handle); |
361 } | 401 } |
362 | 402 |
363 /*********************************************************************** | 403 /*********************************************************************** |
364 | 404 |
365 Sets an existing iterator to point to a new piece of text | 405 Sets an existing iterator to point to a new piece of text |
366 | 406 |
367 ***********************************************************************/ | 407 ***********************************************************************/ |
368 | 408 |
369 void setText (UText text) | 409 void setText (UStringView text) |
370 { | 410 { |
371 Error e; | 411 ICU.UErrorCode e; |
372 ubrk_setText (handle, text.get.ptr, text.length, e); | 412 ubrk_setText (handle, text.get.ptr, text.length, e); |
373 testError (e, "failed to set iterator text"); | 413 ICU.testError (e, "failed to set iterator text"); |
374 } | 414 } |
375 | 415 |
376 /*********************************************************************** | 416 void setText (char[] text) |
377 | 417 { |
418 auto e = ICU.UErrorCode.OK; | |
419 ut.openUTF8(text); | |
420 ubrk_setUText( handle, & ut, e); | |
421 ICU.testError (e, "failed to set text in iterator"); | |
422 } | |
423 | |
424 /*********************************************************************** | |
425 | |
378 Determine the most recently-returned text boundary | 426 Determine the most recently-returned text boundary |
379 | 427 |
380 ***********************************************************************/ | 428 ***********************************************************************/ |
381 | 429 |
382 uint current () | 430 uint current () |
383 { | 431 { |
384 return ubrk_current (handle); | 432 return ubrk_current (handle); |
385 } | 433 } |
386 | 434 |
387 /*********************************************************************** | 435 /*********************************************************************** |
388 | 436 |
389 Determine the text boundary following the current text | 437 Determine the text boundary following the current text |
390 boundary, or UBRK_DONE if all text boundaries have been | 438 boundary, or UBRK_DONE if all text boundaries have been |
391 returned. | 439 returned. |
392 | 440 |
393 If offset is specified, determines the text boundary | 441 If offset is specified, determines the text boundary |
394 following the current text boundary: The value returned | 442 following the current text boundary: The value returned |
395 is always greater than offset, or Done | 443 is always greater than offset, or Done |
396 | 444 |
397 ***********************************************************************/ | 445 ***********************************************************************/ |
398 | 446 |
399 uint next (uint offset = uint.max) | 447 uint next (uint offset = uint.max) |
402 return ubrk_next (handle); | 450 return ubrk_next (handle); |
403 return ubrk_following (handle, offset); | 451 return ubrk_following (handle, offset); |
404 } | 452 } |
405 | 453 |
406 /*********************************************************************** | 454 /*********************************************************************** |
407 | 455 |
408 Determine the text boundary preceding the current text | 456 Determine the text boundary preceding the current text |
409 boundary, or Done if all text boundaries have been returned. | 457 boundary, or Done if all text boundaries have been returned. |
410 | 458 |
411 If offset is specified, determines the text boundary preceding | 459 If offset is specified, determines the text boundary preceding |
412 the specified offset. The value returned is always smaller than | 460 the specified offset. The value returned is always smaller than |
413 offset, or Done. | 461 offset, or Done. |
414 | 462 |
415 ***********************************************************************/ | 463 ***********************************************************************/ |
416 | 464 |
417 uint previous (uint offset = uint.max) | 465 uint previous (uint offset = uint.max) |
420 return ubrk_previous (handle); | 468 return ubrk_previous (handle); |
421 return ubrk_preceding (handle, offset); | 469 return ubrk_preceding (handle, offset); |
422 } | 470 } |
423 | 471 |
424 /*********************************************************************** | 472 /*********************************************************************** |
425 | 473 |
426 Determine the index of the first character in the text | 474 Determine the index of the first character in the text |
427 being scanned. This is not always the same as index 0 | 475 being scanned. This is not always the same as index 0 |
428 of the text. | 476 of the text. |
429 | 477 |
430 ***********************************************************************/ | 478 ***********************************************************************/ |
431 | 479 |
432 uint first () | 480 uint first () |
433 { | 481 { |
434 return ubrk_first (handle); | 482 return ubrk_first (handle); |
435 } | 483 } |
436 | 484 |
437 /*********************************************************************** | 485 /*********************************************************************** |
438 | 486 |
439 Determine the index immediately beyond the last character | 487 Determine the index immediately beyond the last character |
440 in the text being scanned. This is not the same as the last | 488 in the text being scanned. This is not the same as the last |
441 character | 489 character |
442 | 490 |
443 ***********************************************************************/ | 491 ***********************************************************************/ |
444 | 492 |
445 uint last () | 493 uint last () |
446 { | 494 { |
447 return ubrk_last (handle); | 495 return ubrk_last (handle); |
448 } | 496 } |
449 | 497 |
450 /*********************************************************************** | 498 /*********************************************************************** |
451 | 499 |
452 Returns true if the specfied position is a boundary position. | 500 Returns true if the specfied position is a boundary position. |
453 As a side effect, leaves the iterator pointing to the first | 501 As a side effect, leaves the iterator pointing to the first |
454 boundary position at or after "offset". | 502 boundary position at or after "offset". |
455 | 503 |
456 ***********************************************************************/ | 504 ***********************************************************************/ |
457 | 505 |
458 bool isBoundary (uint offset) | 506 bool isBoundary (uint offset) |
459 { | 507 { |
460 return ubrk_isBoundary (handle, offset) != 0; | 508 return ubrk_isBoundary (handle, offset) != 0; |
461 } | 509 } |
462 | 510 |
463 /*********************************************************************** | 511 /*********************************************************************** |
464 | 512 |
465 Return the status from the break rule that determined | 513 Return the status from the break rule that determined |
466 the most recently returned break position. | 514 the most recently returned break position. |
467 | 515 |
468 ***********************************************************************/ | 516 ***********************************************************************/ |
469 | 517 |
470 void getStatus (inout uint s) | 518 void getStatus (inout uint s) |
471 { | 519 { |
472 s = getStatus (); | 520 s = getStatus (); |
473 } | 521 } |
474 | 522 |
475 /*********************************************************************** | 523 /*********************************************************************** |
476 | 524 |
477 Return the status from the break rule that determined | 525 Return the status from the break rule that determined |
478 the most recently returned break position. | 526 the most recently returned break position. |
479 | 527 |
480 The values appear in the rule source within brackets, | 528 The values appear in the rule source within brackets, |
481 {123}, for example. For rules that do not specify a status, | 529 {123}, for example. For rules that do not specify a status, |
482 a default value of 0 is returned. | 530 a default value of 0 is returned. |
483 | 531 |
484 For word break iterators, the possible values are defined | 532 For word break iterators, the possible values are defined |
485 in enum UWordBreak | 533 in enum UWordBreak |
486 | 534 |
487 ***********************************************************************/ | 535 ***********************************************************************/ |
488 | 536 |
489 private uint getStatus () | 537 private uint getStatus () |
491 return ubrk_getRuleStatus (handle); | 539 return ubrk_getRuleStatus (handle); |
492 } | 540 } |
493 | 541 |
494 | 542 |
495 /*********************************************************************** | 543 /*********************************************************************** |
496 | 544 |
497 Bind the ICU functions from a shared library. This is | 545 Bind the ICU functions from a shared library. This is |
498 complicated by the issues regarding D and DLLs on the | 546 complicated by the issues regarding D and DLLs on the |
499 Windows platform | 547 Windows platform |
500 | 548 |
501 ***********************************************************************/ | 549 ***********************************************************************/ |
502 | 550 |
503 private static void* library; | 551 private static void* library; |
504 | 552 |
505 /*********************************************************************** | 553 /*********************************************************************** |
506 | 554 |
507 ***********************************************************************/ | 555 ***********************************************************************/ |
508 | 556 |
509 private static extern (C) | 557 private static extern (C) |
510 { | 558 { |
511 Handle function (uint, char*, wchar*, uint, inout Error) ubrk_open; | 559 Handle function (uint, char*, wchar*, uint, inout ICU.UErrorCode) ubrk_open; |
512 Handle function (wchar*, uint, wchar*, uint, void*, inout Error) ubrk_openRules; | 560 Handle function (wchar*, uint, wchar*, uint, void*, inout ICU.UErrorCode) ubrk_openRules; |
513 void function (Handle) ubrk_close; | 561 void function (Handle) ubrk_close; |
514 void function (Handle, wchar*, uint, inout Error) ubrk_setText; | 562 void function (Handle, wchar*, uint, inout ICU.UErrorCode) ubrk_setText; |
515 uint function (Handle) ubrk_current; | 563 uint function (Handle) ubrk_current; |
516 uint function (Handle) ubrk_next; | 564 uint function (Handle) ubrk_next; |
517 uint function (Handle) ubrk_previous; | 565 uint function (Handle) ubrk_previous; |
518 uint function (Handle) ubrk_first; | 566 uint function (Handle) ubrk_first; |
519 uint function (Handle) ubrk_last; | 567 uint function (Handle) ubrk_last; |
520 uint function (Handle, uint) ubrk_preceding; | 568 uint function (Handle, uint) ubrk_preceding; |
521 uint function (Handle, uint) ubrk_following; | 569 uint function (Handle, uint) ubrk_following; |
522 byte function (Handle, uint) ubrk_isBoundary; | 570 byte function (Handle, uint) ubrk_isBoundary; |
523 uint function (Handle) ubrk_getRuleStatus; | 571 uint function (Handle) ubrk_getRuleStatus; |
524 } | 572 Handle function (Handle, void *, int *, inout ICU.UErrorCode) ubrk_safeClone; |
525 | 573 void function (Handle, UText*, inout ICU.UErrorCode) ubrk_setUText; |
526 /*********************************************************************** | 574 } |
527 | 575 |
528 ***********************************************************************/ | 576 /*********************************************************************** |
529 | 577 |
530 static FunctionLoader.Bind[] targets = | 578 ***********************************************************************/ |
579 | |
580 static FunctionLoader.Bind[] targets = | |
531 [ | 581 [ |
532 {cast(void**) &ubrk_open, "ubrk_open"}, | 582 {cast(void**) &ubrk_open, "ubrk_open"}, |
533 {cast(void**) &ubrk_close, "ubrk_close"}, | 583 {cast(void**) &ubrk_close, "ubrk_close"}, |
534 {cast(void**) &ubrk_openRules, "ubrk_openRules"}, | 584 {cast(void**) &ubrk_openRules, "ubrk_openRules"}, |
535 {cast(void**) &ubrk_setText, "ubrk_setText"}, | 585 {cast(void**) &ubrk_setText, "ubrk_setText"}, |
536 {cast(void**) &ubrk_current, "ubrk_current"}, | 586 {cast(void**) &ubrk_current, "ubrk_current"}, |
537 {cast(void**) &ubrk_next, "ubrk_next"}, | 587 {cast(void**) &ubrk_next, "ubrk_next"}, |
540 {cast(void**) &ubrk_last, "ubrk_last"}, | 590 {cast(void**) &ubrk_last, "ubrk_last"}, |
541 {cast(void**) &ubrk_preceding, "ubrk_preceding"}, | 591 {cast(void**) &ubrk_preceding, "ubrk_preceding"}, |
542 {cast(void**) &ubrk_following, "ubrk_following"}, | 592 {cast(void**) &ubrk_following, "ubrk_following"}, |
543 {cast(void**) &ubrk_isBoundary, "ubrk_isBoundary"}, | 593 {cast(void**) &ubrk_isBoundary, "ubrk_isBoundary"}, |
544 {cast(void**) &ubrk_getRuleStatus, "ubrk_getRuleStatus"}, | 594 {cast(void**) &ubrk_getRuleStatus, "ubrk_getRuleStatus"}, |
595 {cast(void**) &ubrk_setUText, "ubrk_setUText"}, | |
596 {cast(void**) &ubrk_safeClone, "ubrk_safeClone"}, | |
545 ]; | 597 ]; |
546 | 598 |
547 /********************************************************************** | 599 /********************************************************************** |
548 | 600 |
549 **********************************************************************/ | 601 **********************************************************************/ |
550 | 602 |
551 static this () | 603 static this () |
552 { | 604 { |
553 library = FunctionLoader.bind (icuuc, targets); | 605 library = FunctionLoader.bind (ICU.icuuc, targets); |
554 } | 606 } |
555 | 607 |
556 /********************************************************************** | 608 /********************************************************************** |
557 | 609 |
558 **********************************************************************/ | 610 **********************************************************************/ |
559 | 611 |
560 static ~this () | 612 static ~this () |
561 { | 613 { |
562 FunctionLoader.unbind (library); | 614 FunctionLoader.unbind (library); |
563 } | 615 } |
564 } | 616 } |