File tree Expand file tree Collapse file tree 1 file changed +15
-18
lines changed
ext/mbstring/libmbfl/mbfl Expand file tree Collapse file tree 1 file changed +15
-18
lines changed Original file line number Diff line number Diff line change @@ -840,6 +840,19 @@ static const unsigned char *mbfl_find_offset_utf8(const mbfl_string *str, ssize_
840
840
}
841
841
}
842
842
843
+ static size_t mbfl_pointer_to_offset_utf8 (const unsigned char * start , const unsigned char * pos ) {
844
+ size_t result = 0 ;
845
+ while (pos > start ) {
846
+ unsigned char c = * -- pos ;
847
+ if (c < 0x80 ) {
848
+ ++ result ;
849
+ } else if ((c & 0xc0 ) != 0x80 ) {
850
+ ++ result ;
851
+ }
852
+ }
853
+ return result ;
854
+ }
855
+
843
856
size_t
844
857
mbfl_strpos (
845
858
mbfl_string * haystack ,
@@ -920,15 +933,7 @@ mbfl_strpos(
920
933
q = needle_u8_val + needle_u8_len ;
921
934
for (;;) {
922
935
if (q == needle_u8_val ) {
923
- result = 0 ;
924
- while (p > haystack_u8_val ) {
925
- unsigned char c = * -- p ;
926
- if (c < 0x80 ) {
927
- ++ result ;
928
- } else if ((c & 0xc0 ) != 0x80 ) {
929
- ++ result ;
930
- }
931
- }
936
+ result = mbfl_pointer_to_offset_utf8 (haystack_u8_val , p );
932
937
goto out ;
933
938
}
934
939
if (* -- q != * -- p ) {
@@ -999,16 +1004,8 @@ mbfl_strpos(
999
1004
q = needle_u8_val ;
1000
1005
for (;;) {
1001
1006
if (q == qe ) {
1002
- result = 0 ;
1003
1007
p -= needle_u8_len ;
1004
- while (p > haystack_u8_val ) {
1005
- unsigned char c = * -- p ;
1006
- if (c < 0x80 ) {
1007
- ++ result ;
1008
- } else if ((c & 0xc0 ) != 0x80 ) {
1009
- ++ result ;
1010
- }
1011
- }
1008
+ result = mbfl_pointer_to_offset_utf8 (haystack_u8_val , p );
1012
1009
goto out ;
1013
1010
}
1014
1011
if (* q != * p ) {
You can’t perform that action at this time.
0 commit comments