Skip to content

Commit 7681e1f

Browse files
committed
Change isFOO_utf8_safe macros to return matched byte length
Or 0 when the character isn't of type FOO. This allows these macros to be used as booleans, as previously; or to give you how many bytes there are in the matched UTF-8 character. This was always trivially the case for ASCII-range characters, as the former boolean 0,1 gave you the correct length if they matched. The previous commit extended this to return the length for above-Latin1 characters. This commit is the final piece. Latin1 characters that aren't ASCII always are two bytes. So just multiply the return by 2, yielding 0 if no match or 2 bytes if matched.
1 parent 18111a9 commit 7681e1f

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

handy.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2263,8 +2263,10 @@ END_EXTERN_C
22632263
: (UTF8_IS_ABOVE_LATIN1_START(*(p)) \
22642264
? above_latin1 \
22652265
: ((LIKELY((e) - (p) > 1 && UTF8_IS_CONTINUATION(*((p)+1)))) \
2266-
? generic_isCC_(EIGHT_BIT_UTF8_TO_NATIVE(*(p), *((p)+1 )), \
2267-
classnum) \
2266+
/* Multiply by 2 to return byte length of matched \
2267+
* character */ \
2268+
? 2 * generic_isCC_(EIGHT_BIT_UTF8_TO_NATIVE(*(p),*((p)+1)),\
2269+
classnum) \
22682270
: (force_out_malformed_utf8_message_((U8 *) (p), (U8 *) (e),\
22692271
0, MALFORMED_UTF8_DIE),\
22702272
0))))

0 commit comments

Comments
 (0)