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