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