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