+U_CAPI UBreakIterator* U_EXPORT2
+urbtok57_openRules(const UChar *rules,
+ int32_t rulesLength,
+ UParseError *parseErr,
+ UErrorCode *status)
+{
+ if (status == NULL || U_FAILURE(*status)){
+ return 0;
+ }
+
+ BreakIterator *result = 0;
+ UnicodeString ruleString(rules, rulesLength);
+ result = new RuleBasedTokenizer(ruleString, *parseErr, *status);
+ if(U_FAILURE(*status)) {
+ return 0;
+ }
+
+ UBreakIterator *uBI = (UBreakIterator *)result;
+ return uBI;
+}
+
+U_CAPI UBreakIterator* U_EXPORT2
+urbtok57_openBinaryRules(const uint8_t *rules,
+ UErrorCode *status)
+{
+ if (status == NULL || U_FAILURE(*status)){
+ return 0;
+ }
+
+ uint32_t length = ((const RBBIDataHeader57 *)rules)->fLength;
+ uint8_t *ruleCopy = (uint8_t *) uprv_malloc(length);
+ if (ruleCopy == 0)
+ {
+ *status = U_MEMORY_ALLOCATION_ERROR;
+ return 0;
+ }
+ // Copy the rules so they can be adopted by the tokenizer
+ uprv_memcpy(ruleCopy, rules, length);
+ BreakIterator *result = 0;
+ result = new RuleBasedTokenizer(ruleCopy, *status);
+ if(U_FAILURE(*status)) {
+ return 0;
+ }
+
+ UBreakIterator *uBI = (UBreakIterator *)result;
+ return uBI;
+}
+
+U_CAPI UBreakIterator* U_EXPORT2
+urbtok57_openBinaryRulesNoCopy(const uint8_t *rules,
+ UErrorCode *status)
+{
+ if (status == NULL || U_FAILURE(*status)){
+ return 0;
+ }
+
+ BreakIterator *result = 0;
+ result = new RuleBasedTokenizer(rules, RuleBasedTokenizer::kDontAdopt, *status);
+ if(U_FAILURE(*status)) {
+ return 0;
+ }
+
+ UBreakIterator *uBI = (UBreakIterator *)result;
+ return uBI;
+}
+
+U_CAPI uint32_t U_EXPORT2
+urbtok57_getBinaryRules(UBreakIterator *bi,
+ uint8_t *buffer,
+ uint32_t buffSize,
+ UErrorCode *status)
+{
+ if (status == NULL || U_FAILURE(*status)){
+ return 0;
+ }
+ if (buffer == NULL && buffSize > 0) {
+ *status = U_ILLEGAL_ARGUMENT_ERROR;
+ return 0;
+ }
+ RuleBasedBreakIterator57 *rbbi57;
+ if ((rbbi57 = dynamic_cast<RuleBasedBreakIterator57*>(reinterpret_cast<BreakIterator*>(bi))) == NULL) {
+ *status = U_ILLEGAL_ARGUMENT_ERROR;
+ return 0;
+ }
+ uint32_t length;
+ const uint8_t *rules = rbbi57->getBinaryRules(length);
+ if (buffer != 0)
+ {
+ if (length > buffSize) {
+ *status = U_BUFFER_OVERFLOW_ERROR;
+ }
+ else {
+ uprv_memcpy(buffer, rules, length);
+ }
+ }
+ return length;
+}
+
+U_CAPI int32_t U_EXPORT2
+urbtok57_tokenize(UBreakIterator *bi,
+ int32_t maxTokens,
+ RuleBasedTokenRange *outTokens,
+ unsigned long *outTokenFlags)
+{
+ return ((RuleBasedTokenizer *)bi)->tokenize(maxTokens, outTokens, outTokenFlags);
+}