]> git.saurik.com Git - apple/icu.git/blob - icuSources/test/cintltst/cbiapts.c
ICU-62109.0.1.tar.gz
[apple/icu.git] / icuSources / test / cintltst / cbiapts.c
1 // © 2016 and later: Unicode, Inc. and others.
2 // License & terms of use: http://www.unicode.org/copyright.html
3 /********************************************************************
4 * COPYRIGHT:
5 * Copyright (c) 1997-2016, International Business Machines Corporation and
6 * others. All Rights Reserved.
7 ********************************************************************/
8 /********************************************************************************
9 *
10 * File CBIAPTS.C
11 *
12 * Modification History:
13 * Name Description
14 * Madhu Katragadda Creation
15 *********************************************************************************/
16 /*C API TEST FOR BREAKITERATOR */
17 /**
18 * This is an API test. It doesn't test very many cases, and doesn't
19 * try to test the full functionality. It just calls each function in the class and
20 * verifies that it works on a basic level.
21 **/
22
23 #include "unicode/utypes.h"
24
25 #if !UCONFIG_NO_BREAK_ITERATION
26
27 #include <stdlib.h>
28 #include <string.h>
29 #include "unicode/uloc.h"
30 #include "unicode/ubrk.h"
31 #include "unicode/ustring.h"
32 #include "unicode/ucnv.h"
33 #include "unicode/utext.h"
34 #include "cintltst.h"
35 #include "cbiapts.h"
36 #include "cmemory.h"
37
38 #define TEST_ASSERT_SUCCESS(status) {if (U_FAILURE(status)) { \
39 log_data_err("Failure at file %s, line %d, error = %s (Are you missing data?)\n", __FILE__, __LINE__, u_errorName(status));}}
40
41 #define TEST_ASSERT(expr) {if ((expr)==FALSE) { \
42 log_data_err("Test Failure at file %s, line %d (Are you missing data?)\n", __FILE__, __LINE__);}}
43
44 #define APPLE_ADDITIONS 1
45
46 #if !UCONFIG_NO_FILE_IO
47 static void TestBreakIteratorSafeClone(void);
48 #endif
49 static void TestBreakIteratorRules(void);
50 static void TestBreakIteratorRuleError(void);
51 static void TestBreakIteratorStatusVec(void);
52 static void TestBreakIteratorUText(void);
53 static void TestBreakIteratorTailoring(void);
54 static void TestBreakIteratorRefresh(void);
55 static void TestBug11665(void);
56 static void TestBreakIteratorSuppressions(void);
57 #if APPLE_ADDITIONS
58 static void TestRuleBasedTokenizer(void);
59 #endif
60
61 void addBrkIterAPITest(TestNode** root);
62
63 void addBrkIterAPITest(TestNode** root)
64 {
65 #if !UCONFIG_NO_FILE_IO
66 addTest(root, &TestBreakIteratorCAPI, "tstxtbd/cbiapts/TestBreakIteratorCAPI");
67 addTest(root, &TestBreakIteratorSafeClone, "tstxtbd/cbiapts/TestBreakIteratorSafeClone");
68 addTest(root, &TestBreakIteratorUText, "tstxtbd/cbiapts/TestBreakIteratorUText");
69 #endif
70 addTest(root, &TestBreakIteratorRules, "tstxtbd/cbiapts/TestBreakIteratorRules");
71 addTest(root, &TestBreakIteratorRuleError, "tstxtbd/cbiapts/TestBreakIteratorRuleError");
72 addTest(root, &TestBreakIteratorStatusVec, "tstxtbd/cbiapts/TestBreakIteratorStatusVec");
73 addTest(root, &TestBreakIteratorTailoring, "tstxtbd/cbiapts/TestBreakIteratorTailoring");
74 addTest(root, &TestBreakIteratorRefresh, "tstxtbd/cbiapts/TestBreakIteratorRefresh");
75 addTest(root, &TestBug11665, "tstxtbd/cbiapts/TestBug11665");
76 #if !UCONFIG_NO_FILTERED_BREAK_ITERATION
77 addTest(root, &TestBreakIteratorSuppressions, "tstxtbd/cbiapts/TestBreakIteratorSuppressions");
78 #endif
79 #if APPLE_ADDITIONS
80 addTest(root, &TestRuleBasedTokenizer, "tstxtbd/cbiapts/TestRuleBasedTokenizer");
81 #endif
82 }
83
84 #define CLONETEST_ITERATOR_COUNT 2
85
86 /*
87 * Utility function for converting char * to UChar * strings, to
88 * simplify the test code. Converted strings are put in heap allocated
89 * storage. A hook (probably a local in the caller's code) allows all
90 * strings converted with that hook to be freed with a single call.
91 */
92 typedef struct StringStruct {
93 struct StringStruct *link;
94 UChar str[1];
95 } StringStruct;
96
97
98 static UChar* toUChar(const char *src, void **freeHook) {
99 /* Structure of the memory that we allocate on the heap */
100
101 int32_t numUChars;
102 int32_t destSize;
103 UChar stackBuf[2000 + sizeof(void *)/sizeof(UChar)];
104 StringStruct *dest;
105 UConverter *cnv;
106
107 UErrorCode status = U_ZERO_ERROR;
108 if (src == NULL) {
109 return NULL;
110 };
111
112 cnv = ucnv_open(NULL, &status);
113 if(U_FAILURE(status) || cnv == NULL) {
114 return NULL;
115 }
116 ucnv_reset(cnv);
117 numUChars = ucnv_toUChars(cnv,
118 stackBuf,
119 2000,
120 src, -1,
121 &status);
122
123 destSize = (numUChars+1) * sizeof(UChar) + sizeof(struct StringStruct);
124 dest = (StringStruct *)malloc(destSize);
125 if (dest != NULL) {
126 if (status == U_BUFFER_OVERFLOW_ERROR || status == U_STRING_NOT_TERMINATED_WARNING) {
127 ucnv_toUChars(cnv, dest->str, numUChars+1, src, -1, &status);
128 } else if (status == U_ZERO_ERROR) {
129 u_strcpy(dest->str, stackBuf);
130 } else {
131 free(dest);
132 dest = NULL;
133 }
134 }
135
136 ucnv_reset(cnv); /* be good citizens */
137 ucnv_close(cnv);
138 if (dest == NULL) {
139 return NULL;
140 }
141
142 dest->link = (StringStruct*)(*freeHook);
143 *freeHook = dest;
144 return dest->str;
145 }
146
147 static void freeToUCharStrings(void **hook) {
148 StringStruct *s = *(StringStruct **)hook;
149 while (s != NULL) {
150 StringStruct *next = s->link;
151 free(s);
152 s = next;
153 }
154 }
155
156
157 #if !UCONFIG_NO_FILE_IO
158 static void TestBreakIteratorCAPI()
159 {
160 UErrorCode status = U_ZERO_ERROR;
161 UBreakIterator *word, *sentence, *line, *character, *b, *bogus;
162 int32_t start,pos,end,to;
163 int32_t i;
164 int32_t count = 0;
165
166 UChar text[50];
167
168 /* Note: the adjacent "" are concatenating strings, not adding a \" to the
169 string, which is probably what whoever wrote this intended. Don't fix,
170 because it would throw off the hard coded break positions in the following
171 tests. */
172 u_uastrcpy(text, "He's from Africa. ""Mr. Livingston, I presume?"" Yeah");
173
174
175 /*test ubrk_open()*/
176 log_verbose("\nTesting BreakIterator open functions\n");
177
178 /* Use french for fun */
179 word = ubrk_open(UBRK_WORD, "en_US", text, u_strlen(text), &status);
180 if(status == U_FILE_ACCESS_ERROR) {
181 log_data_err("Check your data - it doesn't seem to be around\n");
182 return;
183 } else if(U_FAILURE(status)){
184 log_err_status(status, "FAIL: Error in ubrk_open() for word breakiterator: %s\n", myErrorName(status));
185 }
186 else{
187 log_verbose("PASS: Successfully opened word breakiterator\n");
188 }
189
190 sentence = ubrk_open(UBRK_SENTENCE, "en_US", text, u_strlen(text), &status);
191 if(U_FAILURE(status)){
192 log_err_status(status, "FAIL: Error in ubrk_open() for sentence breakiterator: %s\n", myErrorName(status));
193 return;
194 }
195 else{
196 log_verbose("PASS: Successfully opened sentence breakiterator\n");
197 }
198
199 line = ubrk_open(UBRK_LINE, "en_US", text, u_strlen(text), &status);
200 if(U_FAILURE(status)){
201 log_err("FAIL: Error in ubrk_open() for line breakiterator: %s\n", myErrorName(status));
202 return;
203 }
204 else{
205 log_verbose("PASS: Successfully opened line breakiterator\n");
206 }
207
208 character = ubrk_open(UBRK_CHARACTER, "en_US", text, u_strlen(text), &status);
209 if(U_FAILURE(status)){
210 log_err("FAIL: Error in ubrk_open() for character breakiterator: %s\n", myErrorName(status));
211 return;
212 }
213 else{
214 log_verbose("PASS: Successfully opened character breakiterator\n");
215 }
216 /*trying to open an illegal iterator*/
217 bogus = ubrk_open((UBreakIteratorType)5, "en_US", text, u_strlen(text), &status);
218 if(bogus != NULL) {
219 log_err("FAIL: expected NULL from opening an invalid break iterator.\n");
220 }
221 if(U_SUCCESS(status)){
222 log_err("FAIL: Error in ubrk_open() for BOGUS breakiterator. Expected U_ILLEGAL_ARGUMENT_ERROR\n");
223 }
224 if(U_FAILURE(status)){
225 if(status != U_ILLEGAL_ARGUMENT_ERROR){
226 log_err("FAIL: Error in ubrk_open() for BOGUS breakiterator. Expected U_ILLEGAL_ARGUMENT_ERROR\n Got %s\n", myErrorName(status));
227 }
228 }
229 status=U_ZERO_ERROR;
230
231
232 /* ======= Test ubrk_countAvialable() and ubrk_getAvialable() */
233
234 log_verbose("\nTesting ubrk_countAvailable() and ubrk_getAvailable()\n");
235 count=ubrk_countAvailable();
236 /* use something sensible w/o hardcoding the count */
237 if(count < 0){
238 log_err("FAIL: Error in ubrk_countAvialable() returned %d\n", count);
239 }
240 else{
241 log_verbose("PASS: ubrk_countAvialable() successful returned %d\n", count);
242 }
243 for(i=0;i<count;i++)
244 {
245 log_verbose("%s\n", ubrk_getAvailable(i));
246 if (ubrk_getAvailable(i) == 0)
247 log_err("No locale for which breakiterator is applicable\n");
248 else
249 log_verbose("A locale %s for which breakiterator is applicable\n",ubrk_getAvailable(i));
250 }
251
252 /*========Test ubrk_first(), ubrk_last()...... and other functions*/
253
254 log_verbose("\nTesting the functions for word\n");
255 start = ubrk_first(word);
256 if(start!=0)
257 log_err("error ubrk_start(word) did not return 0\n");
258 log_verbose("first (word = %d\n", (int32_t)start);
259 pos=ubrk_next(word);
260 if(pos!=4)
261 log_err("error ubrk_next(word) did not return 4\n");
262 log_verbose("next (word = %d\n", (int32_t)pos);
263 pos=ubrk_following(word, 4);
264 if(pos!=5)
265 log_err("error ubrl_following(word,4) did not return 6\n");
266 log_verbose("next (word = %d\n", (int32_t)pos);
267 end=ubrk_last(word);
268 if(end!=49)
269 log_err("error ubrk_last(word) did not return 49\n");
270 log_verbose("last (word = %d\n", (int32_t)end);
271
272 pos=ubrk_previous(word);
273 log_verbose("%d %d\n", end, pos);
274
275 pos=ubrk_previous(word);
276 log_verbose("%d \n", pos);
277
278 if (ubrk_isBoundary(word, 2) != FALSE) {
279 log_err("error ubrk_isBoundary(word, 2) did not return FALSE\n");
280 }
281 pos=ubrk_current(word);
282 if (pos != 4) {
283 log_err("error ubrk_current() != 4 after ubrk_isBoundary(word, 2)\n");
284 }
285 if (ubrk_isBoundary(word, 4) != TRUE) {
286 log_err("error ubrk_isBoundary(word, 4) did not return TRUE\n");
287 }
288
289
290
291 log_verbose("\nTesting the functions for character\n");
292 ubrk_first(character);
293 pos = ubrk_following(character, 5);
294 if(pos!=6)
295 log_err("error ubrk_following(character,5) did not return 6\n");
296 log_verbose("Following (character,5) = %d\n", (int32_t)pos);
297 pos=ubrk_following(character, 18);
298 if(pos!=19)
299 log_err("error ubrk_following(character,18) did not return 19\n");
300 log_verbose("Followingcharacter,18) = %d\n", (int32_t)pos);
301 pos=ubrk_preceding(character, 22);
302 if(pos!=21)
303 log_err("error ubrk_preceding(character,22) did not return 21\n");
304 log_verbose("preceding(character,22) = %d\n", (int32_t)pos);
305
306
307 log_verbose("\nTesting the functions for line\n");
308 pos=ubrk_first(line);
309 if(pos != 0)
310 log_err("error ubrk_first(line) returned %d, expected 0\n", (int32_t)pos);
311 pos = ubrk_next(line);
312 pos=ubrk_following(line, 18);
313 if(pos!=22)
314 log_err("error ubrk_following(line) did not return 22\n");
315 log_verbose("following (line) = %d\n", (int32_t)pos);
316
317
318 log_verbose("\nTesting the functions for sentence\n");
319 pos = ubrk_first(sentence);
320 pos = ubrk_current(sentence);
321 log_verbose("Current(sentence) = %d\n", (int32_t)pos);
322 pos = ubrk_last(sentence);
323 if(pos!=49)
324 log_err("error ubrk_last for sentence did not return 49\n");
325 log_verbose("Last (sentence) = %d\n", (int32_t)pos);
326 pos = ubrk_first(sentence);
327 to = ubrk_following( sentence, 0 );
328 if (to == 0) log_err("ubrk_following returned 0\n");
329 to = ubrk_preceding( sentence, to );
330 if (to != 0) log_err("ubrk_preceding didn't return 0\n");
331 if (ubrk_first(sentence)!=ubrk_current(sentence)) {
332 log_err("error in ubrk_first() or ubrk_current()\n");
333 }
334
335
336 /*---- */
337 /*Testing ubrk_open and ubrk_close()*/
338 log_verbose("\nTesting open and close for us locale\n");
339 b = ubrk_open(UBRK_WORD, "fr_FR", text, u_strlen(text), &status);
340 if (U_FAILURE(status)) {
341 log_err("ubrk_open for word returned NULL: %s\n", myErrorName(status));
342 }
343 ubrk_close(b);
344
345 /* Test setText and setUText */
346 {
347 UChar s1[] = {0x41, 0x42, 0x20, 0};
348 UChar s2[] = {0x41, 0x42, 0x43, 0x44, 0x45, 0};
349 UText *ut = NULL;
350 UBreakIterator *bb;
351 int j;
352
353 log_verbose("\nTesting ubrk_setText() and ubrk_setUText()\n");
354 status = U_ZERO_ERROR;
355 bb = ubrk_open(UBRK_WORD, "en_US", NULL, 0, &status);
356 TEST_ASSERT_SUCCESS(status);
357 ubrk_setText(bb, s1, -1, &status);
358 TEST_ASSERT_SUCCESS(status);
359 ubrk_first(bb);
360 j = ubrk_next(bb);
361 TEST_ASSERT(j == 2);
362 ut = utext_openUChars(ut, s2, -1, &status);
363 ubrk_setUText(bb, ut, &status);
364 TEST_ASSERT_SUCCESS(status);
365 j = ubrk_next(bb);
366 TEST_ASSERT(j == 5);
367
368 ubrk_close(bb);
369 utext_close(ut);
370 }
371
372 ubrk_close(word);
373 ubrk_close(sentence);
374 ubrk_close(line);
375 ubrk_close(character);
376 }
377
378 static void TestBreakIteratorSafeClone(void)
379 {
380 UChar text[51]; /* Keep this odd to test for 64-bit memory alignment */
381 /* NOTE: This doesn't reliably force mis-alignment of following items. */
382 uint8_t buffer [CLONETEST_ITERATOR_COUNT] [U_BRK_SAFECLONE_BUFFERSIZE];
383 int32_t bufferSize = U_BRK_SAFECLONE_BUFFERSIZE;
384
385 UBreakIterator * someIterators [CLONETEST_ITERATOR_COUNT];
386 UBreakIterator * someClonedIterators [CLONETEST_ITERATOR_COUNT];
387
388 UBreakIterator * brk;
389 UErrorCode status = U_ZERO_ERROR;
390 int32_t start,pos;
391 int32_t i;
392
393 /*Testing ubrk_safeClone */
394
395 /* Note: the adjacent "" are concatenating strings, not adding a \" to the
396 string, which is probably what whoever wrote this intended. Don't fix,
397 because it would throw off the hard coded break positions in the following
398 tests. */
399 u_uastrcpy(text, "He's from Africa. ""Mr. Livingston, I presume?"" Yeah");
400
401 /* US & Thai - rule-based & dictionary based */
402 someIterators[0] = ubrk_open(UBRK_WORD, "en_US", text, u_strlen(text), &status);
403 if(!someIterators[0] || U_FAILURE(status)) {
404 log_data_err("Couldn't open en_US word break iterator - %s\n", u_errorName(status));
405 return;
406 }
407
408 someIterators[1] = ubrk_open(UBRK_WORD, "th_TH", text, u_strlen(text), &status);
409 if(!someIterators[1] || U_FAILURE(status)) {
410 log_data_err("Couldn't open th_TH word break iterator - %s\n", u_errorName(status));
411 return;
412 }
413
414 /* test each type of iterator */
415 for (i = 0; i < CLONETEST_ITERATOR_COUNT; i++)
416 {
417
418 /* Check the various error & informational states */
419
420 /* Null status - just returns NULL */
421 if (NULL != ubrk_safeClone(someIterators[i], buffer[i], &bufferSize, NULL))
422 {
423 log_err("FAIL: Cloned Iterator failed to deal correctly with null status\n");
424 }
425 /* error status - should return 0 & keep error the same */
426 status = U_MEMORY_ALLOCATION_ERROR;
427 if (NULL != ubrk_safeClone(someIterators[i], buffer[i], &bufferSize, &status) || status != U_MEMORY_ALLOCATION_ERROR)
428 {
429 log_err("FAIL: Cloned Iterator failed to deal correctly with incoming error status\n");
430 }
431 status = U_ZERO_ERROR;
432
433 /* Null buffer size pointer is ok */
434 if (NULL == (brk = ubrk_safeClone(someIterators[i], buffer[i], NULL, &status)) || U_FAILURE(status))
435 {
436 log_err("FAIL: Cloned Iterator failed to deal correctly with null bufferSize pointer\n");
437 }
438 ubrk_close(brk);
439 status = U_ZERO_ERROR;
440
441 /* buffer size pointer is 0 - fill in pbufferSize with a size */
442 bufferSize = 0;
443 if (NULL != ubrk_safeClone(someIterators[i], buffer[i], &bufferSize, &status) ||
444 U_FAILURE(status) || bufferSize <= 0)
445 {
446 log_err("FAIL: Cloned Iterator failed a sizing request ('preflighting')\n");
447 }
448 /* Verify our define is large enough */
449 if (U_BRK_SAFECLONE_BUFFERSIZE < bufferSize)
450 {
451 log_err("FAIL: Pre-calculated buffer size is too small - %d but needed %d\n", U_BRK_SAFECLONE_BUFFERSIZE, bufferSize);
452 }
453 /* Verify we can use this run-time calculated size */
454 if (NULL == (brk = ubrk_safeClone(someIterators[i], buffer[i], &bufferSize, &status)) || U_FAILURE(status))
455 {
456 log_err("FAIL: Iterator can't be cloned with run-time size\n");
457 }
458 if (brk)
459 ubrk_close(brk);
460 /* size one byte too small - should allocate & let us know */
461 if (bufferSize > 1) {
462 --bufferSize;
463 }
464 if (NULL == (brk = ubrk_safeClone(someIterators[i], NULL, &bufferSize, &status)) || status != U_SAFECLONE_ALLOCATED_WARNING)
465 {
466 log_err("FAIL: Cloned Iterator failed to deal correctly with too-small buffer size\n");
467 }
468 if (brk)
469 ubrk_close(brk);
470 status = U_ZERO_ERROR;
471 bufferSize = U_BRK_SAFECLONE_BUFFERSIZE;
472
473 /* Null buffer pointer - return Iterator & set error to U_SAFECLONE_ALLOCATED_ERROR */
474 if (NULL == (brk = ubrk_safeClone(someIterators[i], NULL, &bufferSize, &status)) || status != U_SAFECLONE_ALLOCATED_WARNING)
475 {
476 log_err("FAIL: Cloned Iterator failed to deal correctly with null buffer pointer\n");
477 }
478 if (brk)
479 ubrk_close(brk);
480 status = U_ZERO_ERROR;
481
482 /* Mis-aligned buffer pointer. */
483 {
484 char stackBuf[U_BRK_SAFECLONE_BUFFERSIZE+sizeof(void *)];
485
486 brk = ubrk_safeClone(someIterators[i], &stackBuf[1], &bufferSize, &status);
487 if (U_FAILURE(status) || brk == NULL) {
488 log_err("FAIL: Cloned Iterator failed with misaligned buffer pointer\n");
489 }
490 if (status == U_SAFECLONE_ALLOCATED_WARNING) {
491 log_verbose("Cloned Iterator allocated when using a mis-aligned buffer.\n");
492 }
493 if (brk)
494 ubrk_close(brk);
495 }
496
497
498 /* Null Iterator - return NULL & set U_ILLEGAL_ARGUMENT_ERROR */
499 if (NULL != ubrk_safeClone(NULL, buffer[i], &bufferSize, &status) || status != U_ILLEGAL_ARGUMENT_ERROR)
500 {
501 log_err("FAIL: Cloned Iterator failed to deal correctly with null Iterator pointer\n");
502 }
503 status = U_ZERO_ERROR;
504
505 /* Do these cloned Iterators work at all - make a first & next call */
506 bufferSize = U_BRK_SAFECLONE_BUFFERSIZE;
507 someClonedIterators[i] = ubrk_safeClone(someIterators[i], buffer[i], &bufferSize, &status);
508
509 start = ubrk_first(someClonedIterators[i]);
510 if(start!=0)
511 log_err("error ubrk_start(clone) did not return 0\n");
512 pos=ubrk_next(someClonedIterators[i]);
513 if(pos!=4)
514 log_err("error ubrk_next(clone) did not return 4\n");
515
516 ubrk_close(someClonedIterators[i]);
517 ubrk_close(someIterators[i]);
518 }
519 }
520 #endif
521
522
523 /*
524 // Open a break iterator from char * rules. Take care of conversion
525 // of the rules and error checking.
526 */
527 static UBreakIterator * testOpenRules(char *rules) {
528 UErrorCode status = U_ZERO_ERROR;
529 UChar *ruleSourceU = NULL;
530 void *strCleanUp = NULL;
531 UParseError parseErr;
532 UBreakIterator *bi;
533
534 ruleSourceU = toUChar(rules, &strCleanUp);
535
536 bi = ubrk_openRules(ruleSourceU, -1, /* The rules */
537 NULL, -1, /* The text to be iterated over. */
538 &parseErr, &status);
539
540 if (U_FAILURE(status)) {
541 log_data_err("FAIL: ubrk_openRules: ICU Error \"%s\" (Are you missing data?)\n", u_errorName(status));
542 bi = 0;
543 };
544 freeToUCharStrings(&strCleanUp);
545 return bi;
546
547 }
548
549 /*
550 * TestBreakIteratorRules - Verify that a break iterator can be created from
551 * a set of source rules.
552 */
553 static void TestBreakIteratorRules() {
554 /* Rules will keep together any run of letters not including 'a', OR
555 * keep together 'abc', but only when followed by 'def', OTHERWISE
556 * just return one char at a time.
557 */
558 char rules[] = "abc/def{666};\n [\\p{L} - [a]]* {2}; . {1};";
559 /* 0123456789012345678 */
560 char data[] = "abcdex abcdefgh-def"; /* the test data string */
561 char breaks[] = "** ** * ** *"; /* * the expected break positions */
562 char tags[] = "01 21 6 21 2"; /* expected tag values at break positions */
563 int32_t tagMap[] = {0, 1, 2, 3, 4, 5, 666};
564
565 UChar *uData;
566 void *freeHook = NULL;
567 UErrorCode status = U_ZERO_ERROR;
568 int32_t pos;
569 int i;
570
571 UBreakIterator *bi = testOpenRules(rules);
572 if (bi == NULL) {return;}
573 uData = toUChar(data, &freeHook);
574 ubrk_setText(bi, uData, -1, &status);
575
576 pos = ubrk_first(bi);
577 for (i=0; i<sizeof(breaks); i++) {
578 if (pos == i && breaks[i] != '*') {
579 log_err("FAIL: unexpected break at position %d found\n", pos);
580 break;
581 }
582 if (pos != i && breaks[i] == '*') {
583 log_err("FAIL: expected break at position %d not found.\n", i);
584 break;
585 }
586 if (pos == i) {
587 int32_t tag, expectedTag;
588 tag = ubrk_getRuleStatus(bi);
589 expectedTag = tagMap[tags[i]&0xf];
590 if (tag != expectedTag) {
591 log_err("FAIL: incorrect tag value. Position = %d; expected tag %d, got %d",
592 pos, expectedTag, tag);
593 break;
594 }
595 pos = ubrk_next(bi);
596 }
597 }
598
599 /* #12914 add basic sanity test for ubrk_getBinaryRules, ubrk_openBinaryRules */
600 /* Underlying functionality checked in C++ rbbiapts.cpp TestRoundtripRules */
601 status = U_ZERO_ERROR;
602 int32_t rulesLength = ubrk_getBinaryRules(bi, NULL, 0, &status); /* preflight */
603 if (U_FAILURE(status)) {
604 log_err("FAIL: ubrk_getBinaryRules preflight err: %s", u_errorName(status));
605 } else {
606 uint8_t* binaryRules = (uint8_t*)uprv_malloc(rulesLength);
607 if (binaryRules == NULL) {
608 log_err("FAIL: unable to malloc rules buffer, size %u", rulesLength);
609 } else {
610 rulesLength = ubrk_getBinaryRules(bi, binaryRules, rulesLength, &status);
611 if (U_FAILURE(status)) {
612 log_err("FAIL: ubrk_getBinaryRules err: %s", u_errorName(status));
613 } else {
614 UBreakIterator* bi2 = ubrk_openBinaryRules(binaryRules, rulesLength, uData, -1, &status);
615 if (U_FAILURE(status)) {
616 log_err("FAIL: ubrk_openBinaryRules err: %s", u_errorName(status));
617 } else {
618 int32_t maxCount = sizeof(breaks); /* fail-safe test limit */
619 int32_t pos2 = ubrk_first(bi2);
620 pos = ubrk_first(bi);
621 do {
622 if (pos2 != pos) {
623 log_err("FAIL: interator from ubrk_openBinaryRules does not match original, get pos = %d instead of %d", pos2, pos);
624 }
625 pos2 = ubrk_next(bi2);
626 pos = ubrk_next(bi);
627 } while ((pos != UBRK_DONE || pos2 != UBRK_DONE) && maxCount-- > 0);
628
629 ubrk_close(bi2);
630 }
631 }
632 uprv_free(binaryRules);
633 }
634 }
635
636 freeToUCharStrings(&freeHook);
637 ubrk_close(bi);
638 }
639
640 static void TestBreakIteratorRuleError() {
641 /*
642 * TestBreakIteratorRuleError - Try to create a BI from rules with syntax errors,
643 * check that the error is reported correctly.
644 */
645 char rules[] = " # This is a rule comment on line 1\n"
646 "[:L:]; # this rule is OK.\n"
647 "abcdefg); # Error, mismatched parens\n";
648 UChar *uRules;
649 void *freeHook = NULL;
650 UErrorCode status = U_ZERO_ERROR;
651 UParseError parseErr;
652 UBreakIterator *bi;
653
654 uRules = toUChar(rules, &freeHook);
655 bi = ubrk_openRules(uRules, -1, /* The rules */
656 NULL, -1, /* The text to be iterated over. */
657 &parseErr, &status);
658 if (U_SUCCESS(status)) {
659 log_err("FAIL: construction of break iterator succeeded when it should have failed.\n");
660 ubrk_close(bi);
661 } else {
662 if (parseErr.line != 3 || parseErr.offset != 8) {
663 log_data_err("FAIL: incorrect error position reported. Got line %d, char %d, expected line 3, char 7 (Are you missing data?)\n",
664 parseErr.line, parseErr.offset);
665 }
666 }
667 freeToUCharStrings(&freeHook);
668 }
669
670
671 /*
672 * TestsBreakIteratorStatusVals() Test the ubrk_getRuleStatusVec() funciton
673 */
674 static void TestBreakIteratorStatusVec() {
675 #define RULE_STRING_LENGTH 200
676 UChar rules[RULE_STRING_LENGTH];
677
678 #define TEST_STRING_LENGTH 25
679 UChar testString[TEST_STRING_LENGTH];
680 UBreakIterator *bi = NULL;
681 int32_t pos = 0;
682 int32_t vals[10];
683 int32_t numVals;
684 UErrorCode status = U_ZERO_ERROR;
685
686 u_uastrncpy(rules, "[A-N]{100}; \n"
687 "[a-w]{200}; \n"
688 "[\\p{L}]{300}; \n"
689 "[\\p{N}]{400}; \n"
690 "[0-5]{500}; \n"
691 "!.*;\n", RULE_STRING_LENGTH);
692 u_uastrncpy(testString, "ABC", TEST_STRING_LENGTH);
693
694
695 bi = ubrk_openRules(rules, -1, testString, -1, NULL, &status);
696 TEST_ASSERT_SUCCESS(status);
697 TEST_ASSERT(bi != NULL);
698
699 /* The TEST_ASSERT above should change too... */
700 if (bi != NULL) {
701 pos = ubrk_next(bi);
702 TEST_ASSERT(pos == 1);
703
704 memset(vals, -1, sizeof(vals));
705 numVals = ubrk_getRuleStatusVec(bi, vals, 10, &status);
706 TEST_ASSERT_SUCCESS(status);
707 TEST_ASSERT(numVals == 2);
708 TEST_ASSERT(vals[0] == 100);
709 TEST_ASSERT(vals[1] == 300);
710 TEST_ASSERT(vals[2] == -1);
711
712 numVals = ubrk_getRuleStatusVec(bi, vals, 0, &status);
713 TEST_ASSERT(status == U_BUFFER_OVERFLOW_ERROR);
714 TEST_ASSERT(numVals == 2);
715 }
716
717 ubrk_close(bi);
718 }
719
720
721 /*
722 * static void TestBreakIteratorUText(void);
723 *
724 * Test that ubrk_setUText() is present and works for a simple case.
725 */
726 static void TestBreakIteratorUText(void) {
727 const char *UTF8Str = "\x41\xc3\x85\x5A\x20\x41\x52\x69\x6E\x67"; /* c3 85 is utf-8 for A with a ring on top */
728 /* 0 1 2 34567890 */
729
730 UErrorCode status = U_ZERO_ERROR;
731 UBreakIterator *bi = NULL;
732 int32_t pos = 0;
733
734
735 UText *ut = utext_openUTF8(NULL, UTF8Str, -1, &status);
736 TEST_ASSERT_SUCCESS(status);
737
738 bi = ubrk_open(UBRK_WORD, "en_US", NULL, 0, &status);
739 if (U_FAILURE(status)) {
740 log_err_status(status, "Failure at file %s, line %d, error = %s\n", __FILE__, __LINE__, u_errorName(status));
741 return;
742 }
743
744 ubrk_setUText(bi, ut, &status);
745 if (U_FAILURE(status)) {
746 log_err("Failure at file %s, line %d, error = %s\n", __FILE__, __LINE__, u_errorName(status));
747 return;
748 }
749
750 pos = ubrk_first(bi);
751 TEST_ASSERT(pos == 0);
752
753 pos = ubrk_next(bi);
754 TEST_ASSERT(pos == 4);
755
756 pos = ubrk_next(bi);
757 TEST_ASSERT(pos == 5);
758
759 pos = ubrk_next(bi);
760 TEST_ASSERT(pos == 10);
761
762 pos = ubrk_next(bi);
763 TEST_ASSERT(pos == UBRK_DONE);
764 ubrk_close(bi);
765 utext_close(ut);
766 }
767
768 /*
769 * static void TestBreakIteratorTailoring(void);
770 *
771 * Test break iterator tailorings from CLDR data.
772 */
773
774 /* Thai/Lao grapheme break tailoring */
775 static const UChar thTest[] = { 0x0020, 0x0E40, 0x0E01, 0x0020,
776 0x0E01, 0x0E30, 0x0020, 0x0E01, 0x0E33, 0x0020, 0 };
777 /*in Unicode 6.1 en should behave just like th for this*/
778 /*static const int32_t thTestOffs_enFwd[] = { 1, 3, 4, 6, 7, 9, 10 };*/
779 static const int32_t thTestOffs_thFwd[] = { 1, 2, 3, 4, 5, 6, 7, 9, 10 };
780 /*static const int32_t thTestOffs_enRev[] = { 9, 7, 6, 4, 3, 1, 0 };*/
781 static const int32_t thTestOffs_thRev[] = { 9, 7, 6, 5, 4, 3, 2, 1, 0 };
782
783 /* Hebrew line break tailoring, for cldrbug 3028 */
784 static const UChar heTest[] = { 0x0020, 0x002D, 0x0031, 0x0032, 0x0020,
785 0x0061, 0x002D, 0x006B, 0x0020,
786 0x0061, 0x0300, 0x2010, 0x006B, 0x0020,
787 0x05DE, 0x05D4, 0x002D, 0x0069, 0x0020,
788 0x05D1, 0x05BC, 0x2010, 0x0047, 0x0020, 0 };
789 /*in Unicode 6.1 en should behave just like he for this*/
790 /*static const int32_t heTestOffs_enFwd[] = { 1, 5, 7, 9, 12, 14, 17, 19, 22, 24 };*/
791 static const int32_t heTestOffs_heFwd[] = { 1, 5, 7, 9, 12, 14, 19, 24 };
792 /*static const int32_t heTestOffs_enRev[] = { 22, 19, 17, 14, 12, 9, 7, 5, 1, 0 };*/
793 static const int32_t heTestOffs_heRev[] = { 19, 14, 12, 9, 7, 5, 1, 0 };
794
795 /* Finnish line break tailoring, for cldrbug 3029 */
796 static const UChar fiTest[] = { /* 00 */ 0x0020, 0x002D, 0x0031, 0x0032, 0x0020,
797 /* 05 */ 0x0061, 0x002D, 0x006B, 0x0020,
798 /* 09 */ 0x0061, 0x0300, 0x2010, 0x006B, 0x0020,
799 /* 14 */ 0x0061, 0x0020, 0x002D, 0x006B, 0x0020,
800 /* 19 */ 0x0061, 0x0300, 0x0020, 0x2010, 0x006B, 0x0020, 0 };
801 static const int32_t fiTestOffs_enFwd[] = { 1, 5, 7, 9, 12, 14, 16, 17, 19, 22, 23, 25 };
802 static const int32_t fiTestOffs_fiFwd[] = { 1, 5, 7, 9, 12, 14, 16, 19, 22, 25 };
803 static const int32_t fiTestOffs_enRev[] = { 23, 22, 19, 17, 16, 14, 12, 9, 7, 5, 1, 0 };
804 static const int32_t fiTestOffs_fiRev[] = { 22, 19, 16, 14, 12, 9, 7, 5, 1, 0 };
805
806 /* Khmer dictionary-based work break, for ICU ticket #8329 */
807 static const UChar kmTest[] = { /* 00 */ 0x179F, 0x17BC, 0x1798, 0x1785, 0x17C6, 0x178E, 0x17B6, 0x1799, 0x1796, 0x17C1,
808 /* 10 */ 0x179B, 0x1794, 0x1793, 0x17D2, 0x178F, 0x17B7, 0x1785, 0x178A, 0x17BE, 0x1798,
809 /* 20 */ 0x17D2, 0x1794, 0x17B8, 0x17A2, 0x1792, 0x17B7, 0x179F, 0x17D2, 0x178B, 0x17B6,
810 /* 30 */ 0x1793, 0x17A2, 0x179A, 0x1796, 0x17D2, 0x179A, 0x17C7, 0x1782, 0x17BB, 0x178E,
811 /* 40 */ 0x178A, 0x179B, 0x17CB, 0x1796, 0x17D2, 0x179A, 0x17C7, 0x17A2, 0x1784, 0x17D2,
812 /* 50 */ 0x1782, 0 };
813 static const int32_t kmTestOffs_kmFwd[] = { 3, /*8,*/ 11, 17, 23, 31, /*33,*/ 40, 43, 51 }; /* TODO: Investigate failure to break at offset 8 */
814 static const int32_t kmTestOffs_kmRev[] = { 43, 40, /*33,*/ 31, 23, 17, 11, /*8,*/ 3, 0 };
815
816
817 /* Korean keepAll vs Normal */
818 static const UChar koTest[] = { /* 00 */ 0xBAA8, 0xB4E0, 0x0020, 0xC778, 0xB958, 0x0020, 0xAD6C, 0xC131, 0xC6D0, 0xC758,
819 /* 10 */ 0x0020, 0xCC9C, 0xBD80, 0xC758, 0x0020, 0xC874, 0xC5C4, 0xC131, 0xACFC, 0x0020,
820 /* 20 */ 0xB3D9, 0xB4F1, 0xD558, 0xACE0, 0x0020, 0xC591, 0xB3C4, 0xD560, 0x002E, 0x8BA1,
821 /* 30 */ 0x7B97, 0x673A, 0x53EA, 0x662F, 0x5904, 0x7406, 0x6570, 0x5B57, 0x3002, 0 }; // 基本上,计算机只是处理数字。
822 static const int32_t koTestOffs_koKeepAllFwd[] = { 3, 6, 11, 15, 20, 25, 29, 39 };
823 static const int32_t koTestOffs_koKeepAllRev[] = { 29, 25, 20, 15, 11, 6, 3, 0 };
824 static const int32_t koTestOffs_koKeepHngFwd[] = { 3, 6, 11, 15, 20, 25, 29, 30, 31, 32, 33, 34, 35, 36, 37, 39 };
825 static const int32_t koTestOffs_koKeepHngRev[] = { 37, 36, 35, 34, 33, 32, 31, 30, 29, 25, 20, 15, 11, 6, 3, 0 };
826 static const int32_t koTestOffs_koNormFwd[] = { 1, 3, 4, 6, 7, 8, 9, 11, 12, 13, 15, 16, 17, 18, 20, 21, 22, 23, 25, 26, 27, 29, 30, 31, 32, 33, 34, 35, 36, 37, 39 };
827 static const int32_t koTestOffs_koNormRev[] = { 37, 36, 35, 34, 33, 32, 31, 30, 29, 27, 26, 25, 23, 22, 21, 20, 18, 17, 16, 15, 13, 12, 11, 9, 8, 7, 6, 4, 3, 1, 0 };
828
829 typedef struct {
830 const char * locale;
831 UBreakIteratorType type;
832 ULineWordOptions lineWordOpts;
833 const UChar * test;
834 const int32_t * offsFwd;
835 const int32_t * offsRev;
836 int32_t numOffsets;
837 } RBBITailoringTest;
838
839 static const RBBITailoringTest tailoringTests[] = {
840 { "en", UBRK_CHARACTER, UBRK_LINEWORD_NORMAL, thTest, thTestOffs_thFwd, thTestOffs_thRev, UPRV_LENGTHOF(thTestOffs_thFwd) },
841 { "en_US_POSIX", UBRK_CHARACTER, UBRK_LINEWORD_NORMAL, thTest, thTestOffs_thFwd, thTestOffs_thRev, UPRV_LENGTHOF(thTestOffs_thFwd) },
842 { "en", UBRK_LINE, UBRK_LINEWORD_NORMAL, heTest, heTestOffs_heFwd, heTestOffs_heRev, UPRV_LENGTHOF(heTestOffs_heFwd) },
843 { "he", UBRK_LINE, UBRK_LINEWORD_NORMAL, heTest, heTestOffs_heFwd, heTestOffs_heRev, UPRV_LENGTHOF(heTestOffs_heFwd) },
844 { "en", UBRK_LINE, UBRK_LINEWORD_NORMAL, fiTest, fiTestOffs_enFwd, fiTestOffs_enRev, UPRV_LENGTHOF(fiTestOffs_enFwd) },
845 { "fi", UBRK_LINE, UBRK_LINEWORD_NORMAL, fiTest, fiTestOffs_fiFwd, fiTestOffs_fiRev, UPRV_LENGTHOF(fiTestOffs_fiFwd) },
846 { "km", UBRK_WORD, UBRK_LINEWORD_NORMAL, kmTest, kmTestOffs_kmFwd, kmTestOffs_kmRev, UPRV_LENGTHOF(kmTestOffs_kmFwd) },
847 { "ko", UBRK_LINE, UBRK_LINEWORD_NORMAL, koTest, koTestOffs_koNormFwd, koTestOffs_koNormRev, UPRV_LENGTHOF(koTestOffs_koNormFwd) },
848 { "ko@lw=keepall", UBRK_LINE, UBRK_LINEWORD_NORMAL, koTest, koTestOffs_koKeepAllFwd, koTestOffs_koKeepAllRev, UPRV_LENGTHOF(koTestOffs_koKeepAllFwd) },
849 { "ko", UBRK_LINE, UBRK_LINEWORD_KEEP_ALL, koTest, koTestOffs_koKeepAllFwd, koTestOffs_koKeepAllRev, UPRV_LENGTHOF(koTestOffs_koKeepAllFwd) },
850 { "ko@lw=keep-hangul", UBRK_LINE, UBRK_LINEWORD_NORMAL, koTest, koTestOffs_koKeepHngFwd, koTestOffs_koKeepHngRev, UPRV_LENGTHOF(koTestOffs_koKeepHngFwd) },
851 { "ko", UBRK_LINE, UBRK_LINEWORD_KEEP_HANGUL, koTest, koTestOffs_koKeepHngFwd, koTestOffs_koKeepHngRev, UPRV_LENGTHOF(koTestOffs_koKeepHngFwd) },
852 { "ko@lw=normal", UBRK_LINE, UBRK_LINEWORD_NORMAL, koTest, koTestOffs_koNormFwd, koTestOffs_koNormRev, UPRV_LENGTHOF(koTestOffs_koNormFwd) },
853 { NULL, 0, 0, NULL, NULL, 0 },
854 };
855
856 static void TestBreakIteratorTailoring(void) {
857 const RBBITailoringTest * testPtr;
858 for (testPtr = tailoringTests; testPtr->locale != NULL; ++testPtr) {
859 UErrorCode status = U_ZERO_ERROR;
860 UBreakIterator* ubrkiter = ubrk_open(testPtr->type, testPtr->locale, testPtr->test, -1, &status);
861 if ( U_SUCCESS(status) ) {
862 int32_t offset, offsindx;
863 UBool foundError;
864
865 if (testPtr->lineWordOpts != UBRK_LINEWORD_NORMAL) {
866 ubrk_setLineWordOpts(ubrkiter, testPtr->lineWordOpts);
867 }
868 foundError = FALSE;
869 ubrk_first(ubrkiter);
870 for (offsindx = 0; (offset = ubrk_next(ubrkiter)) != UBRK_DONE; ++offsindx) {
871 if (!foundError && offsindx >= testPtr->numOffsets) {
872 log_err("FAIL: locale %s, break type %d, ubrk_next expected UBRK_DONE, got %d\n",
873 testPtr->locale, testPtr->type, offset);
874 foundError = TRUE;
875 } else if (!foundError && offset != testPtr->offsFwd[offsindx]) {
876 log_err("FAIL: locale %s, break type %d, ubrk_next expected %d, got %d\n",
877 testPtr->locale, testPtr->type, testPtr->offsFwd[offsindx], offset);
878 foundError = TRUE;
879 }
880 }
881 if (!foundError && offsindx < testPtr->numOffsets) {
882 log_err("FAIL: locale %s, break type %d, ubrk_next expected %d, got UBRK_DONE\n",
883 testPtr->locale, testPtr->type, testPtr->offsFwd[offsindx]);
884 }
885
886 foundError = FALSE;
887 ubrk_last(ubrkiter);
888 for (offsindx = 0; (offset = ubrk_previous(ubrkiter)) != UBRK_DONE; ++offsindx) {
889 if (!foundError && offsindx >= testPtr->numOffsets) {
890 log_err("FAIL: locale %s, break type %d, ubrk_previous expected UBRK_DONE, got %d\n",
891 testPtr->locale, testPtr->type, offset);
892 foundError = TRUE;
893 } else if (!foundError && offset != testPtr->offsRev[offsindx]) {
894 log_err("FAIL: locale %s, break type %d, ubrk_previous expected %d, got %d\n",
895 testPtr->locale, testPtr->type, testPtr->offsRev[offsindx], offset);
896 foundError = TRUE;
897 }
898 }
899 if (!foundError && offsindx < testPtr->numOffsets) {
900 log_err("FAIL: locale %s, break type %d, ubrk_previous expected %d, got UBRK_DONE\n",
901 testPtr->locale, testPtr->type, testPtr->offsRev[offsindx]);
902 }
903
904 ubrk_close(ubrkiter);
905 } else {
906 log_err_status(status, "FAIL: locale %s, break type %d, ubrk_open status: %s\n", testPtr->locale, testPtr->type, u_errorName(status));
907 }
908 }
909 }
910
911
912 static void TestBreakIteratorRefresh(void) {
913 /*
914 * RefreshInput changes out the input of a Break Iterator without
915 * changing anything else in the iterator's state. Used with Java JNI,
916 * when Java moves the underlying string storage. This test
917 * runs a ubrk_next() repeatedly, moving the text in the middle of the sequence.
918 * The right set of boundaries should still be found.
919 */
920 UChar testStr[] = {0x20, 0x41, 0x20, 0x42, 0x20, 0x43, 0x20, 0x44, 0x0}; /* = " A B C D" */
921 UChar movedStr[] = {0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0};
922 UErrorCode status = U_ZERO_ERROR;
923 UBreakIterator *bi;
924 UText ut1 = UTEXT_INITIALIZER;
925 UText ut2 = UTEXT_INITIALIZER;
926
927 bi = ubrk_open(UBRK_LINE, "en_US", NULL, 0, &status);
928 TEST_ASSERT_SUCCESS(status);
929 if (U_FAILURE(status)) {
930 return;
931 }
932
933 utext_openUChars(&ut1, testStr, -1, &status);
934 TEST_ASSERT_SUCCESS(status);
935 ubrk_setUText(bi, &ut1, &status);
936 TEST_ASSERT_SUCCESS(status);
937
938 if (U_SUCCESS(status)) {
939 /* Line boundaries will occur before each letter in the original string */
940 TEST_ASSERT(1 == ubrk_next(bi));
941 TEST_ASSERT(3 == ubrk_next(bi));
942
943 /* Move the string, kill the original string. */
944 u_strcpy(movedStr, testStr);
945 u_memset(testStr, 0x20, u_strlen(testStr));
946 utext_openUChars(&ut2, movedStr, -1, &status);
947 TEST_ASSERT_SUCCESS(status);
948 ubrk_refreshUText(bi, &ut2, &status);
949 TEST_ASSERT_SUCCESS(status);
950
951 /* Find the following matches, now working in the moved string. */
952 TEST_ASSERT(5 == ubrk_next(bi));
953 TEST_ASSERT(7 == ubrk_next(bi));
954 TEST_ASSERT(8 == ubrk_next(bi));
955 TEST_ASSERT(UBRK_DONE == ubrk_next(bi));
956 TEST_ASSERT_SUCCESS(status);
957
958 utext_close(&ut1);
959 utext_close(&ut2);
960 }
961 ubrk_close(bi);
962 }
963
964
965 static void TestBug11665(void) {
966 // The problem was with the incorrect breaking of Japanese text beginning
967 // with Katakana characters when no prior Japanese or Chinese text had been
968 // encountered.
969 //
970 // Tested here in cintltst, rather than in intltest, because only cintltst
971 // tests have the ability to reset ICU, which is needed to get the bug
972 // to manifest itself.
973
974 static UChar japaneseText[] = {0x30A2, 0x30EC, 0x30EB, 0x30AE, 0x30FC, 0x6027, 0x7D50, 0x819C, 0x708E};
975 int32_t boundaries[10] = {0};
976 UBreakIterator *bi = NULL;
977 int32_t brk;
978 int32_t brkIdx = 0;
979 int32_t totalBreaks = 0;
980 UErrorCode status = U_ZERO_ERROR;
981
982 ctest_resetICU();
983 bi = ubrk_open(UBRK_WORD, "en_US", japaneseText, UPRV_LENGTHOF(japaneseText), &status);
984 TEST_ASSERT_SUCCESS(status);
985 if (!bi) {
986 return;
987 }
988 for (brk=ubrk_first(bi); brk != UBRK_DONE; brk=ubrk_next(bi)) {
989 boundaries[brkIdx] = brk;
990 if (++brkIdx >= UPRV_LENGTHOF(boundaries) - 1) {
991 break;
992 }
993 }
994 if (brkIdx <= 2 || brkIdx >= UPRV_LENGTHOF(boundaries)) {
995 log_err("%s:%d too few or many breaks found.\n", __FILE__, __LINE__);
996 } else {
997 totalBreaks = brkIdx;
998 brkIdx = 0;
999 for (brk=ubrk_first(bi); brk != UBRK_DONE; brk=ubrk_next(bi)) {
1000 if (brk != boundaries[brkIdx]) {
1001 log_err("%s:%d Break #%d differs between first and second iteration.\n", __FILE__, __LINE__, brkIdx);
1002 break;
1003 }
1004 if (++brkIdx >= UPRV_LENGTHOF(boundaries) - 1) {
1005 log_err("%s:%d Too many breaks.\n", __FILE__, __LINE__);
1006 break;
1007 }
1008 }
1009 if (totalBreaks != brkIdx) {
1010 log_err("%s:%d Number of breaks differ between first and second iteration.\n", __FILE__, __LINE__);
1011 }
1012 }
1013 ubrk_close(bi);
1014 }
1015
1016 /*
1017 * expOffset is the set of expected offsets, ending with '-1'.
1018 * "Expected expOffset -1" means "expected the end of the offsets"
1019 */
1020
1021 static const char testSentenceSuppressionsEn[] = "Mr. Jones comes home. Dr. Smith Ph.D. is out. In the U.S.A. it is hot.";
1022 static const int32_t testSentSuppFwdOffsetsEn[] = { 22, 46, 70, -1 }; /* With suppressions */
1023 static const int32_t testSentFwdOffsetsEn[] = { 4, 22, 26, 46, 70, -1 }; /* Without suppressions */
1024 static const int32_t testSentSuppRevOffsetsEn[] = { 46, 22, 0, -1 }; /* With suppressions */
1025 static const int32_t testSentRevOffsetsEn[] = { 46, 26, 22, 4, 0, -1 }; /* Without suppressions */
1026
1027 static const char testSentenceSuppressionsDe[] = "Wenn ich schon h\\u00F6re zu Guttenberg kommt evtl. zur\\u00FCck.";
1028 // "Wenn ich schon höre zu Guttenberg kommt evtl. zurück."
1029 static const int32_t testSentSuppFwdOffsetsDe[] = { 53, -1 }; /* With suppressions */
1030 static const int32_t testSentFwdOffsetsDe[] = { 53, -1 }; /* Without suppressions; no break in evtl. zur due to casing */
1031 static const int32_t testSentSuppRevOffsetsDe[] = { 0, -1 }; /* With suppressions */
1032 static const int32_t testSentRevOffsetsDe[] = { 0, -1 }; /* Without suppressions */
1033
1034 static const char testSentenceSuppressionsEs[] = "Te esperamos todos los miercoles en Bravo 416, Col. El Pueblo a las 7 PM.";
1035 static const int32_t testSentSuppFwdOffsetsEs[] = { 73, -1 }; /* With suppressions */
1036 static const int32_t testSentFwdOffsetsEs[] = { 52, 73, -1 }; /* Without suppressions */
1037 static const int32_t testSentSuppRevOffsetsEs[] = { 0, -1 }; /* With suppressions */
1038 static const int32_t testSentRevOffsetsEs[] = { 52, 0, -1 }; /* Without suppressions */
1039
1040 static const char testSentenceSuppressionsE1[] = "Add or detract. The world will little note.";
1041 static const char testSentenceSuppressionsE1u[] = "ADD OR DETRACT. THE WORLD WILL LITTLE NOTE.";
1042 static const int32_t testSentFwdOffsetsE1[] = { 16, 43, -1 }; /* Suppressions and case should make no difference */
1043 static const int32_t testSentRevOffsetsE1[] = { 16, 0, -1 }; /* Suppressions and case should make no difference */
1044
1045 static const char testSentenceSuppressionsE2[] = "Coming up, the sprints at NCAA. Are you watching?";
1046 static const char testSentenceSuppressionsE2u[] = "COMING UP, THE SPRINTS AT NCAA. ARE YOU WATCHING?";
1047 static const int32_t testSentFwdOffsetsE2[] = { 32, 49, -1 }; /* Suppressions and case should make no difference */
1048 static const int32_t testSentRevOffsetsE2[] = { 32, 0, -1 }; /* Suppressions and case should make no difference */
1049
1050 static const char testSentenceSuppressionsFr[] = "Tr\\u00E8s bonne prise de parole de M. Junod, municipal \\u00E0 la culture de Lausanne.";
1051 // "Très bonne prise de parole de M. Junod, municipal à la culture de Lausanne."
1052 static const int32_t testSentFwdOffsetsFr[] = { 33, 75, -1 }; /* Without suppressions */
1053 static const int32_t testSentSuppFwdOffsetsFr[] = { 75, -1 }; /* With suppressions */
1054 static const int32_t testSentRevOffsetsFr[] = { 33, 0, -1 }; /* Without suppressions */
1055 static const int32_t testSentSuppRevOffsetsFr[] = { 0, -1 }; /* With suppressions */
1056
1057 static const char testSentenceSuppressionsE3[] = "G8 countries e.g. U.K., Japan. Sanctions i.e. restrictions. Test E. Xx G. Xx I. Xx.";
1058 static const char testSentenceSuppressionsE3u[] = "G8 COUNTRIES E.G. U.K., JAPAN. SANCTIONS I.E. RESTRICTIONS. TEST E. XX G. XX I. XX.";
1059 static const int32_t testSentSuppFwdOffsetsE3[] = { 31, 60, 83, -1 }; /* With suppressions */
1060 static const int32_t testSentSuppRevOffsetsE3[] = { 60, 31, 0, -1 }; /* With suppressions */
1061 static const int32_t testSentFwdOffsetsE3[] = { 18, 31, 60, 68, 74, 80, 83, -1 }; /* Without suppressions */
1062 static const int32_t testSentRevOffsetsE3[] = { 80, 74, 68, 60, 31, 18, 0, -1 }; /* Without suppressions */
1063 static const int32_t testSentFwdOffsetsE3u[] = { 18, 31, 46, 60, 68, 74, 80, 83, -1 }; /* Without suppressions */
1064 static const int32_t testSentRevOffsetsE3u[] = { 80, 74, 68, 60, 46, 31, 18, 0, -1 }; /* Without suppressions */
1065
1066 enum { kTextULenMax = 128, kTextBLenMax = 192 };
1067
1068 typedef struct {
1069 const char * locale;
1070 const char * text;
1071 const int32_t * expFwdOffsets;
1072 const int32_t * expRevOffsets;
1073 } TestBISuppressionsItem;
1074
1075 static const TestBISuppressionsItem testBISuppressionsItems[] = {
1076 { "en@ss=standard", testSentenceSuppressionsEn, testSentSuppFwdOffsetsEn, testSentSuppRevOffsetsEn },
1077 { "en", testSentenceSuppressionsEn, testSentFwdOffsetsEn, testSentRevOffsetsEn },
1078 { "en_CA", testSentenceSuppressionsEn, testSentFwdOffsetsEn, testSentRevOffsetsEn },
1079 { "en_CA@ss=standard", testSentenceSuppressionsEn, testSentSuppFwdOffsetsEn, testSentSuppRevOffsetsEn },
1080 { "fr@ss=standard", testSentenceSuppressionsEn, testSentFwdOffsetsEn, testSentRevOffsetsEn },
1081 { "af@ss=standard", testSentenceSuppressionsEn, testSentFwdOffsetsEn, testSentRevOffsetsEn }, /* no brkiter data => nosuppressions? */
1082 { "af_ZA@ss=standard", testSentenceSuppressionsEn, testSentFwdOffsetsEn, testSentRevOffsetsEn }, /* no brkiter data => nosuppressions? */
1083 { "zh@ss=standard", testSentenceSuppressionsEn, testSentFwdOffsetsEn, testSentRevOffsetsEn }, /* brkiter data, no suppressions data => no suppressions */
1084 { "zh_Hant@ss=standard", testSentenceSuppressionsEn, testSentFwdOffsetsEn, testSentRevOffsetsEn }, /* brkiter data, no suppressions data => no suppressions */
1085 { "fi@ss=standard", testSentenceSuppressionsEn, testSentFwdOffsetsEn, testSentRevOffsetsEn }, /* brkiter data, no suppressions data => no suppressions */
1086 { "ja@ss=standard", testSentenceSuppressionsEn, testSentFwdOffsetsEn, testSentRevOffsetsEn }, /* brkiter data, no suppressions data => no suppressions */
1087 { "de@ss=standard", testSentenceSuppressionsDe, testSentSuppFwdOffsetsDe, testSentSuppRevOffsetsDe },
1088 { "de", testSentenceSuppressionsDe, testSentFwdOffsetsDe, testSentRevOffsetsDe },
1089 { "es@ss=standard", testSentenceSuppressionsEs, testSentSuppFwdOffsetsEs, testSentSuppRevOffsetsEs },
1090 { "es", testSentenceSuppressionsEs, testSentFwdOffsetsEs, testSentRevOffsetsEs },
1091 { "en", testSentenceSuppressionsE1, testSentFwdOffsetsE1, testSentRevOffsetsE1 },
1092 { "en@ss=standard", testSentenceSuppressionsE1, testSentFwdOffsetsE1, testSentRevOffsetsE1 },
1093 { "en", testSentenceSuppressionsE1u, testSentFwdOffsetsE1, testSentRevOffsetsE1 },
1094 { "en@ss=standard", testSentenceSuppressionsE1u, testSentFwdOffsetsE1, testSentRevOffsetsE1 },
1095 { "en", testSentenceSuppressionsE2, testSentFwdOffsetsE2, testSentRevOffsetsE2 },
1096 { "en@ss=standard", testSentenceSuppressionsE2, testSentFwdOffsetsE2, testSentRevOffsetsE2 },
1097 { "en", testSentenceSuppressionsE2u, testSentFwdOffsetsE2, testSentRevOffsetsE2 },
1098 { "en@ss=standard", testSentenceSuppressionsE2u, testSentFwdOffsetsE2, testSentRevOffsetsE2 },
1099 { "fr", testSentenceSuppressionsFr, testSentFwdOffsetsFr, testSentRevOffsetsFr },
1100 { "fr@ss=standard", testSentenceSuppressionsFr, testSentSuppFwdOffsetsFr, testSentSuppRevOffsetsFr },
1101 { "en@ss=standard", testSentenceSuppressionsE3, testSentSuppFwdOffsetsE3, testSentSuppRevOffsetsE3 },
1102 { "en", testSentenceSuppressionsE3, testSentFwdOffsetsE3, testSentRevOffsetsE3 },
1103 { "en@ss=standard", testSentenceSuppressionsE3u, testSentSuppFwdOffsetsE3, testSentSuppRevOffsetsE3 },
1104 { "en", testSentenceSuppressionsE3u, testSentFwdOffsetsE3u, testSentRevOffsetsE3u },
1105 { NULL, NULL, NULL }
1106 };
1107
1108 static void TestBreakIteratorSuppressions(void) {
1109 const TestBISuppressionsItem * itemPtr;
1110
1111 for (itemPtr = testBISuppressionsItems; itemPtr->locale != NULL; itemPtr++) {
1112 UChar textU[kTextULenMax + 1];
1113 char textB[kTextBLenMax];
1114 int32_t textULen = u_unescape(itemPtr->text, textU, kTextULenMax);
1115 textU[kTextULenMax] = 0; // ensure zero termination
1116 UErrorCode status = U_ZERO_ERROR;
1117 UBreakIterator *bi = ubrk_open(UBRK_SENTENCE, itemPtr->locale, textU, textULen, &status);
1118 log_verbose("#%d: %s\n", (itemPtr-testBISuppressionsItems), itemPtr->locale);
1119 if (U_SUCCESS(status)) {
1120 int32_t offset, start;
1121 const int32_t * expOffsetPtr;
1122 const int32_t * expOffsetStart;
1123 u_austrcpy(textB, textU);
1124
1125 expOffsetStart = expOffsetPtr = itemPtr->expFwdOffsets;
1126 ubrk_first(bi);
1127 for (; (offset = ubrk_next(bi)) != UBRK_DONE && *expOffsetPtr >= 0; expOffsetPtr++) {
1128 if (offset != *expOffsetPtr) {
1129 log_err("FAIL: ubrk_next loc \"%s\", expected %d, got %d, text \"%s\"\n",
1130 itemPtr->locale, *expOffsetPtr, offset, textB);
1131 }
1132 }
1133 if (offset != UBRK_DONE || *expOffsetPtr >= 0) {
1134 log_err("FAIL: ubrk_next loc \"%s\", expected UBRK_DONE & expOffset -1, got %d and %d, text \"%s\"\n",
1135 itemPtr->locale, offset, *expOffsetPtr, textB);
1136 }
1137
1138 expOffsetStart = expOffsetPtr = itemPtr->expFwdOffsets;
1139 start = ubrk_first(bi) + 1;
1140 for (; (offset = ubrk_following(bi, start)) != UBRK_DONE && *expOffsetPtr >= 0; expOffsetPtr++) {
1141 if (offset != *expOffsetPtr) {
1142 log_err("FAIL: ubrk_following(%d) loc \"%s\", expected %d, got %d, text \"%s\"\n",
1143 start, itemPtr->locale, *expOffsetPtr, offset, textB);
1144 }
1145 start = *expOffsetPtr + 1;
1146 }
1147 if (offset != UBRK_DONE || *expOffsetPtr >= 0) {
1148 log_err("FAIL: ubrk_following(%d) loc \"%s\", expected UBRK_DONE & expOffset -1, got %d and %d, text \"%s\"\n",
1149 start, itemPtr->locale, offset, *expOffsetPtr, textB);
1150 }
1151
1152 expOffsetStart = expOffsetPtr = itemPtr->expRevOffsets;
1153 offset = ubrk_last(bi);
1154 log_verbose("___ @%d ubrk_last\n", offset);
1155 if(offset == 0) {
1156 log_err("FAIL: ubrk_last loc \"%s\" unexpected %d\n", itemPtr->locale, offset);
1157 }
1158 for (; (offset = ubrk_previous(bi)) != UBRK_DONE && *expOffsetPtr >= 0; expOffsetPtr++) {
1159 if (offset != *expOffsetPtr) {
1160 log_err("FAIL: ubrk_previous loc \"%s\", expected %d, got %d, text \"%s\"\n",
1161 itemPtr->locale, *expOffsetPtr, offset, textB);
1162 } else {
1163 log_verbose("[%d] @%d ubrk_previous()\n", (expOffsetPtr - expOffsetStart), offset);
1164 }
1165 }
1166 if (offset != UBRK_DONE || *expOffsetPtr >= 0) {
1167 log_err("FAIL: ubrk_previous loc \"%s\", expected UBRK_DONE & expOffset[%d] -1, got %d and %d, text \"%s\"\n",
1168 itemPtr->locale, expOffsetPtr - expOffsetStart, offset, *expOffsetPtr, textB);
1169 }
1170
1171 expOffsetStart = expOffsetPtr = itemPtr->expRevOffsets;
1172 start = ubrk_last(bi) - 1;
1173 for (; (offset = ubrk_preceding(bi, start)) != UBRK_DONE && *expOffsetPtr >= 0; expOffsetPtr++) {
1174 if (offset != *expOffsetPtr) {
1175 log_err("FAIL: ubrk_preceding(%d) loc \"%s\", expected %d, got %d, text \"%s\"\n",
1176 start, itemPtr->locale, *expOffsetPtr, offset, textB);
1177 }
1178 start = *expOffsetPtr - 1;
1179 }
1180 if (start >=0 && (offset != UBRK_DONE || *expOffsetPtr >= 0)) {
1181 log_err("FAIL: ubrk_preceding loc(%d) \"%s\", expected UBRK_DONE & expOffset -1, got %d and %d, text \"%s\"\n",
1182 start, itemPtr->locale, offset, *expOffsetPtr, textB);
1183 }
1184
1185 ubrk_close(bi);
1186 } else {
1187 log_data_err("FAIL: ubrk_open(UBRK_SENTENCE, \"%s\", ...) status %s (Are you missing data?)\n",
1188 itemPtr->locale, u_errorName(status));
1189 }
1190 }
1191 }
1192
1193 #if APPLE_ADDITIONS
1194 #include <stdio.h>
1195 #include <unistd.h>
1196 #include "unicode/urbtok.h"
1197 #include "cstring.h"
1198 #if U_PLATFORM_IS_DARWIN_BASED
1199 #include <mach/mach_time.h>
1200 #define GET_START() mach_absolute_time()
1201 #define GET_DURATION(start, info) ((mach_absolute_time() - start) * info.numer)/info.denom
1202 #else
1203 #include "putilimp.h"
1204 #define GET_START() (uint64_t)uprv_getUTCtime()
1205 #define GET_DURATION(start, info) ((uint64_t)uprv_getUTCtime() - start)
1206 #endif
1207
1208 typedef struct {
1209 RuleBasedTokenRange token;
1210 unsigned long flags;
1211 } RBTokResult;
1212
1213 static const UChar tokTextLatn[] = {
1214 /*
1215 "Short phrase! Another (with parens); done.\n
1216 At 4:00, tea-time.\n
1217 He wouldn't've wanted y'all to ... come at 3:30pm for $3 coffee @funman :)\n
1218 x3:30 -- x1.0"
1219 */
1220 0x53,0x68,0x6F,0x72,0x74,0x20,0x70,0x68,0x72,0x61,0x73,0x65,0x21,0x20,
1221 0x41,0x6E,0x6F,0x74,0x68,0x65,0x72,0x20,0x28,0x77,0x69,0x74,0x68,0x20,0x70,0x61,0x72,0x65,0x6E,0x73,0x29,0x3B,0x20,0x64,0x6F,0x6E,0x65,0x2E,0x0A,
1222 0x41,0x74,0x20,0x34,0x3A,0x30,0x30,0x2C,0x20,0x74,0x65,0x61,0x2D,0x74,0x69,0x6D,0x65,0x2E,0x0A,
1223 0x48,0x65,0x20,0x77,0x6F,0x75,0x6C,0x64,0x6E,0x27,0x74,0x27,0x76,0x65,0x20,0x77,0x61,0x6E,0x74,0x65,0x64,0x20,
1224 0x79,0x27,0x61,0x6C,0x6C,0x20,0x74,0x6F,0x20,0x2E,0x2E,0x2E,0x20, 0x63,0x6F,0x6D,0x65,0x20,0x61,0x74,0x20,
1225 0x33,0x3A,0x33,0x30,0x70,0x6D,0x20,0x66,0x6F,0x72,0x20,0x24,0x33,0x20,0x63,0x6F,0x66,0x66,0x65,0x65,0x20,
1226 0x40,0x66,0x75,0x6E,0x6D,0x61,0x6E,0x20,0x3A,0x29,0x0A,
1227 0x78,0x33,0x3A,0x33,0x30,0x20,0x2D,0x2D,0x20,0x78,0x31,0x2E,0x30,0
1228 };
1229
1230
1231 static const RBTokResult expTokLatnCFST[] = { // 26 tokens
1232 { { 0, 5 }, 0x002 }, // Short
1233 { { 6, 7 }, 0x020 }, // phrase!
1234 { { 14, 7 }, 0x002 }, // Another
1235 { { 22, 5 }, 0x020 }, // (with
1236 { { 28, 8 }, 0x020 }, // parens);
1237 { { 37, 5 }, 0x020 }, // done.
1238 { { 43, 2 }, 0x002 }, //
1239 { { 46, 5 }, 0x030 }, //
1240 { { 52, 9 }, 0x020 }, //
1241 { { 62, 2 }, 0x002 }, //
1242 { { 65, 11 }, 0x020 }, //
1243 { { 77, 6 }, 0x000 }, //
1244 { { 84, 5 }, 0x020 }, //
1245 { { 90, 2 }, 0x000 }, //
1246 { { 93, 3 }, 0x020 }, //
1247 { { 97, 4 }, 0x000 }, //
1248 { { 102, 2 }, 0x000 }, //
1249 { { 105, 6 }, 0x030 }, //
1250 { { 112, 3 }, 0x000 }, //
1251 { { 116, 2 }, 0x030 }, //
1252 { { 119, 6 }, 0x000 }, //
1253 { { 126, 7 }, 0x020 }, //
1254 { { 134, 2 }, 0x020 }, //
1255 { { 137, 5 }, 0x030 }, //
1256 { { 143, 2 }, 0x020 }, //
1257 { { 146, 4 }, 0x030 }, //
1258 };
1259
1260 // The following was expTokLatnNLLT for ICU 61-based Apple ICU
1261 static const RBTokResult expTokLatnNLLT_Old[] = { // 66 tokens
1262 { { 0, 5 }, 0xC8 }, // Short
1263 { { 5, 1 }, 0x00 }, // _sp_
1264 { { 6, 6 }, 0xC8 }, // phrase
1265 { { 12, 1 }, 0x00 }, // !
1266 { { 13, 1 }, 0x00 }, // _sp_
1267 { { 14, 7 }, 0xC8 }, // Another
1268 { { 21, 1 }, 0x00 }, // _sp_
1269 { { 22, 1 }, 0x00 }, // (
1270 { { 23, 4 }, 0xC8 }, // with
1271 { { 27, 1 }, 0x00 }, // _sp_
1272 { { 28, 6 }, 0xC8 }, // parens
1273 { { 34, 1 }, 0x00 }, // )
1274 { { 35, 1 }, 0x00 }, // ;
1275 { { 36, 1 }, 0x00 }, // _sp_
1276 { { 37, 4 }, 0xC8 }, // done
1277 { { 41, 1 }, 0x14 }, // .
1278 { { 42, 1 }, 0x00 }, // _nl_
1279
1280 { { 43, 2 }, 0xC8 }, // At
1281 { { 45, 1 }, 0x00 }, // _sp_
1282 { { 46, 4 }, 0x76 }, // 4:00
1283 { { 50, 1 }, 0x00 }, // ,
1284 { { 51, 1 }, 0x00 }, // _sp_
1285 { { 52, 3 }, 0xC8 }, // tea
1286 { { 55, 1 }, 0x15 }, // -
1287 { { 56, 4 }, 0xC8 }, // time
1288 { { 60, 1 }, 0x14 }, // .
1289 { { 61, 1 }, 0x00 }, // _nl_
1290
1291 { { 62, 2 }, 0xC8 }, // He
1292 { { 64, 1 }, 0x00 }, // _sp_
1293 { { 65, 8 }, 0xCA }, // wouldn't
1294 { { 73, 1 }, 0x16 }, // '
1295 { { 74, 2 }, 0xC8 }, // ve
1296 { { 76, 1 }, 0x00 }, // _sp_
1297 { { 77, 6 }, 0xC8 }, // wanted
1298 { { 83, 1 }, 0x00 }, // _sp_
1299 { { 84, 5 }, 0xCA }, // y'all
1300 { { 89, 1 }, 0x00 }, // _sp_
1301 { { 90, 2 }, 0xC8 }, // to
1302 { { 92, 1 }, 0x00 }, // _sp_
1303 { { 93, 3 }, 0x3C }, // ...
1304 { { 96, 1 }, 0x00 }, // _sp_
1305 { { 97, 4 }, 0xC8 }, // come
1306 { { 101, 1 }, 0x00 }, // _sp_
1307 { { 102, 2 }, 0xC8 }, // at
1308 { { 104, 1 }, 0x00 }, // _sp_
1309 { { 105, 4 }, 0xC8 }, // 3:30
1310 { { 109, 2 }, 0xC8 }, // pm
1311 { { 111, 1 }, 0x00 }, // _sp_
1312 { { 112, 3 }, 0xC8 }, // for
1313 { { 115, 1 }, 0x00 }, // _sp_
1314 { { 116, 1 }, 0x00 }, // $
1315 { { 117, 1 }, 0x64 }, // 3
1316 { { 118, 1 }, 0x00 }, // _sp_
1317 { { 119, 6 }, 0xC8 }, // coffee
1318 { { 125, 1 }, 0x00 }, // _sp_
1319 { { 126, 7 }, 0xDF }, // @funman
1320 { { 133, 1 }, 0x00 }, // _sp_
1321 { { 134, 2 }, 0x20 }, // :)
1322 { { 136, 1 }, 0x00 }, // _nl_
1323 { { 137, 1 }, 0x76 }, // x
1324 { { 138, 4 }, 0x76 }, // 3:30
1325 { { 142, 1 }, 0x00 }, // _sp_
1326 { { 143, 2 }, 0x3D }, // --
1327 { { 145, 1 }, 0x00 }, // _sp_
1328 { { 146, 1 }, 0x77 }, // x
1329 { { 147, 3 }, 0x77 }, // 1.0
1330 };
1331
1332 // For ICU 62-based Apple ICU, expTokLatnNLLT matches expTokLatnNLLT_File
1333 #define expTokLatnNLLT expTokLatnNLLT_File
1334 static const RBTokResult expTokLatnNLLT_File[] = { // 67 tokens
1335 { { 0, 5 }, 0xC8 }, // Short
1336 { { 5, 1 }, 0x00 }, // _sp_
1337 { { 6, 6 }, 0xC8 }, // phrase
1338 { { 12, 1 }, 0x00 }, // !
1339 { { 13, 1 }, 0x00 }, // _sp_
1340 { { 14, 7 }, 0xC8 }, // Another
1341 { { 21, 1 }, 0x00 }, // _sp_
1342 { { 22, 1 }, 0x00 }, // (
1343 { { 23, 4 }, 0xC8 }, // with
1344 { { 27, 1 }, 0x00 }, // _sp_
1345 { { 28, 6 }, 0xC8 }, // parens
1346 { { 34, 1 }, 0x00 }, // )
1347 { { 35, 1 }, 0x00 }, // ;
1348 { { 36, 1 }, 0x00 }, // _sp_
1349 { { 37, 4 }, 0xC8 }, // done
1350 { { 41, 1 }, 0x14 }, // .
1351 { { 42, 1 }, 0x00 }, // _nl_
1352
1353 { { 43, 2 }, 0xC8 }, // At
1354 { { 45, 1 }, 0x00 }, // _sp_
1355 { { 46, 4 }, 0x76 }, // 4:00
1356 { { 50, 1 }, 0x00 }, // ,
1357 { { 51, 1 }, 0x00 }, // _sp_
1358 { { 52, 3 }, 0xC8 }, // tea
1359 { { 55, 1 }, 0x15 }, // -
1360 { { 56, 4 }, 0xC8 }, // time
1361 { { 60, 1 }, 0x14 }, // .
1362 { { 61, 1 }, 0x00 }, // _nl_
1363
1364 { { 62, 2 }, 0xC8 }, // He
1365 { { 64, 1 }, 0x00 }, // _sp_
1366 { { 65, 8 }, 0xCA }, // wouldn't
1367 { { 73, 1 }, 0x16 }, // '
1368 { { 74, 2 }, 0xC8 }, // ve
1369 { { 76, 1 }, 0x00 }, // _sp_
1370 { { 77, 6 }, 0xC8 }, // wanted
1371 { { 83, 1 }, 0x00 }, // _sp_
1372 { { 84, 5 }, 0xCA }, // y'all
1373 { { 89, 1 }, 0x00 }, // _sp_
1374 { { 90, 2 }, 0xC8 }, // to
1375 { { 92, 1 }, 0x00 }, // _sp_
1376 { { 93, 3 }, 0x3C }, // ...
1377 { { 96, 1 }, 0x00 }, // _sp_
1378 { { 97, 4 }, 0xC8 }, // come
1379 { { 101, 1 }, 0x00 }, // _sp_
1380 { { 102, 2 }, 0xC8 }, // at
1381 { { 104, 1 }, 0x00 }, // _sp_
1382 { { 105, 4 }, 0xC8 }, // 3:30
1383 { { 109, 2 }, 0xC8 }, // pm
1384 { { 111, 1 }, 0x00 }, // _sp_
1385 { { 112, 3 }, 0xC8 }, // for
1386 { { 115, 1 }, 0x00 }, // _sp_
1387 { { 116, 1 }, 0x00 }, // $
1388 { { 117, 1 }, 0x64 }, // 3
1389 { { 118, 1 }, 0x00 }, // _sp_
1390 { { 119, 6 }, 0xC8 }, // coffee
1391 { { 125, 1 }, 0x00 }, // _sp_
1392 { { 126, 7 }, 0xDF }, // @funman
1393 { { 133, 1 }, 0x00 }, // _sp_
1394 { { 134, 2 }, 0x20 }, // :)
1395 { { 136, 1 }, 0x00 }, // _nl_
1396 { { 137, 1 }, 0x76 }, // x
1397 { { 138, 4 }, 0x76 }, // 3:30
1398 { { 142, 1 }, 0x00 }, // _sp_
1399 { { 143, 2 }, 0x3D }, // --
1400 { { 145, 1 }, 0x00 }, // _sp_
1401 { { 146, 2 }, 0xEC }, // x1
1402 { { 148, 1 }, 0x14 }, // .
1403 { { 149, 1 }, 0x64 }, // 0
1404 };
1405
1406 static const RBTokResult expTokLatnNLLT_57[] = { // 67 tokens
1407 { { 0, 5 }, 0xC8 }, //
1408 { { 5, 1 }, 0x00 }, //
1409 { { 6, 6 }, 0xC8 }, //
1410 { { 12, 1 }, 0x00 }, //
1411 { { 13, 1 }, 0x00 }, //
1412 { { 14, 7 }, 0xC8 }, //
1413 { { 21, 1 }, 0x00 }, //
1414 { { 22, 1 }, 0x00 }, //
1415 { { 23, 4 }, 0xC8 }, //
1416 { { 27, 1 }, 0x00 }, //
1417 { { 28, 6 }, 0xC8 }, //
1418 { { 34, 1 }, 0x00 }, //
1419 { { 35, 1 }, 0x00 }, //
1420 { { 36, 1 }, 0x00 }, //
1421 { { 37, 4 }, 0xC8 }, //
1422 { { 41, 1 }, 0x14 }, //
1423 { { 42, 1 }, 0x00 }, //
1424
1425 { { 43, 2 }, 0xC8 }, //
1426 { { 45, 1 }, 0x00 }, //
1427 { { 46, 4 }, 0x76 }, //
1428 { { 50, 1 }, 0x00 }, //
1429 { { 51, 1 }, 0x00 }, //
1430 { { 52, 3 }, 0xC8 }, //
1431 { { 55, 1 }, 0x15 }, //
1432 { { 56, 4 }, 0xC8 }, //
1433 { { 60, 1 }, 0x14 }, //
1434 { { 61, 1 }, 0x00 }, //
1435
1436 { { 62, 2 }, 0xC8 }, //
1437 { { 64, 1 }, 0x00 }, //
1438 { { 65, 8 }, 0xCA }, //
1439 { { 73, 1 }, 0x16 }, //
1440 { { 74, 2 }, 0xC8 }, //
1441 { { 76, 1 }, 0x00 }, //
1442 { { 77, 6 }, 0xC8 }, //
1443 { { 83, 1 }, 0x00 }, //
1444 { { 84, 5 }, 0xCA }, //
1445 { { 89, 1 }, 0x00 }, //
1446 { { 90, 2 }, 0xC8 }, //
1447 { { 92, 1 }, 0x00 }, //
1448 { { 93, 3 }, 0x3C }, //
1449 { { 96, 1 }, 0x00 }, //
1450 { { 97, 4 }, 0xC8 }, //
1451 { { 101, 1 }, 0x00 }, //
1452 { { 102, 2 }, 0xC8 }, //
1453 { { 104, 1 }, 0x00 }, //
1454 { { 105, 6 }, 0xC8 }, //
1455 { { 111, 1 }, 0x00 }, //
1456 { { 112, 3 }, 0xC8 }, //
1457 { { 115, 1 }, 0x00 }, //
1458 { { 116, 1 }, 0x00 }, //
1459 { { 117, 1 }, 0x64 }, //
1460 { { 118, 1 }, 0x00 }, //
1461 { { 119, 6 }, 0xC8 }, //
1462 { { 125, 1 }, 0x00 }, //
1463 { { 126, 7 }, 0xDF }, //
1464 { { 133, 1 }, 0x00 }, //
1465 { { 134, 2 }, 0x20 }, //
1466 { { 136, 1 }, 0x00 }, //
1467 { { 137, 2 }, 0xEC }, //
1468 { { 139, 1 }, 0x00 }, //
1469 { { 140, 2 }, 0x64 }, //
1470 { { 142, 1 }, 0x00 }, //
1471 { { 143, 2 }, 0x3D }, //
1472 { { 145, 1 }, 0x00 }, //
1473 { { 146, 2 }, 0xEC }, //
1474 { { 148, 1 }, 0x14 }, //
1475 { { 149, 1 }, 0x64 }, //
1476 };
1477
1478
1479 static const RBTokResult expTokLatnStdW[] = { // 72 tokens
1480 { { 0, 5 }, 0x0C8 }, //
1481 { { 5, 1 }, 0x000 }, //
1482 { { 6, 6 }, 0x0C8 }, //
1483 { { 12, 1 }, 0x000 }, //
1484 { { 13, 1 }, 0x000 }, //
1485 { { 14, 7 }, 0x0C8 }, //
1486 { { 21, 1 }, 0x000 }, //
1487 { { 22, 1 }, 0x000 }, //
1488 { { 23, 4 }, 0x0C8 }, //
1489 { { 27, 1 }, 0x000 }, //
1490 { { 28, 6 }, 0x0C8 }, //
1491 { { 34, 1 }, 0x000 }, //
1492 { { 35, 1 }, 0x000 }, //
1493 { { 36, 1 }, 0x000 }, //
1494 { { 37, 4 }, 0x0C8 }, //
1495 { { 41, 1 }, 0x000 }, //
1496 { { 42, 1 }, 0x000 }, //
1497 { { 43, 2 }, 0x0C8 }, //
1498 { { 45, 1 }, 0x000 }, //
1499 { { 46, 1 }, 0x064 }, //
1500 { { 47, 1 }, 0x000 }, //
1501 { { 48, 2 }, 0x064 }, //
1502 { { 50, 1 }, 0x000 }, //
1503 { { 51, 1 }, 0x000 }, //
1504 { { 52, 3 }, 0x0C8 }, //
1505 { { 55, 1 }, 0x000 }, //
1506 { { 56, 4 }, 0x0C8 }, //
1507 { { 60, 1 }, 0x000 }, //
1508 { { 61, 1 }, 0x000 }, //
1509 { { 62, 2 }, 0x0C8 }, //
1510 { { 64, 1 }, 0x000 }, //
1511 { { 65, 11 }, 0x0C8 }, //
1512 { { 76, 1 }, 0x000 }, //
1513 { { 77, 6 }, 0x0C8 }, //
1514 { { 83, 1 }, 0x000 }, //
1515 { { 84, 5 }, 0x0C8 }, //
1516 { { 89, 1 }, 0x000 }, //
1517 { { 90, 2 }, 0x0C8 }, //
1518 { { 92, 1 }, 0x000 }, //
1519 { { 93, 1 }, 0x000 }, //
1520 { { 94, 1 }, 0x000 }, //
1521 { { 95, 1 }, 0x000 }, //
1522 { { 96, 1 }, 0x000 }, //
1523 { { 97, 4 }, 0x0C8 }, //
1524 { { 101, 1 }, 0x000 }, //
1525 { { 102, 2 }, 0x0C8 }, //
1526 { { 104, 1 }, 0x000 }, //
1527 { { 105, 1 }, 0x064 }, //
1528 { { 106, 1 }, 0x000 }, //
1529 { { 107, 4 }, 0x0C8 }, //
1530 { { 111, 1 }, 0x000 }, //
1531 { { 112, 3 }, 0x0C8 }, //
1532 { { 115, 1 }, 0x000 }, //
1533 { { 116, 1 }, 0x000 }, //
1534 { { 117, 1 }, 0x064 }, //
1535 { { 118, 1 }, 0x000 }, //
1536 { { 119, 6 }, 0x0C8 }, //
1537 { { 125, 1 }, 0x000 }, //
1538 { { 126, 1 }, 0x000 }, //
1539 { { 127, 6 }, 0x0C8 }, //
1540 { { 133, 1 }, 0x000 }, //
1541 { { 134, 1 }, 0x000 }, //
1542 { { 135, 1 }, 0x000 }, //
1543 { { 136, 1 }, 0x000 }, //
1544 { { 137, 2 }, 0x0EC }, //
1545 { { 139, 1 }, 0x000 }, //
1546 { { 140, 2 }, 0x064 }, //
1547 { { 142, 1 }, 0x000 }, //
1548 { { 143, 1 }, 0x000 }, //
1549 { { 144, 1 }, 0x000 }, //
1550 { { 145, 1 }, 0x000 }, //
1551 { { 146, 4 }, 0x064 }, //
1552 };
1553
1554 static const UChar tokTextMisc[] = {
1555 /*
1556 "4‑inch phone.\n
1557 3월 30일\n
1558 从你开始使用 iPhone 6s 的那一刻起,你就会感觉到它是如此不同。\n""
1559 */
1560 0x0034,0x2011,0x0069,0x006E,0x0063,0x0068,0x0020,0x0070,0x0068,0x006F,0x006E,0x0065,0x002E,0x000A,
1561 0x0033,0xC6D4,0x0020,0x0033,0x0030,0xC77C,0x000A,
1562 0x4ECE,0x4F60,0x5F00,0x59CB,0x4F7F,0x7528,0x0020,0x0069,0x0050,0x0068,0x006F,0x006E,0x0065,0x0020,
1563 0x0036,0x0073,0x0020,0x7684,0x90A3,0x4E00,0x523B,0x8D77,0xFF0C,
1564 0x4F60,0x5C31,0x4F1A,0x611F,0x89C9,0x5230,0x5B83,0x662F,0x5982,0x6B64,0x4E0D,0x540C,0x3002,0x000A,0
1565 };
1566
1567 static const RBTokResult expTokMiscCFST[] = { // 8 tokens
1568 // ranges flags text
1569 { { 0, 6}, 0x131 }, // 4‑inch
1570 { { 7, 6}, 0x20 }, // phone.
1571 { { 14, 2}, 0x1110 }, // 3월
1572 { { 17, 3}, 0x1110 }, // 30일
1573 { { 21, 6}, 0x40000000 }, // 从你开始使用
1574 { { 28, 6}, 0x04 }, // iPhone
1575 { { 35, 2}, 0x10 }, // 6s
1576 { { 38, 19}, 0x40000121 }, // 的那一刻起,你就会感觉到它是如此不同。
1577 };
1578
1579 static const RBTokResult expTokMiscCFST_57Bulk[] = { // 5 tokens
1580 // ranges flags text
1581 { { 0, 6}, 0x131 }, // 4‑inch
1582 { { 7, 6}, 0x20 }, // phone.
1583 { { 14, 2}, 0x1110 }, // 3월
1584 { { 17, 3}, 0x1110 }, // 30일
1585 { { 21, 6}, 0x40000000 }, // 从你开始使用
1586 // missing the last 3 entries
1587 };
1588
1589
1590 static const RBTokResult expTokMiscNLLT[] = { // 36 tokens
1591 { { 0, 1 }, 0x064 }, //
1592 { { 1, 1 }, 0x000 }, //
1593 { { 2, 4 }, 0x0C8 }, //
1594 { { 6, 1 }, 0x000 }, //
1595 { { 7, 5 }, 0x0C8 }, //
1596 { { 12, 1 }, 0x014 }, //
1597 { { 13, 1 }, 0x000 }, //
1598 { { 14, 1 }, 0x064 }, //
1599 { { 15, 1 }, 0x0C8 }, //
1600 { { 16, 1 }, 0x000 }, //
1601 { { 17, 2 }, 0x064 }, //
1602 { { 19, 1 }, 0x0C8 }, //
1603 { { 20, 1 }, 0x000 }, //
1604 { { 21, 1 }, 0x190 }, //
1605 { { 22, 1 }, 0x190 }, //
1606 { { 23, 2 }, 0x190 }, //
1607 { { 25, 2 }, 0x190 }, //
1608 { { 27, 1 }, 0x000 }, //
1609 { { 28, 6 }, 0x0C8 }, //
1610 { { 34, 1 }, 0x000 }, //
1611 { { 35, 2 }, 0x0C8 }, //
1612 { { 37, 1 }, 0x000 }, //
1613 { { 38, 1 }, 0x190 }, //
1614 { { 39, 2 }, 0x190 }, //
1615 { { 41, 2 }, 0x190 }, //
1616 { { 43, 1 }, 0x000 }, //
1617 { { 44, 1 }, 0x190 }, //
1618 { { 45, 1 }, 0x190 }, //
1619 { { 46, 1 }, 0x190 }, //
1620 { { 47, 2 }, 0x190 }, //
1621 { { 49, 1 }, 0x190 }, //
1622 { { 50, 2 }, 0x190 }, //
1623 { { 52, 2 }, 0x190 }, //
1624 { { 54, 2 }, 0x190 }, //
1625 { { 56, 1 }, 0x000 }, //
1626 { { 57, 1 }, 0x000 }, //
1627 };
1628
1629 static const RBTokResult expTokMiscNLLT_57Loop[] = { // 36 tokens
1630 { { 0, 1 }, 0x064 }, //
1631 { { 1, 1 }, 0x000 }, //
1632 { { 2, 4 }, 0x0C8 }, //
1633 { { 6, 1 }, 0x000 }, //
1634 { { 7, 5 }, 0x0C8 }, //
1635 { { 12, 1 }, 0x014 }, //
1636 { { 13, 1 }, 0x000 }, //
1637 { { 14, 1 }, 0x064 }, //
1638 { { 15, 1 }, 0x0C8 }, //
1639 { { 16, 1 }, 0x000 }, //
1640 { { 17, 2 }, 0x064 }, //
1641 { { 19, 1 }, 0x0C8 }, //
1642 { { 20, 1 }, 0x000 }, //
1643 { { 21, 1 }, 0x190 }, //
1644 { { 22, 1 }, 0x000 }, //
1645 { { 23, 2 }, 0x000 }, //
1646 { { 25, 2 }, 0x000 }, //
1647 { { 27, 1 }, 0x000 }, //
1648 { { 28, 6 }, 0x0C8 }, //
1649 { { 34, 1 }, 0x000 }, //
1650 { { 35, 2 }, 0x0C8 }, //
1651 { { 37, 1 }, 0x000 }, //
1652 { { 38, 1 }, 0x190 }, //
1653 { { 39, 2 }, 0x000 }, //
1654 { { 41, 2 }, 0x000 }, //
1655 { { 43, 1 }, 0x000 }, //
1656 { { 44, 1 }, 0x190 }, //
1657 { { 45, 1 }, 0x000 }, //
1658 { { 46, 1 }, 0x000 }, //
1659 { { 47, 2 }, 0x000 }, //
1660 { { 49, 1 }, 0x000 }, //
1661 { { 50, 2 }, 0x000 }, //
1662 { { 52, 2 }, 0x000 }, //
1663 { { 54, 2 }, 0x000 }, //
1664 { { 56, 1 }, 0x000 }, //
1665 { { 57, 1 }, 0x000 }, //
1666 };
1667
1668 static const RBTokResult expTokMiscStdW[] = { // 36 tokens
1669 { { 0, 1 }, 0x064 }, //
1670 { { 1, 1 }, 0x000 }, //
1671 { { 2, 4 }, 0x0C8 }, //
1672 { { 6, 1 }, 0x000 }, //
1673 { { 7, 5 }, 0x0C8 }, //
1674 { { 12, 1 }, 0x000 }, // 0x014 for NLLT
1675 { { 13, 1 }, 0x000 }, //
1676 { { 14, 1 }, 0x064 }, //
1677 { { 15, 1 }, 0x0C8 }, //
1678 { { 16, 1 }, 0x000 }, //
1679 { { 17, 2 }, 0x064 }, //
1680 { { 19, 1 }, 0x0C8 }, //
1681 { { 20, 1 }, 0x000 }, //
1682 { { 21, 1 }, 0x190 }, //
1683 { { 22, 1 }, 0x190 }, //
1684 { { 23, 2 }, 0x190 }, //
1685 { { 25, 2 }, 0x190 }, //
1686 { { 27, 1 }, 0x000 }, //
1687 { { 28, 6 }, 0x0C8 }, //
1688 { { 34, 1 }, 0x000 }, //
1689 { { 35, 2 }, 0x0C8 }, //
1690 { { 37, 1 }, 0x000 }, //
1691 { { 38, 1 }, 0x190 }, //
1692 { { 39, 2 }, 0x190 }, //
1693 { { 41, 2 }, 0x190 }, //
1694 { { 43, 1 }, 0x000 }, //
1695 { { 44, 1 }, 0x190 }, //
1696 { { 45, 1 }, 0x190 }, //
1697 { { 46, 1 }, 0x190 }, //
1698 { { 47, 2 }, 0x190 }, //
1699 { { 49, 1 }, 0x190 }, //
1700 { { 50, 2 }, 0x190 }, //
1701 { { 52, 2 }, 0x190 }, //
1702 { { 54, 2 }, 0x190 }, //
1703 { { 56, 1 }, 0x000 }, //
1704 { { 57, 1 }, 0x000 }, //
1705 };
1706
1707 static const UChar tokTextJpan[] = {
1708 0x30B3,0x30F3,0x30D4,0x30E5,0x30FC,0x30BF,0x30FC, // {{ 0, 7 }, 400 }
1709 0x306F, // {{ 7, 1 }, 400 }
1710 0x3001, // {{ 8, 1 }, 0 } 、
1711 0x672C,0x8CEA, // {{ 9, 2 }, 400 }
1712 0x7684, // {{ 11, 1 }, 400 }
1713 0x306B, // {{ 12, 1 }, 400 }
1714 0x306F, // {{ 13, 1 }, 400 }
1715 0x6570,0x5B57, // {{ 14, 2 }, 400 }
1716 0x3057,0x304B, // {{ 16, 2 }, 400 }
1717 0x6271,0x3046, // {{ 18, 2 }, 400 }
1718 0x3053,0x3068, // {{ 20, 2 }, 400 }
1719 0x304C, // {{ 22, 1 }, 400 }
1720 0x3067,0x304D, // {{ 23, 2 }, 400 }
1721 0x307E, // {{ 25, 1 }, 400 }
1722 0x305B,0x3093, // {{ 26, 2 }, 400 }
1723 0x3002, // {{ 28, 1 }, 0 } 。
1724 0x30B3,0x30F3,0x30D4,0x30E5,0x30FC,0x30BF,0x30FC, // {{ 29, 7 }, 400 }
1725 0x306F, // {{ 36, 1 }, 400 }
1726 0x3001, // {{ 37, 1 }, 0 } 、
1727 0x6587,0x5B57, // {{ 38, 2 }, 400 }
1728 0x3084, // {{ 40, 1 }, 400 }
1729 0x8A18,0x53F7, // {{ 41, 2 }, 400 }
1730 0x306A,0x3069, // {{ 43, 2 }, 400 }
1731 0x306E, // {{ 45, 1 }, 400 }
1732 0x305D,0x308C,0x305E,0x308C,0x306B, // {{ 46, 5 }, 400 }
1733 0x756A,0x53F7, // {{ 51, 2 }, 400 }
1734 0x3092, // {{ 53, 1 }, 400 }
1735 0x5272,0x308A,0x632F,0x308B, // {{ 54, 4 }, 400 }
1736 0x3053,0x3068, // {{ 58, 2 }, 400 }
1737 0x306B,0x3088,0x3063,0x3066, // {{ 60, 4 }, 400 }
1738 0x6271,0x3048,0x308B, // {{ 64, 3 }, 400 }
1739 0x3088,0x3046, // {{ 67, 2 }, 400 }
1740 0x306B,0x3057, // {{ 69, 2 }, 400 }
1741 0x307E,0x3059, // {{ 71, 2 }, 400 }
1742 0x3002, // {{ 73, 1 }, 0 } 。
1743 0x30E6,0x30CB, // {{ 74, 2 }, 400 }
1744 0x30B3,0x30FC,0x30C9, // {{ 76, 3 }, 400 }
1745 0x304C, // {{ 79, 1 }, 400 }
1746 0x51FA,0x6765,0x308B, // {{ 80, 3 }, 400 }
1747 0x307E,0x3067, // {{ 83, 2 }, 400 }
1748 0x306F, // {{ 85, 1 }, 400 }
1749 0x3001, // {{ 86, 1 }, 0 } 、
1750 0x3053,0x308C,0x3089,0x306E, // {{ 87, 4 }, 400 }
1751 0x756A,0x53F7, // {{ 91, 2 }, 400 }
1752 0x3092, // {{ 93, 1 }, 400 }
1753 0x5272,0x308A,0x632F,0x308B, // {{ 94, 4 }, 400 }
1754 0x4ED5,0x7D44,0x307F, // {{ 98, 3 }, 400 }
1755 0x304C, // {{ 101, 1 }, 400 }
1756 0x767E, // {{ 102, 1 }, 400 }
1757 0x7A2E,0x985E, // {{ 103, 2 }, 400 }
1758 0x3082, // {{ 105, 1 }, 400 }
1759 0x5B58,0x5728, // {{ 106, 2 }, 400 }
1760 0x3057,0x307E, // {{ 108, 2 }, 400 }
1761 0x3057,0x305F, // {{ 110, 2 }, 400 }
1762 0x3002, // {{ 112, 1 }, 0 } 。
1763 0
1764 };
1765
1766 static const RBTokResult expTokJpanCFST[] = { // 1 token (??)
1767 // ranges flags text
1768 {{ 0, 113 }, 0x40000120 },
1769 };
1770
1771 static const RBTokResult expTokJpan[] = { // 55 tokens
1772 // ranges flags text
1773 {{ 0, 7 }, 400 },
1774 {{ 7, 1 }, 400 },
1775 {{ 8, 1 }, 0 }, // 、
1776 {{ 9, 2 }, 400 },
1777 {{ 11, 1 }, 400 },
1778 {{ 12, 1 }, 400 },
1779 {{ 13, 1 }, 400 },
1780 {{ 14, 2 }, 400 },
1781 {{ 16, 2 }, 400 },
1782 {{ 18, 2 }, 400 },
1783 {{ 20, 2 }, 400 },
1784 {{ 22, 1 }, 400 },
1785 {{ 23, 2 }, 400 },
1786 {{ 25, 1 }, 400 },
1787 {{ 26, 2 }, 400 },
1788 {{ 28, 1 }, 0 }, // 。
1789 {{ 29, 7 }, 400 },
1790 {{ 36, 1 }, 400 },
1791 {{ 37, 1 }, 0 }, // 、
1792 {{ 38, 2 }, 400 },
1793 {{ 40, 1 }, 400 },
1794 {{ 41, 2 }, 400 },
1795 {{ 43, 2 }, 400 },
1796 {{ 45, 1 }, 400 },
1797 {{ 46, 5 }, 400 },
1798 {{ 51, 2 }, 400 },
1799 {{ 53, 1 }, 400 },
1800 {{ 54, 4 }, 400 },
1801 {{ 58, 2 }, 400 },
1802 {{ 60, 4 }, 400 },
1803 {{ 64, 3 }, 400 },
1804 {{ 67, 2 }, 400 },
1805 {{ 69, 2 }, 400 },
1806 {{ 71, 2 }, 400 },
1807 {{ 73, 1 }, 0 }, // 。
1808 {{ 74, 2 }, 400 },
1809 {{ 76, 3 }, 400 },
1810 {{ 79, 1 }, 400 },
1811 {{ 80, 3 }, 400 },
1812 {{ 83, 2 }, 400 },
1813 {{ 85, 1 }, 400 },
1814 {{ 86, 1 }, 0 }, // 、
1815 {{ 87, 4 }, 400 },
1816 {{ 91, 2 }, 400 },
1817 {{ 93, 1 }, 400 },
1818 {{ 94, 4 }, 400 },
1819 {{ 98, 3 }, 400 },
1820 {{ 101, 1 }, 400 },
1821 {{ 102, 1 }, 400 },
1822 {{ 103, 2 }, 400 },
1823 {{ 105, 1 }, 400 },
1824 {{ 106, 2 }, 400 },
1825 {{ 108, 2 }, 400 },
1826 {{ 110, 2 }, 400 },
1827 {{ 112, 1 }, 0 }, // 。
1828 };
1829
1830 static const RBTokResult expTokJpanNLLT_57Loop[] = { // 55 tokens
1831 {{ 0, 7 }, 0x190 }, //
1832 {{ 7, 1 }, 0x000 }, //
1833 {{ 8, 1 }, 0x000 }, //
1834 {{ 9, 2 }, 0x190 }, //
1835 {{ 11, 1 }, 0x000 }, //
1836 {{ 12, 1 }, 0x000 }, //
1837 {{ 13, 1 }, 0x000 }, //
1838 {{ 14, 2 }, 0x000 }, //
1839 {{ 16, 2 }, 0x000 }, //
1840 {{ 18, 2 }, 0x000 }, //
1841 {{ 20, 2 }, 0x000 }, //
1842 {{ 22, 1 }, 0x000 }, //
1843 {{ 23, 2 }, 0x000 }, //
1844 {{ 25, 1 }, 0x000 }, //
1845 {{ 26, 2 }, 0x000 }, //
1846 {{ 28, 1 }, 0x000 }, //
1847 {{ 29, 7 }, 0x190 }, //
1848 {{ 36, 1 }, 0x000 }, //
1849 {{ 37, 1 }, 0x000 }, //
1850 {{ 38, 2 }, 0x190 }, //
1851 {{ 40, 1 }, 0x000 }, //
1852 {{ 41, 2 }, 0x000 }, //
1853 {{ 43, 2 }, 0x000 }, //
1854 {{ 45, 1 }, 0x000 }, //
1855 {{ 46, 5 }, 0x000 }, //
1856 {{ 51, 2 }, 0x000 }, //
1857 {{ 53, 1 }, 0x000 }, //
1858 {{ 54, 4 }, 0x000 }, //
1859 {{ 58, 2 }, 0x000 }, //
1860 {{ 60, 4 }, 0x000 }, //
1861 {{ 64, 3 }, 0x000 }, //
1862 {{ 67, 2 }, 0x000 }, //
1863 {{ 69, 2 }, 0x000 }, //
1864 {{ 71, 2 }, 0x000 }, //
1865 {{ 73, 1 }, 0x000 }, //
1866 {{ 74, 2 }, 0x190 }, //
1867 {{ 76, 3 }, 0x000 }, //
1868 {{ 79, 1 }, 0x000 }, //
1869 {{ 80, 3 }, 0x000 }, //
1870 {{ 83, 2 }, 0x000 }, //
1871 {{ 85, 1 }, 0x000 }, //
1872 {{ 86, 1 }, 0x000 }, //
1873 {{ 87, 4 }, 0x190 }, //
1874 {{ 91, 2 }, 0x000 }, //
1875 {{ 93, 1 }, 0x000 }, //
1876 {{ 94, 4 }, 0x000 }, //
1877 {{ 98, 3 }, 0x000 }, //
1878 {{ 101, 1 }, 0x000 }, //
1879 {{ 102, 1 }, 0x000 }, //
1880 {{ 103, 2 }, 0x000 }, //
1881 {{ 105, 1 }, 0x000 }, //
1882 {{ 106, 2 }, 0x000 }, //
1883 {{ 108, 2 }, 0x000 }, //
1884 {{ 110, 2 }, 0x000 }, //
1885 {{ 112, 1 }, 0x000 }, //
1886 };
1887
1888
1889 static const UChar tokTextThai[] = {
1890 0x55,0x6E,0x69,0x63,0x6F,0x64,0x65, // {{ 0, 7 }, 200 },
1891 0x20, // {{ 7, 1 }, 1 },
1892 0x0E04,0x0E37,0x0E2D, // {{ 8, 3 }, 200 },
1893 0x0E2D,0x0E30,0x0E44,0x0E23, // {{ 11, 4 }, 200 },
1894 0x3F, // {{ 15, 1 }, 0 },
1895 0x0A, // {{ 16, 1 }, 0 },
1896 0x55,0x6E,0x69,0x63,0x6F,0x64,0x65, // {{ 17, 7 }, 200 },
1897 0x20, // {{ 24, 1 }, 1 },
1898 0x0E01,0x0E33,0x0E2B,0x0E19,0x0E14, // {{ 25, 5 }, 200 },
1899 0x0E2B,0x0E21,0x0E32,0x0E22,0x0E40,0x0E25,0x0E02, // {{ 30, 7 }, 200 },
1900 0x0E40,0x0E09,0x0E1E,0x0E32,0x0E30, // {{ 37, 5 }, 200 },
1901 0x0E2A,0x0E33,0x0E2B,0x0E23,0x0E31,0x0E1A, // {{ 42, 6 }, 200 },
1902 0x0E17,0x0E38,0x0E01, // {{ 48, 3 }, 200 },
1903 0x0E2D,0x0E31,0x0E01,0x0E02,0x0E23,0x0E30, // {{ 51, 6 }, 200 },
1904 0x0A, // {{ 57, 1 }, 0 },
1905 0x0E42,0x0E14,0x0E22, // {{ 58, 3 }, 200 },
1906 0x0E44,0x0E21,0x0E48, // {{ 61, 3 }, 200 },
1907 0x0E2A,0x0E19,0x0E43,0x0E08, // {{ 64, 4 }, 200 },
1908 0x0E27,0x0E48,0x0E32, // {{ 68, 3 }, 200 },
1909 0x0E40,0x0E1B,0x0E47,0x0E19, // {{ 71, 4 }, 200 },
1910 0x0E41,0x0E1E, // {{ 75, 2 }, 200 },
1911 0x0E25,0x0E47,0x0E15, // {{ 77, 3 }, 200 },
1912 0x0E1F,0x0E2D,0x0E23,0x0E4C,0x0E21, // {{ 80, 5 }, 200 },
1913 0x0E43,0x0E14, // {{ 85, 2 }, 200 },
1914 0x0A, // {{ 87, 1 }, 0 },
1915 0x0E44,0x0E21,0x0E48, // {{ 88, 3 }, 200 },
1916 0x0E02,0x0E36,0x0E49,0x0E19, // {{ 91, 4 }, 200 },
1917 0x0E01,0x0E31,0x0E1A, // {{ 95, 3 }, 200 },
1918 0x0E27,0x0E48,0x0E32, // {{ 98, 3 }, 200 },
1919 0x0E08,0x0E30, // {{ 101, 2 }, 200 },
1920 0x0E40,0x0E1B,0x0E47,0x0E19, // {{ 103, 4 }, 200 },
1921 0x0E42,0x0E1B,0x0E23,0x0E41,0x0E01,0x0E23,0x0E21, // {{ 107, 7 }, 200 },
1922 0x0E43,0x0E14, // {{ 114, 2 }, 200 },
1923 0x0A, // {{ 116, 1 }, 0 },
1924 0x0E41,0x0E25,0x0E30, // {{ 117, 3 }, 200 },
1925 0x0E44,0x0E21,0x0E48, // {{ 120, 3 }, 200 },
1926 0x0E27,0x0E48,0x0E32, // {{ 123, 3 }, 200 },
1927 0x0E08,0x0E30, // {{ 126, 2 }, 200 },
1928 0x0E40,0x0E1B,0x0E47,0x0E19, // {{ 128, 4 }, 200 },
1929 0x0E20,0x0E32,0x0E29,0x0E32, // {{ 132, 4 }, 200 },
1930 0x0E43,0x0E14, // {{ 136, 2 }, 200 },
1931 0x0A, // {{ 138, 1 }, 0 },
1932 0
1933 };
1934
1935 static const RBTokResult expTokThaiCFST[] = { // 34 tokens
1936 {{ 0, 7 }, 0x002 }, //
1937 {{ 8, 3 }, 0x020 }, //
1938 {{ 11, 5 }, 0x020 }, //
1939 {{ 17, 7 }, 0x002 }, //
1940 {{ 25, 5 }, 0x109 }, //
1941 {{ 30, 7 }, 0x109 }, //
1942 {{ 37, 5 }, 0x109 }, //
1943 {{ 42, 6 }, 0x109 }, //
1944 {{ 48, 3 }, 0x109 }, //
1945 {{ 51, 6 }, 0x109 }, //
1946 {{ 58, 3 }, 0x009 }, //
1947 {{ 61, 3 }, 0x009 }, //
1948 {{ 64, 4 }, 0x009 }, //
1949 {{ 68, 3 }, 0x009 }, //
1950 {{ 71, 4 }, 0x009 }, //
1951 {{ 75, 2 }, 0x009 }, //
1952 {{ 77, 3 }, 0x009 }, //
1953 {{ 80, 5 }, 0x009 }, //
1954 {{ 85, 2 }, 0x009 }, //
1955 {{ 88, 3 }, 0x009 }, //
1956 {{ 91, 4 }, 0x009 }, //
1957 {{ 95, 3 }, 0x009 }, //
1958 {{ 98, 3 }, 0x009 }, //
1959 {{ 101, 2 }, 0x009 }, //
1960 {{ 103, 4 }, 0x009 }, //
1961 {{ 107, 7 }, 0x009 }, //
1962 {{ 114, 2 }, 0x009 }, //
1963 {{ 117, 3 }, 0x009 }, //
1964 {{ 120, 3 }, 0x009 }, //
1965 {{ 123, 3 }, 0x009 }, //
1966 {{ 126, 2 }, 0x009 }, //
1967 {{ 128, 4 }, 0x009 }, //
1968 {{ 132, 4 }, 0x009 }, //
1969 {{ 136, 2 }, 0x009 }, //
1970 };
1971
1972 static const RBTokResult expTokThaiCFST_57Loop[] = { // 34 tokens
1973 {{ 0, 7 }, 0x002 }, //
1974 {{ 8, 3 }, 0x020 }, //
1975 {{ 11, 5 }, 0x000 }, //
1976 {{ 17, 7 }, 0x002 }, //
1977 {{ 25, 5 }, 0x109 }, //
1978 {{ 30, 7 }, 0x000 }, //
1979 {{ 37, 5 }, 0x000 }, //
1980 {{ 42, 6 }, 0x000 }, //
1981 {{ 48, 3 }, 0x000 }, //
1982 {{ 51, 6 }, 0x000 }, //
1983 {{ 58, 3 }, 0x009 }, //
1984 {{ 61, 3 }, 0x000 }, //
1985 {{ 64, 4 }, 0x000 }, //
1986 {{ 68, 3 }, 0x000 }, //
1987 {{ 71, 4 }, 0x000 }, //
1988 {{ 75, 2 }, 0x000 }, //
1989 {{ 77, 3 }, 0x000 }, //
1990 {{ 80, 5 }, 0x000 }, //
1991 {{ 85, 2 }, 0x000 }, //
1992 {{ 88, 3 }, 0x009 }, //
1993 {{ 91, 4 }, 0x000 }, //
1994 {{ 95, 3 }, 0x000 }, //
1995 {{ 98, 3 }, 0x000 }, //
1996 {{ 101, 2 }, 0x000 }, //
1997 {{ 103, 4 }, 0x000 }, //
1998 {{ 107, 7 }, 0x000 }, //
1999 {{ 114, 2 }, 0x000 }, //
2000 {{ 117, 3 }, 0x009 }, //
2001 {{ 120, 3 }, 0x000 }, //
2002 {{ 123, 3 }, 0x000 }, //
2003 {{ 126, 2 }, 0x000 }, //
2004 {{ 128, 4 }, 0x000 }, //
2005 {{ 132, 4 }, 0x000 }, //
2006 {{ 136, 2 }, 0x000 }, //
2007 };
2008
2009 static const RBTokResult expTokThai[] = { // 42 tokens
2010 // ranges flags text
2011 {{ 0, 7 }, 0xC8 }, // 0xC8 = 200
2012 {{ 7, 1 }, 0x00 }, //
2013 {{ 8, 3 }, 0xC8 },
2014 {{ 11, 4 }, 0xC8 },
2015 {{ 15, 1 }, 0x00 }, //
2016 {{ 16, 1 }, 0x00 }, //
2017 {{ 17, 7 }, 0xC8 },
2018 {{ 24, 1 }, 0x00 }, //
2019 {{ 25, 5 }, 0xC8 },
2020 {{ 30, 7 }, 0xC8 },
2021 {{ 37, 5 }, 0xC8 },
2022 {{ 42, 6 }, 0xC8 },
2023 {{ 48, 3 }, 0xC8 },
2024 {{ 51, 6 }, 0xC8 },
2025 {{ 57, 1 }, 0x00 }, //
2026 {{ 58, 3 }, 0xC8 },
2027 {{ 61, 3 }, 0xC8 },
2028 {{ 64, 4 }, 0xC8 },
2029 {{ 68, 3 }, 0xC8 },
2030 {{ 71, 4 }, 0xC8 },
2031 {{ 75, 2 }, 0xC8 },
2032 {{ 77, 3 }, 0xC8 },
2033 {{ 80, 5 }, 0xC8 },
2034 {{ 85, 2 }, 0xC8 },
2035 {{ 87, 1 }, 0x00 }, //
2036 {{ 88, 3 }, 0xC8 },
2037 {{ 91, 4 }, 0xC8 },
2038 {{ 95, 3 }, 0xC8 },
2039 {{ 98, 3 }, 0xC8 },
2040 {{ 101, 2 }, 0xC8 },
2041 {{ 103, 4 }, 0xC8 },
2042 {{ 107, 7 }, 0xC8 },
2043 {{ 114, 2 }, 0xC8 },
2044 {{ 116, 1 }, 0x00 }, //
2045 {{ 117, 3 }, 0xC8 },
2046 {{ 120, 3 }, 0xC8 },
2047 {{ 123, 3 }, 0xC8 },
2048 {{ 126, 2 }, 0xC8 },
2049 {{ 128, 4 }, 0xC8 },
2050 {{ 132, 4 }, 0xC8 },
2051 {{ 136, 2 }, 0xC8 },
2052 {{ 138, 1 }, 0x00 }, //
2053 };
2054
2055 static const RBTokResult expTokThaiNLLT_57Loop[] = { // 42 tokens
2056 {{ 0, 7 }, 0xC8 }, // 0xC8 = 200
2057 {{ 7, 1 }, 0x00 }, //
2058 {{ 8, 3 }, 0xC8 }, //
2059 {{ 11, 4 }, 0x00 }, //
2060 {{ 15, 1 }, 0x00 }, //
2061 {{ 16, 1 }, 0x00 }, //
2062 {{ 17, 7 }, 0xC8 }, //
2063 {{ 24, 1 }, 0x00 }, //
2064 {{ 25, 5 }, 0xC8 }, //
2065 {{ 30, 7 }, 0x00 }, //
2066 {{ 37, 5 }, 0x00 }, //
2067 {{ 42, 6 }, 0x00 }, //
2068 {{ 48, 3 }, 0x00 }, //
2069 {{ 51, 6 }, 0x00 }, //
2070 {{ 57, 1 }, 0x00 }, //
2071 {{ 58, 3 }, 0xC8 }, //
2072 {{ 61, 3 }, 0x00 }, //
2073 {{ 64, 4 }, 0x00 }, //
2074 {{ 68, 3 }, 0x00 }, //
2075 {{ 71, 4 }, 0x00 }, //
2076 {{ 75, 2 }, 0x00 }, //
2077 {{ 77, 3 }, 0x00 }, //
2078 {{ 80, 5 }, 0x00 }, //
2079 {{ 85, 2 }, 0x00 }, //
2080 {{ 87, 1 }, 0x00 }, //
2081 {{ 88, 3 }, 0xC8 }, //
2082 {{ 91, 4 }, 0x00 }, //
2083 {{ 95, 3 }, 0x00 }, //
2084 {{ 98, 3 }, 0x00 }, //
2085 {{ 101, 2 }, 0x00 }, //
2086 {{ 103, 4 }, 0x00 }, //
2087 {{ 107, 7 }, 0x00 }, //
2088 {{ 114, 2 }, 0x00 }, //
2089 {{ 116, 1 }, 0x00 }, //
2090 {{ 117, 3 }, 0xC8 }, //
2091 {{ 120, 3 }, 0x00 }, //
2092 {{ 123, 3 }, 0x00 }, //
2093 {{ 126, 2 }, 0x00 }, //
2094 {{ 128, 4 }, 0x00 }, //
2095 {{ 132, 4 }, 0x00 }, //
2096 {{ 136, 2 }, 0x00 }, //
2097 {{ 138, 1 }, 0x00 }, //
2098 };
2099
2100
2101 typedef struct {
2102 const char* descrip;
2103 const UChar* tokText; // zero-terminated text
2104 const RBTokResult* expTok;
2105 int32_t expTokLen;
2106 const RBTokResult* expTokFile;
2107 int32_t expTokFileLen;
2108 const RBTokResult* expTok57Loop; // Actual urbtok results in ICU 59 for this test
2109 int32_t expTok57LoopLen; // Actual urbtok results in ICU 59 for this test
2110 const RBTokResult* expTok57Bulk; // Actual urbtok results in ICU 59 for this test
2111 int32_t expTok57BulkLen; // Actual urbtok results in ICU 59 for this test
2112 } TokTextAndResults;
2113
2114 static const TokTextAndResults tokTextAndResCFST[] = {
2115 { "CFST/Latn", tokTextLatn, expTokLatnCFST, UPRV_LENGTHOF(expTokLatnCFST), expTokLatnCFST, UPRV_LENGTHOF(expTokLatnCFST), expTokLatnCFST, UPRV_LENGTHOF(expTokLatnCFST), expTokLatnCFST, UPRV_LENGTHOF(expTokLatnCFST) },
2116 { "CFST/Misc", tokTextMisc, expTokMiscCFST, UPRV_LENGTHOF(expTokMiscCFST), expTokMiscCFST, UPRV_LENGTHOF(expTokMiscCFST), expTokMiscCFST, UPRV_LENGTHOF(expTokMiscCFST), expTokMiscCFST_57Bulk, UPRV_LENGTHOF(expTokMiscCFST_57Bulk) },
2117 { "CFST/Jpan", tokTextJpan, expTokJpanCFST, UPRV_LENGTHOF(expTokJpanCFST), expTokJpanCFST, UPRV_LENGTHOF(expTokJpanCFST), expTokJpanCFST, UPRV_LENGTHOF(expTokJpanCFST), expTokJpanCFST, UPRV_LENGTHOF(expTokJpanCFST) },
2118 { "CFST/Thai", tokTextThai, expTokThaiCFST, UPRV_LENGTHOF(expTokThaiCFST), expTokThaiCFST, UPRV_LENGTHOF(expTokThaiCFST), expTokThaiCFST_57Loop, UPRV_LENGTHOF(expTokThaiCFST_57Loop), expTokThaiCFST, UPRV_LENGTHOF(expTokThaiCFST) },
2119 { NULL, NULL, NULL, 0, NULL, 0, NULL, 0 }
2120 };
2121
2122 static const TokTextAndResults tokTextAndResNLLT[] = {
2123 { "NLLT/Latn", tokTextLatn, expTokLatnNLLT, UPRV_LENGTHOF(expTokLatnNLLT), expTokLatnNLLT_File, UPRV_LENGTHOF(expTokLatnNLLT_File), expTokLatnNLLT_57, UPRV_LENGTHOF(expTokLatnNLLT_57), expTokLatnNLLT_57, UPRV_LENGTHOF(expTokLatnNLLT_57)},
2124 { "NLLT/Misc", tokTextMisc, expTokMiscNLLT, UPRV_LENGTHOF(expTokMiscNLLT), expTokMiscNLLT, UPRV_LENGTHOF(expTokMiscNLLT), expTokMiscNLLT_57Loop, UPRV_LENGTHOF(expTokMiscNLLT_57Loop), expTokMiscNLLT, UPRV_LENGTHOF(expTokMiscNLLT)},
2125 { "NLLT/Jpan", tokTextJpan, expTokJpan, UPRV_LENGTHOF(expTokJpan), expTokJpan, UPRV_LENGTHOF(expTokJpan), expTokJpanNLLT_57Loop, UPRV_LENGTHOF(expTokJpanNLLT_57Loop), expTokJpan, UPRV_LENGTHOF(expTokJpan) },
2126 { "NLLT/Thai", tokTextThai, expTokThai, UPRV_LENGTHOF(expTokThai), expTokThai, UPRV_LENGTHOF(expTokThai), expTokThaiNLLT_57Loop, UPRV_LENGTHOF(expTokThaiNLLT_57Loop), expTokThai, UPRV_LENGTHOF(expTokThai) },
2127 { NULL, NULL, NULL, 0, NULL, 0, NULL, 0 }
2128 };
2129
2130 static const TokTextAndResults tokTextAndResStdW[] = {
2131 { "StdW/Latn", tokTextLatn, expTokLatnStdW, UPRV_LENGTHOF(expTokLatnStdW), expTokLatnStdW, UPRV_LENGTHOF(expTokLatnStdW), expTokLatnStdW, UPRV_LENGTHOF(expTokLatnStdW), expTokLatnStdW, UPRV_LENGTHOF(expTokLatnStdW) },
2132 { "StdW/Misc", tokTextMisc, expTokMiscStdW, UPRV_LENGTHOF(expTokMiscStdW), expTokMiscStdW, UPRV_LENGTHOF(expTokMiscStdW), expTokMiscStdW, UPRV_LENGTHOF(expTokMiscStdW), expTokMiscStdW, UPRV_LENGTHOF(expTokMiscStdW) },
2133 { "StdW/Jpan", tokTextJpan, expTokJpan, UPRV_LENGTHOF(expTokJpan), expTokJpan, UPRV_LENGTHOF(expTokJpan), expTokJpan, UPRV_LENGTHOF(expTokJpan), expTokJpan, UPRV_LENGTHOF(expTokJpan) },
2134 { "StdW/Thai", tokTextThai, expTokThai, UPRV_LENGTHOF(expTokThai), expTokThai, UPRV_LENGTHOF(expTokThai), expTokThai, UPRV_LENGTHOF(expTokThai), expTokThai, UPRV_LENGTHOF(expTokThai) },
2135 { NULL, NULL, NULL, 0, NULL, 0, NULL, 0 }
2136 };
2137
2138 typedef struct {
2139 const char* descrip;
2140 const char* rulesSource; // relative to cintltst directory; UTF8 rule source; NULL for std word rules
2141 const char* rulesBin; // relative to cintltst directory; current binary version
2142 const char* rulesBin57; // relative to cintltst directory; ICU 57 binary version
2143 const TokTextAndResults* textAndResults;
2144 } TokRulesAndTests;
2145
2146 static const TokRulesAndTests tokRulesTests[] = { // icu60 binary files invalid in ICU 62
2147 { "CFST", "../testdata/tokCFSTrules.txt", NULL,/*tokCFSTrulesLE_icu60.data invalid*/ "../testdata/tokCFSTrulesLE_icu57.data", tokTextAndResCFST },
2148 { "NLLT", "../testdata/wordNLLTu8.txt", NULL,/*wordNLLT_icu60.dat invalid */ "../testdata/wordNLLT_icu57.dat", tokTextAndResNLLT },
2149 { "StdW", "../../data/brkitr/rules/word.txt", NULL, NULL, tokTextAndResStdW },
2150 { "WORD", NULL, NULL, NULL, tokTextAndResStdW },
2151 { NULL, NULL, NULL, NULL, NULL }
2152 };
2153
2154 enum {
2155 kMaxTokens = 96
2156 };
2157
2158 // read data from file into a malloc'ed buf, which must be freed by caller.
2159 // returns NULL if error.
2160 static void* dataBufFromFile(const char* path, long* dataBufSizeP) {
2161 FILE * dataFile;
2162 void * dataBuf;
2163 long dataBufSize, dataFileRead = 0;
2164
2165 if (dataBufSizeP) {
2166 *dataBufSizeP = 0;
2167 }
2168 dataFile = fopen(path, "r");
2169 if (dataFile == NULL) {
2170 log_data_err("FAIL: for %s, fopen fails\n", path);
2171 return NULL;
2172 }
2173 fseek(dataFile, 0, SEEK_END);
2174 dataBufSize = ftell(dataFile);
2175 rewind(dataFile);
2176
2177 dataBuf = uprv_malloc(dataBufSize);
2178 if (dataBuf != NULL) {
2179 dataFileRead = fread(dataBuf, 1, dataBufSize, dataFile);
2180 }
2181 fclose(dataFile);
2182 if (dataBuf == NULL) {
2183 log_data_err("FAIL: for %s, uprv_malloc fails for dataBuf[%ld]\n", path, dataBufSize);
2184 return NULL;
2185 }
2186 if (dataFileRead < dataBufSize) {
2187 log_data_err("FAIL: for %s, fread fails, read %ld of %ld\n", path, dataFileRead, dataBufSize);
2188 uprv_free(dataBuf);
2189 return NULL;
2190 }
2191 if (dataBufSizeP) {
2192 *dataBufSizeP = dataBufSize;
2193 }
2194 return dataBuf;
2195 }
2196
2197 static void handleTokResults(const char* testItem, const char* tokClass, const char* ruleSource, const char* algType,
2198 uint64_t duration, int32_t expTokLen, const RBTokResult* expTokRes,
2199 int32_t getTokLen, RuleBasedTokenRange* getTokens, unsigned long *getFlags) {
2200 int32_t iToken;
2201 UBool fail = (getTokLen != expTokLen);
2202 for (iToken = 0; !fail && iToken < getTokLen; iToken++) {
2203 if ( getTokens[iToken].location != expTokRes[iToken].token.location || getTokens[iToken].length != expTokRes[iToken].token.length ||
2204 getFlags[iToken] != expTokRes[iToken].flags ) {
2205 fail = TRUE;
2206 }
2207 }
2208 if (fail) {
2209 log_err("FAIL: %s %s %s %s expected %d tokens, got %d\n", testItem, tokClass, ruleSource, algType, expTokLen, getTokLen);
2210 printf("# expect get\n");
2211 printf("# loc len flags loc len flags\n");
2212 int32_t maxTokens = (getTokLen >= expTokLen)? getTokLen: expTokLen;
2213 for (iToken = 0; iToken < maxTokens; iToken++) {
2214 if (iToken < expTokLen) {
2215 printf(" %3ld %3ld 0x%-8lX", expTokRes[iToken].token.location,
2216 expTokRes[iToken].token.length, expTokRes[iToken].flags);
2217 } else {
2218 printf(" ");
2219 }
2220 if (iToken < getTokLen) {
2221 printf(" %3ld %3ld 0x%-8lX\n", getTokens[iToken].location, getTokens[iToken].length, getFlags[iToken] );
2222 } else {
2223 printf("\n");
2224 }
2225 }
2226 } else {
2227 log_info("%s %s %s %s get %d tokens, nsec %llu\n", testItem, tokClass, ruleSource, algType, getTokLen, duration);
2228 }
2229 }
2230
2231 static void TestRuleBasedTokenizer(void) {
2232 const TokRulesAndTests* ruleTypePtr;
2233 uint64_t start, duration;
2234 #if U_PLATFORM_IS_DARWIN_BASED
2235 mach_timebase_info_data_t info;
2236
2237 mach_timebase_info(&info);
2238 #endif
2239 for (ruleTypePtr = tokRulesTests; ruleTypePtr->descrip != NULL; ruleTypePtr++) {
2240 UBreakIterator* ubrkFromSource = NULL;
2241 UBreakIterator* ubrkBinFromSource = NULL;
2242 UBreakIterator* utokFromSource = NULL;
2243 UBreakIterator* utokBinFromSource = NULL;
2244 UBreakIterator* utokBinFromFile = NULL;
2245 UBreakIterator* utok57FromSource = NULL;
2246 UBreakIterator* utok57BinFromSource = NULL;
2247 UBreakIterator* utok57BinFromFile = NULL;
2248 uint8_t* ubrkBinRules = NULL; // these must be retained while ubrkBinFromSource is open
2249 UErrorCode status = U_ZERO_ERROR;
2250
2251 log_info("- starting tests for rule type %s\n", ruleTypePtr->descrip);
2252
2253 // Get UBreakIterators
2254 if (ruleTypePtr->rulesSource == NULL) {
2255 // use standard WORD rules for root
2256 start = GET_START();
2257 ubrkFromSource = ubrk_open(UBRK_WORD, "root", NULL, 0, &status);
2258 duration = GET_DURATION(start, info);
2259 if (U_FAILURE(status)) {
2260 log_err("FAIL: ubrk_open WORD for root, status: %s\n", u_errorName(status));
2261 } else {
2262 log_info(" ubrk_open nsec %llu\n", duration);
2263 int32_t rulesBinFromStdSize = ubrk_getBinaryRules(ubrkFromSource, NULL, 0, &status);
2264 if (U_FAILURE(status)) {
2265 log_err("FAIL: ubrk_getBinaryRules preflight status: %s, rulesBinFromStdSize %d\n", u_errorName(status), rulesBinFromStdSize);
2266 } else {
2267 ubrkBinRules = (uint8_t *)uprv_malloc(rulesBinFromStdSize);
2268 if (ubrkBinRules == NULL) {
2269 log_data_err("FAIL: uprv_malloc fails for ubrkBinRules[%d]\n", rulesBinFromStdSize);
2270 } else {
2271 start = GET_START();
2272 rulesBinFromStdSize = ubrk_getBinaryRules(ubrkFromSource, ubrkBinRules, rulesBinFromStdSize, &status);
2273 duration = GET_DURATION(start, info);
2274 if (U_FAILURE(status)) {
2275 log_err("FAIL: ubrk_getBinaryRules status: %s, rulesBinFromStdSize %d\n", u_errorName(status), rulesBinFromStdSize);
2276 } else {
2277 log_info(" ubrk_getBinaryRules size %d, nsec %llu\n", rulesBinFromStdSize, duration);
2278
2279 status = U_ZERO_ERROR;
2280 start = GET_START();
2281 // ubrk_openBinaryRules does not copy the binary rules, they must be kept around while ubrkBinFromSource is open
2282 ubrkBinFromSource = ubrk_openBinaryRules(ubrkBinRules, rulesBinFromStdSize, NULL, 0, &status);
2283 duration = GET_DURATION(start, info);
2284 if (U_FAILURE(status)) {
2285 log_err("FAIL: ubrk_openBinaryRules status: %s\n", u_errorName(status));
2286 } else {
2287 log_info(" ubrk_openBinaryRules nsec %llu\n", duration);
2288 }
2289
2290 status = U_ZERO_ERROR;
2291 start = GET_START();
2292 utokBinFromSource = urbtok_openBinaryRules(ubrkBinRules, &status);
2293 duration = GET_DURATION(start, info);
2294 if (U_FAILURE(status)) {
2295 log_err("FAIL: urbtok_openBinaryRules status: %s\n", u_errorName(status));
2296 } else {
2297 log_info(" urbtok_openBinaryRules nsec %llu\n", duration);
2298 }
2299
2300 status = U_ZERO_ERROR;
2301 utok57BinFromSource = urbtok57_openBinaryRules(ubrkBinRules, &status);
2302 if (U_SUCCESS(status)) {
2303 log_err("FAIL: urbtok57_openBinaryRules with new rules succeeded but should have failed\n");
2304 ubrk_close(utok57BinFromSource);
2305 utok57BinFromSource = NULL;
2306 }
2307 }
2308 // ubrkBinRules is freed at the end of the main loop
2309 }
2310 }
2311 }
2312 status = U_ZERO_ERROR;
2313 start = GET_START();
2314 utokFromSource = urbtok_open(UBRK_WORD, "root", &status);
2315 duration = GET_DURATION(start, info);
2316 if (U_FAILURE(status)) {
2317 log_err("FAIL: urbtok_open WORD for root, status: %s\n", u_errorName(status));
2318 } else {
2319 log_info(" urbtok_open nsec %llu\n", duration);
2320 }
2321 } else {
2322 // use source rules, including custom rules from CoreNLP
2323 int32_t rulesUTF16Size;
2324 UChar* rulesUTF16Buf = NULL;
2325 long rulesUTF8Size;
2326 char * rulesUTF8Buf = (char *)dataBufFromFile(ruleTypePtr->rulesSource, &rulesUTF8Size);
2327 // dataBufFromFile already logged any errors leading to NULL return
2328 if (rulesUTF8Buf) {
2329 long rulesUTF8Offset = 0;
2330 /* Handle UTF8 BOM: */
2331 if (uprv_strncmp(rulesUTF8Buf, "\xEF\xBB\xBF", 3) == 0) {
2332 rulesUTF8Offset = 3;
2333 rulesUTF8Size -= rulesUTF8Offset;
2334 }
2335 u_strFromUTF8(NULL, 0, &rulesUTF16Size, rulesUTF8Buf+rulesUTF8Offset, rulesUTF8Size, &status); /* preflight */
2336 if (status == U_BUFFER_OVERFLOW_ERROR) { /* expected for preflight */
2337 status = U_ZERO_ERROR;
2338 }
2339 if (U_FAILURE(status)) {
2340 log_data_err("FAIL: for %s, u_strFromUTF8 preflight fails: %s\n", ruleTypePtr->rulesSource, u_errorName(status));
2341 } else {
2342 rulesUTF16Buf = (UChar *)uprv_malloc(rulesUTF16Size*sizeof(UChar));
2343 if (rulesUTF16Buf == NULL) {
2344 log_data_err("FAIL: for %s, uprv_malloc fails for rulesUTF16Buf[%ld]\n", ruleTypePtr->rulesSource, rulesUTF16Size*sizeof(UChar));
2345 } else {
2346 u_strFromUTF8(rulesUTF16Buf, rulesUTF16Size, &rulesUTF16Size, rulesUTF8Buf+rulesUTF8Offset, rulesUTF8Size, &status);
2347 if (U_FAILURE(status)) {
2348 log_data_err("FAIL: for %s, u_strFromUTF8 fails: %s\n", ruleTypePtr->rulesSource, u_errorName(status));
2349 uprv_free(rulesUTF16Buf);
2350 rulesUTF16Buf = NULL;
2351 }
2352 }
2353 }
2354 uprv_free(rulesUTF8Buf);
2355 }
2356 if (rulesUTF16Buf) {
2357 UParseError parseErr;
2358
2359 status = U_ZERO_ERROR;
2360 start = GET_START();
2361 ubrkFromSource = ubrk_openRules(rulesUTF16Buf, rulesUTF16Size, NULL, 0, &parseErr, &status);
2362 duration = GET_DURATION(start, info);
2363 if (U_FAILURE(status)) {
2364 log_err("FAIL: ubrk_openRules %s status: %s, line %d, col %d\n", ruleTypePtr->rulesSource, u_errorName(status), parseErr.line, parseErr.offset);
2365 } else {
2366 log_info(" ubrk_openRules nsec %llu\n", duration);
2367 }
2368
2369 status = U_ZERO_ERROR;
2370 start = GET_START();
2371 utokFromSource = urbtok_openRules(rulesUTF16Buf, rulesUTF16Size, &parseErr, &status);
2372 duration = GET_DURATION(start, info);
2373 if (U_FAILURE(status)) {
2374 log_err("FAIL: urbtok_openRules %s status: %s, line %d, col %d\n", ruleTypePtr->rulesSource, u_errorName(status), parseErr.line, parseErr.offset);
2375 } else {
2376 log_info(" urbtok_openRules nsec %llu\n", duration);
2377 }
2378
2379 status = U_ZERO_ERROR;
2380 start = GET_START();
2381 utok57FromSource = urbtok57_openRules(rulesUTF16Buf, rulesUTF16Size, &parseErr, &status);
2382 duration = GET_DURATION(start, info);
2383 if (U_FAILURE(status)) {
2384 if (ruleTypePtr->rulesBin57) {
2385 // Have binary, source should word
2386 log_err("FAIL: urbtok57_openRules %s status: %s, line %d, col %d\n", ruleTypePtr->rulesSource, u_errorName(status), parseErr.line, parseErr.offset);
2387 } else {
2388 // Source may use new syntax not compatible with urbtok57
2389 log_info(" urbtok57_openRules cannot handle %s, status: %s, line %d, col %d\n", ruleTypePtr->rulesSource, u_errorName(status), parseErr.line, parseErr.offset);
2390 }
2391 } else {
2392 log_info(" urbtok57_openRules nsec %llu\n", duration);
2393 }
2394
2395 uprv_free(rulesUTF16Buf);
2396 }
2397 if (ubrkFromSource) {
2398 status = U_ZERO_ERROR;
2399 int32_t rulesBinFromSourceSize = ubrk_getBinaryRules(ubrkFromSource, NULL, 0, &status);
2400 if (U_FAILURE(status)) {
2401 log_err("FAIL: ubrk_getBinaryRules preflight status: %s, rulesBinFromSourceSize %d\n", u_errorName(status), rulesBinFromSourceSize);
2402 } else {
2403 ubrkBinRules = (uint8_t *)uprv_malloc(rulesBinFromSourceSize);
2404 if (ubrkBinRules == NULL) {
2405 log_data_err("FAIL: uprv_malloc fails for ubrk ubrkBinRules[%d]\n", rulesBinFromSourceSize);
2406 } else {
2407 start = GET_START();
2408 rulesBinFromSourceSize = ubrk_getBinaryRules(ubrkFromSource, ubrkBinRules, rulesBinFromSourceSize, &status);
2409 duration = GET_DURATION(start, info);
2410 if (U_FAILURE(status)) {
2411 log_err("FAIL: ubrk_getBinaryRules status: %s, rulesBinFromSourceSize %d\n", u_errorName(status), rulesBinFromSourceSize);
2412 } else {
2413 log_info(" ubrk_getBinaryRules size %d, nsec %llu\n", rulesBinFromSourceSize, duration);
2414
2415 start = GET_START();
2416 // ubrk_openBinaryRules does not copy the binary rules, they must be kept around while ubrkBinFromSource is open
2417 ubrkBinFromSource = ubrk_openBinaryRules(ubrkBinRules, rulesBinFromSourceSize, NULL, 0, &status);
2418 duration = GET_DURATION(start, info);
2419 if (U_FAILURE(status)) {
2420 log_err("FAIL: ubrk_openBinaryRules status: %s\n", u_errorName(status));
2421 } else {
2422 log_info(" ubrk_openBinaryRules nsec %llu\n", duration);
2423 }
2424 }
2425 // ubrkBinRules is freed at the end of the main loop
2426 }
2427 }
2428 }
2429
2430 if (utokFromSource) {
2431 status = U_ZERO_ERROR;
2432 int32_t rulesBinFromSourceSize = urbtok_getBinaryRules(utokFromSource, NULL, 0, &status);
2433 if (U_FAILURE(status)) {
2434 log_err("FAIL: urbtok_getBinaryRules preflight status: %s, rulesBinFromSourceSize %d\n", u_errorName(status), rulesBinFromSourceSize);
2435 } else {
2436 uint8_t* rulesBinFromSource = (uint8_t *)uprv_malloc(rulesBinFromSourceSize);
2437 if (rulesBinFromSource == NULL) {
2438 log_data_err("FAIL: uprv_malloc fails for urbtok rulesBinFromSource[%d]\n", rulesBinFromSourceSize);
2439 } else {
2440 start = GET_START();
2441 rulesBinFromSourceSize = urbtok_getBinaryRules(utokFromSource, rulesBinFromSource, rulesBinFromSourceSize, &status);
2442 duration = GET_DURATION(start, info);
2443 if (U_FAILURE(status)) {
2444 log_err("FAIL: urbtok_getBinaryRules status: %s, rulesBinFromSourceSize %d\n", u_errorName(status), rulesBinFromSourceSize);
2445 } else {
2446 log_info(" urbtok_getBinaryRules size %d, nsec %llu\n", rulesBinFromSourceSize, duration);
2447
2448 status = U_ZERO_ERROR;
2449 start = GET_START();
2450 // ubrk_openBinaryRules does copy the binary rules, they can be freed at the end of this block
2451 utokBinFromSource = urbtok_openBinaryRules(rulesBinFromSource, &status);
2452 duration = GET_DURATION(start, info);
2453 if (U_FAILURE(status)) {
2454 log_err("FAIL: urbtok_openBinaryRules from source status: %s\n", u_errorName(status));
2455 } else {
2456 log_info(" urbtok_openBinaryRules from source nsec %llu\n", duration);
2457 }
2458
2459 status = U_ZERO_ERROR;
2460 utok57BinFromSource = urbtok57_openBinaryRules(rulesBinFromSource, &status);
2461 if (U_SUCCESS(status)) {
2462 log_err("FAIL: urbtok57_openBinaryRules with new rules succeeded but should have failed\n");
2463 ubrk_close(utok57BinFromSource);
2464 utok57BinFromSource = NULL;
2465 }
2466
2467 if (ruleTypePtr->rulesBin) {
2468 long rulesBinSize;
2469 uint8_t* rulesBinBuf = (uint8_t*)dataBufFromFile(ruleTypePtr->rulesBin, &rulesBinSize);
2470 // dataBufFromFile already logged any errors leading to NULL return
2471 if (rulesBinBuf) {
2472 log_info(" get urbtok binary rules from file, rulesBinSize %d\n", rulesBinSize);
2473 status = U_ZERO_ERROR;
2474 start = GET_START();
2475 utokBinFromFile = urbtok_openBinaryRules(rulesBinBuf, &status);
2476 duration = GET_DURATION(start, info);
2477 if (U_FAILURE(status)) {
2478 log_err("FAIL: urbtok_openBinaryRules from file status: %s\n", u_errorName(status));
2479 } else {
2480 log_info(" urbtok_openBinaryRules from file nsec %llu\n", duration);
2481 }
2482 uprv_free(rulesBinBuf);
2483 }
2484 }
2485 }
2486 uprv_free(rulesBinFromSource);
2487 }
2488 }
2489 }
2490
2491 if (utok57FromSource) {
2492 status = U_ZERO_ERROR;
2493 int32_t rulesBinFromSourceSize = urbtok57_getBinaryRules(utok57FromSource, NULL, 0, &status);
2494 if (U_FAILURE(status)) {
2495 log_err("FAIL: urbtok57_getBinaryRules preflight status: %s, rulesBinFromSourceSize %d\n", u_errorName(status), rulesBinFromSourceSize);
2496 } else {
2497 uint8_t* rulesBinFromSource = (uint8_t *)uprv_malloc(rulesBinFromSourceSize);
2498 if (rulesBinFromSource == NULL) {
2499 log_data_err("FAIL: uprv_malloc fails for urbtok57 rulesBinFromSource[%d]\n", rulesBinFromSourceSize);
2500 } else {
2501 start = GET_START();
2502 rulesBinFromSourceSize = urbtok57_getBinaryRules(utok57FromSource, rulesBinFromSource, rulesBinFromSourceSize, &status);
2503 duration = GET_DURATION(start, info);
2504 if (U_FAILURE(status)) {
2505 log_err("FAIL: urbtok57_getBinaryRules status: %s, rulesBinFromSourceSize %d\n", u_errorName(status), rulesBinFromSourceSize);
2506 } else {
2507 log_info(" urbtok57_getBinaryRules size %d, nsec %llu\n", rulesBinFromSourceSize, duration);
2508
2509 status = U_ZERO_ERROR;
2510 start = GET_START();
2511 // ubrk_openBinaryRules does copy the binary rules, they can be freed at the end of this block
2512 utok57BinFromSource = urbtok57_openBinaryRules(rulesBinFromSource, &status);
2513 duration = GET_DURATION(start, info);
2514 if (U_FAILURE(status)) {
2515 log_err("FAIL: urbtok57_openBinaryRules from source status: %s\n", u_errorName(status));
2516 } else {
2517 log_info(" urbtok57_openBinaryRules from source nsec %llu\n", duration);
2518 }
2519
2520 if (ruleTypePtr->rulesBin57) {
2521 long rulesBinSize;
2522 uint8_t* rulesBinBuf = (uint8_t*)dataBufFromFile(ruleTypePtr->rulesBin57, &rulesBinSize);
2523 // dataBufFromFile already logged any errors leading to NULL return
2524 if (rulesBinBuf) {
2525 log_info(" get urbtok57 binary rules from file, rulesBinSize %d\n", rulesBinSize);
2526 status = U_ZERO_ERROR;
2527 start = GET_START();
2528 utok57BinFromFile = urbtok57_openBinaryRules(rulesBinBuf, &status);
2529 duration = GET_DURATION(start, info);
2530 if (U_FAILURE(status)) {
2531 log_err("FAIL: urbtok57_openBinaryRules from file status: %s\n", u_errorName(status));
2532 } else {
2533 log_info(" urbtok57_openBinaryRules file nsec %llu\n", duration);
2534 }
2535 uprv_free(rulesBinBuf);
2536 }
2537 }
2538 }
2539 uprv_free(rulesBinFromSource);
2540 }
2541 }
2542 }
2543 }
2544
2545 if (ubrkFromSource) {
2546 // Test tokenization
2547 const TokTextAndResults* textResultsPtr;
2548 for (textResultsPtr = ruleTypePtr->textAndResults; textResultsPtr->descrip != NULL; textResultsPtr++) {
2549 RuleBasedTokenRange tokens[kMaxTokens];
2550 unsigned long flags[kMaxTokens];
2551 RuleBasedTokenRange *tokenLimit = tokens + kMaxTokens;
2552 RuleBasedTokenRange *tokenP;
2553 unsigned long *flagsP;
2554 int32_t iTest, numTokens;
2555 const char* testType[] = { "source", "binFromSource", "binFromFile" };
2556 int32_t textLen = u_strlen(textResultsPtr->tokText);
2557 log_info("-- starting tests for rule/text combo %s, text UTF16 units: %d\n", textResultsPtr->descrip, textLen);
2558
2559 if (ubrkFromSource || ubrkBinFromSource) {
2560 for (iTest = 0; iTest < 2; iTest++) {
2561 UBreakIterator* ubrk = (iTest==0)? ubrkFromSource: ubrkBinFromSource;
2562 if (ubrk) {
2563 int32_t offset, lastOffset;
2564 // Do ubrk loop tests
2565 status = U_ZERO_ERROR;
2566 ubrk_setText(ubrk, textResultsPtr->tokText, textLen, &status);
2567 if (U_FAILURE(status)) {
2568 log_err("FAIL: %s ubrk_setText ubrk %s status: %s\n", textResultsPtr->descrip, testType[iTest], u_errorName(status));
2569 } else {
2570 start = GET_START();
2571 lastOffset = ubrk_current(ubrk);
2572 for (tokenP = tokens, flagsP = flags; tokenP < tokenLimit && (offset = ubrk_next(ubrk)) != UBRK_DONE;) {
2573 int32_t flagSet = ubrk_getRuleStatus(ubrk);
2574 if (flagSet != -1) {
2575 int32_t flagVec[8];
2576 int32_t flagCount;
2577 UErrorCode locStatus = U_ZERO_ERROR;
2578
2579 tokenP->location = lastOffset;
2580 tokenP++->length = offset - lastOffset;
2581 flagCount = ubrk_getRuleStatusVec(ubrk, flagVec, 8, &locStatus);
2582 if (U_SUCCESS(locStatus) && flagCount-- > 1) {
2583 // skip last flagVec entry since we have from ubrk_getRuleStatus above
2584 int32_t flagIdx;
2585 for (flagIdx = 0; flagIdx < flagCount; flagIdx++) {
2586 flagSet |= flagVec[flagIdx];
2587 }
2588 }
2589 *flagsP++ = (unsigned long)flagSet;
2590 }
2591 lastOffset = offset;
2592 }
2593 numTokens = tokenP - tokens;
2594 duration = GET_DURATION(start, info);
2595
2596 handleTokResults(textResultsPtr->descrip, "ubrk", testType[iTest], "(loop)", duration,
2597 textResultsPtr->expTokLen, textResultsPtr->expTok, numTokens, tokens, flags);
2598 }
2599 }
2600 }
2601 }
2602
2603 if (utokFromSource || utokBinFromSource) {
2604 for (iTest = 0; iTest < 3; iTest++) {
2605 UBreakIterator* utok = (iTest==0)? utokFromSource: ((iTest==1)? utokBinFromSource: utokBinFromFile);
2606 if (utok) {
2607 // Do utok loop & bulk tests
2608 status = U_ZERO_ERROR;
2609 ubrk_setText(utok, textResultsPtr->tokText, textLen, &status);
2610 if (U_FAILURE(status)) {
2611 log_err("FAIL: %s ubrk_setText utok %s (loop) status: %s\n", textResultsPtr->descrip, testType[iTest], u_errorName(status));
2612 } else {
2613 start = GET_START();
2614 for (tokenP = tokens, flagsP = flags; tokenP < tokenLimit && urbtok_tokenize(utok, 1, tokenP, flagsP) == 1; tokenP++, flagsP++) {
2615 ;
2616 }
2617 numTokens = tokenP - tokens;
2618 duration = GET_DURATION(start, info);
2619
2620 if (iTest < 2) {
2621 handleTokResults(textResultsPtr->descrip, "utok", testType[iTest], "(loop)", duration,
2622 textResultsPtr->expTokLen, textResultsPtr->expTok, numTokens, tokens, flags);
2623 } else {
2624 handleTokResults(textResultsPtr->descrip, "utok", testType[iTest], "(loop)", duration,
2625 textResultsPtr->expTokFileLen, textResultsPtr->expTokFile, numTokens, tokens, flags);
2626 }
2627 }
2628
2629 status = U_ZERO_ERROR;
2630 ubrk_setText(utok, textResultsPtr->tokText, textLen, &status);
2631 if (U_FAILURE(status)) {
2632 log_err("FAIL: %s ubrk_setText utok %s (bulk) status: %s\n", textResultsPtr->descrip, testType[iTest], u_errorName(status));
2633 } else {
2634 start = GET_START();
2635 numTokens = urbtok_tokenize(utok, kMaxTokens, tokens, flags);
2636 duration = GET_DURATION(start, info);
2637
2638 if (iTest < 2) {
2639 handleTokResults(textResultsPtr->descrip, "utok", testType[iTest], "(bulk)", duration,
2640 textResultsPtr->expTokLen, textResultsPtr->expTok, numTokens, tokens, flags);
2641 } else {
2642 handleTokResults(textResultsPtr->descrip, "utok", testType[iTest], "(bulk)", duration,
2643 textResultsPtr->expTokFileLen, textResultsPtr->expTokFile, numTokens, tokens, flags);
2644 }
2645 }
2646 }
2647 }
2648 }
2649
2650 if (utok57FromSource || utok57BinFromSource) {
2651 for (iTest = 0; iTest < 3; iTest++) {
2652 UBreakIterator* utok57 = (iTest==0)? utok57FromSource: ((iTest==1)? utok57BinFromSource: utok57BinFromFile);;
2653 if (utok57) {
2654 // Do utok57 loop & bulk tests
2655 status = U_ZERO_ERROR;
2656 ubrk_setText(utok57, textResultsPtr->tokText, textLen, &status);
2657 if (U_FAILURE(status)) {
2658 log_err("FAIL: %s ubrk_setText utok57 %s (loop) status: %s\n", textResultsPtr->descrip, testType[iTest], u_errorName(status));
2659 } else {
2660 start = GET_START();
2661 for (tokenP = tokens, flagsP = flags; tokenP < tokenLimit && urbtok57_tokenize(utok57, 1, tokenP, flagsP) == 1; tokenP++, flagsP++) {
2662 ;
2663 }
2664 numTokens = tokenP - tokens;
2665 duration = GET_DURATION(start, info);
2666
2667 handleTokResults(textResultsPtr->descrip, "utok57", testType[iTest], "(loop)", duration,
2668 textResultsPtr->expTok57LoopLen, textResultsPtr->expTok57Loop, numTokens, tokens, flags);
2669 }
2670
2671 status = U_ZERO_ERROR;
2672 ubrk_setText(utok57, textResultsPtr->tokText, textLen, &status);
2673 if (U_FAILURE(status)) {
2674 log_err("FAIL: %s ubrk_setText utok57 %s (bulk) status: %s\n", textResultsPtr->descrip, testType[iTest], u_errorName(status));
2675 } else {
2676 start = GET_START();
2677 numTokens = urbtok57_tokenize(utok57, kMaxTokens, tokens, flags);
2678 duration = GET_DURATION(start, info);
2679
2680 handleTokResults(textResultsPtr->descrip, "utok57", testType[iTest], "(bulk)", duration,
2681 textResultsPtr->expTok57BulkLen, textResultsPtr->expTok57Bulk, numTokens, tokens, flags);
2682 }
2683 }
2684 }
2685 }
2686 }
2687 }
2688
2689 // Close UBreakIterators and rule memory, don't need to check for NULL
2690 ubrk_close(ubrkFromSource);
2691 ubrk_close(ubrkBinFromSource);
2692 ubrk_close(utokFromSource);
2693 ubrk_close(utokBinFromSource);
2694 ubrk_close(utokBinFromFile);
2695 ubrk_close(utok57FromSource);
2696 ubrk_close(utok57BinFromSource);
2697 ubrk_close(utok57BinFromFile);
2698 uprv_free(ubrkBinRules);
2699 }
2700 }
2701
2702
2703
2704 #endif
2705
2706
2707 #endif /* #if !UCONFIG_NO_BREAK_ITERATION */