2 ******************************************************************************
3 * Copyright (C) 2006-2008, 2017 Apple Inc. All Rights Reserved.
4 ******************************************************************************
10 #include "unicode/utypes.h"
12 #if !UCONFIG_NO_BREAK_ITERATION
14 #include "unicode/utext.h"
15 #include "unicode/ubrk.h"
16 #include "unicode/parseerr.h"
19 * The interfaces here are meant to extend the functionality of the standard
20 * ubrk_* interfaces in ubrk.h to allow for faster batch tokenization. This
21 * was primarily intended for Spotlight and related processes. Note that
22 * urbtok_tokenize here does not fully support all features of ICU break rules.
25 typedef struct RuleBasedTokenRange
{
28 } RuleBasedTokenRange
;
31 * Open a new UBreakIterator for tokenizing text using specified breaking rules.
32 * The rule syntax is ... (TBD)
33 * @param rules A set of rules specifying the text breaking conventions.
34 * @param rulesLength The number of characters in rules, or -1 if null-terminated.
35 * @param parseErr Receives position and context information for any syntax errors
36 * detected while parsing the rules.
37 * @param status A UErrorCode to receive any errors.
38 * @return A UBreakIterator for the specified rules.
42 U_INTERNAL UBreakIterator
* U_EXPORT2
43 urbtok_openRules(const UChar
*rules
,
45 UParseError
*parseErr
,
49 * Open a new UBreakIterator for tokenizing text using specified breaking rules.
50 * @param rules A set of rules specifying the text breaking conventions. The binary rules
51 * must be at least 32-bit aligned. Note: This version makes a copy of the
52 * rules, so after calling this function the caller can close or release
53 * the rules that were passed to this function. The copy created by this
54 * call will be freed when ubrk_close() is called on the UBreakIterator*.
55 * @param status A UErrorCode to receive any errors.
56 * @return A UBreakIterator for the specified rules.
60 U_INTERNAL UBreakIterator
* U_EXPORT2
61 urbtok_openBinaryRules(const uint8_t *rules
,
65 * Open a new UBreakIterator for tokenizing text using specified breaking rules.
66 * @param rules A set of rules specifying the text breaking conventions. The binary rules
67 * must be at least 32-bit aligned. Note: This version does NOT make a copy
68 * of the rules, so after calling this function the caller must not close or
69 * release the rules passed to this function until after they are finished
70 * with this UBreakIterator* (and any others created using the same rules)
71 * and have called ubrk_close() to close the UBreakIterator* (and any others
72 * using the same rules).
73 * @param status A UErrorCode to receive any errors.
74 * @return A UBreakIterator for the specified rules.
78 U_INTERNAL UBreakIterator
* U_EXPORT2
79 urbtok_openBinaryRulesNoCopy(const uint8_t *rules
,
83 * Get the (native-endian) binary break rules for this tokenizer.
84 * @param bi The tokenizer to use.
85 * @param buffer The output buffer for the rules. You can pass 0 to get the required size.
86 * @param buffSize The size of the output buffer.
87 * @param status A UErrorCode to receive any errors.
88 * @return The actual size of the binary rules, whether they fit the buffer or not.
91 U_INTERNAL
uint32_t U_EXPORT2
92 urbtok_getBinaryRules(UBreakIterator
*bi
,
98 * Tokenize text using a rule-based tokenizer.
99 * This is primarily intended for speedy batch tokenization using very simple rules.
100 * It does not currently implement support for all of the features of ICU break rules
101 * (adding that would reduce performance). If you need support for all of the ICU rule
102 * features, please use the standard ubrk_* interfaces; instead of urbtok_tokenize,
103 * use a loop with ubrk_next and ubrk_getRuleStatus.
105 * @param bi The tokenizer to use.
106 * @param maxTokens The maximum number of tokens to return.
107 * @param outTokens An array of RuleBasedTokenRange to fill in with the tokens.
108 * @param outTokenFlags An (optional) array of uint32_t to fill in with token flags.
109 * @return The number of tokens returned, 0 if done.
112 U_INTERNAL
int32_t U_EXPORT2
113 urbtok_tokenize(UBreakIterator
*bi
,
115 RuleBasedTokenRange
*outTokens
,
116 unsigned long *outTokenFlags
);
119 * Swap the endianness of a set of binary break rules.
120 * @param rules A set of rules which need swapping.
121 * @param buffer The output buffer for the swapped rules, which must be the same
122 * size as the input rules buffer.
123 * @param inIsBigEndian UBool indicating whether the input is big-endian
124 * @param outIsBigEndian UBool indicating whether the output should be big-endian
125 * @param status A UErrorCode to receive any errors.
128 U_INTERNAL
void U_EXPORT2
129 urbtok_swapBinaryRules(const uint8_t *rules
,
132 UBool outIsBigEndian
,
136 #endif /* #if !UCONFIG_NO_BREAK_ITERATION */