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