From d59937ca545474202762c5f39f6a16b12193950f Mon Sep 17 00:00:00 2001 From: Karl Williamson Date: Sat, 6 Apr 2013 12:50:48 -0600 Subject: [PATCH] utf8.c: Use macro instead of duplicating code There is a macro that accomplishes this task, and is easier to read. --- utf8.c | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/utf8.c b/utf8.c index 965cd14..1570fc8 100644 --- a/utf8.c +++ b/utf8.c @@ -1268,14 +1268,14 @@ Perl_utf8_to_bytes(pTHX_ U8 *s, STRLEN *len) /* ensure valid UTF-8 and chars < 256 before updating string */ while (s < send) { - U8 c = *s++; - - if (!UTF8_IS_INVARIANT(c) && - (!UTF8_IS_DOWNGRADEABLE_START(c) || (s >= send) - || !(c = *s++) || !UTF8_IS_CONTINUATION(c))) { - *len = ((STRLEN) -1); - return 0; + if (! UTF8_IS_INVARIANT(*s)) { + if (! UTF8_IS_NEXT_CHAR_DOWNGRADEABLE(s, send)) { + *len = ((STRLEN) -1); + return 0; + } + s++; } + s++; } d = s = save; @@ -1319,14 +1319,14 @@ Perl_bytes_from_utf8(pTHX_ const U8 *s, STRLEN *len, bool *is_utf8) /* ensure valid UTF-8 and chars < 256 before converting string */ for (send = s + *len; s < send;) { - U8 c = *s++; - if (!UTF8_IS_INVARIANT(c)) { - if (UTF8_IS_DOWNGRADEABLE_START(c) && s < send && - (c = *s++) && UTF8_IS_CONTINUATION(c)) - count++; - else + if (! UTF8_IS_INVARIANT(*s)) { + if (! UTF8_IS_NEXT_CHAR_DOWNGRADEABLE(s, send)) { return (U8 *)start; + } + count++; + s++; } + s++; } *is_utf8 = FALSE; -- 2.7.4