@@ -155,6 +155,9 @@ int grapheme_strpos_utf16(unsigned char *haystack, int32_t haystack_len, unsigne
155
155
status = U_ZERO_ERROR ;
156
156
bi = grapheme_get_break_iterator (u_break_iterator_buffer , & status TSRMLS_CC );
157
157
STRPOS_CHECK_STATUS (status , "Failed to get iterator" );
158
+ status = U_ZERO_ERROR ;
159
+ ubrk_setText (bi , uhaystack , uhaystack_len , & status );
160
+ STRPOS_CHECK_STATUS (status , "Failed to set up iterator" );
158
161
159
162
status = U_ZERO_ERROR ;
160
163
src = usearch_open (uneedle , uneedle_len , uhaystack , uhaystack_len , "" , bi , & status );
@@ -169,7 +172,7 @@ int grapheme_strpos_utf16(unsigned char *haystack, int32_t haystack_len, unsigne
169
172
}
170
173
171
174
if (offset != 0 ) {
172
- offset_pos = grapheme_get_haystack_offset (bi , uhaystack , uhaystack_len , offset );
175
+ offset_pos = grapheme_get_haystack_offset (bi , offset );
173
176
if (offset_pos == -1 ) {
174
177
status = U_ILLEGAL_ARGUMENT_ERROR ;
175
178
STRPOS_CHECK_STATUS (status , "Invalid search offset" );
@@ -191,7 +194,7 @@ int grapheme_strpos_utf16(unsigned char *haystack, int32_t haystack_len, unsigne
191
194
}
192
195
STRPOS_CHECK_STATUS (status , "Error looking up string" );
193
196
if (char_pos != USEARCH_DONE && ubrk_isBoundary (bi , char_pos )) {
194
- ret_pos = grapheme_count_graphemes (bi , uhaystack , char_pos );
197
+ ret_pos = grapheme_count_graphemes (bi , uhaystack ,char_pos );
195
198
if (puchar_pos ) {
196
199
* puchar_pos = char_pos ;
197
200
}
@@ -290,18 +293,12 @@ int32_t grapheme_count_graphemes(UBreakIterator *bi, UChar *string, int32_t stri
290
293
291
294
292
295
/* {{{ grapheme_get_haystack_offset - bump the haystack pointer based on the grapheme count offset */
293
- int grapheme_get_haystack_offset (UBreakIterator * bi , UChar * uhaystack , int32_t uhaystack_len , int32_t offset )
296
+ int grapheme_get_haystack_offset (UBreakIterator * bi , int32_t offset )
294
297
{
295
- UErrorCode status ;
296
298
int32_t pos ;
297
299
int32_t (* iter_op )(UBreakIterator * bi );
298
300
int iter_incr ;
299
301
300
- if ( NULL != bi ) {
301
- status = U_ZERO_ERROR ;
302
- ubrk_setText (bi , uhaystack , uhaystack_len , & status );
303
- }
304
-
305
302
if ( 0 == offset ) {
306
303
return 0 ;
307
304
}
0 commit comments