This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Add Vernon Lyon to AUTHORS
[perl5.git] / utf8.c
diff --git a/utf8.c b/utf8.c
index 668b9fa..53085e6 100644 (file)
--- a/utf8.c
+++ b/utf8.c
@@ -2502,16 +2502,18 @@ Perl_sv_uni_display(pTHX_ SV *dsv, SV *ssv, STRLEN pvlim, UV flags)
 }
 
 /*
-=for apidoc ibcmp_utf8
+=for apidoc foldEQ_utf8
 
-Returns true if the strings s1 and s2 differ case-insensitively, false
-if they are equal case-insensitively.
+Returns true if the leading portions of the strings s1 and s2 (either or both
+of which may be in UTF-8) are the same case-insensitively; false otherwise.
+How far into the strings to compare is determined by other input parameters.
 
 If u1 is true, the string s1 is assumed to be in UTF-8-encoded Unicode;
 otherwise it is assumed to be in native 8-bit encoding.  Correspondingly for u2
 with respect to s2.
 
-If the byte length l1 is non-zero, s1+l1 will be used as a goal to reach.  The
+If the byte length l1 is non-zero, it says how far into s1 to check for fold
+equality.  In other words, s1+l1 will be used as a goal to reach.  The
 scan will not be considered to be a match unless the goal is reached, and
 scanning won't continue past that goal.  Correspondingly for l2 with respect to
 s2.
@@ -2520,14 +2522,16 @@ If pe1 is non-NULL and the pointer it points to is not NULL, that pointer is
 considered an end pointer beyond which scanning of s1 will not continue under
 any circumstances.  This means that if both l1 and pe1 are specified, and pe1
 is less than s1+l1, the match will never be successful because it can never
-get as far as its goal.  Correspondingly for pe2 with respect to s2.
+get as far as its goal (and in fact is asserted against).  Correspondingly for
+pe2 with respect to s2.
 
-At least one of s1 and s2 must have a goal, and if both do, both have to be
+At least one of s1 and s2 must have a goal (at least one of l1 and l2 must be
+non-zero), and if both do, both have to be
 reached for a successful match.   Also, if the fold of a character is multiple
 characters, all of them must be matched (see tr21 reference below for
 'folding').
 
-Upon a successful match (when the routine returns false), if pe1 is non-NULL,
+Upon a successful match, if pe1 is non-NULL,
 it will be set to point to the beginning of the I<next> character of s1 beyond
 what was matched.  Correspondingly for pe2 and s2.
 
@@ -2537,7 +2541,7 @@ http://www.unicode.org/unicode/reports/tr21/ (Case Mappings).
 
 =cut */
 I32
-Perl_ibcmp_utf8(pTHX_ const char *s1, char **pe1, register UV l1, bool u1, const char *s2, char **pe2, register UV l2, bool u2)
+Perl_foldEQ_utf8(pTHX_ const char *s1, char **pe1, register UV l1, bool u1, const char *s2, char **pe2, register UV l2, bool u2)
 {
     dVAR;
     register const U8 *p1  = (const U8*)s1; /* Point to current char */
@@ -2554,7 +2558,7 @@ Perl_ibcmp_utf8(pTHX_ const char *s1, char **pe1, register UV l1, bool u1, const
     U8 natbuf[2];               /* Holds native 8-bit char converted to utf8;
                                    these always fit in 2 bytes */
 
-    PERL_ARGS_ASSERT_IBCMP_UTF8;
+    PERL_ARGS_ASSERT_FOLDEQ_UTF8;
 
     if (pe1) {
         e1 = *(U8**)pe1;
@@ -2584,19 +2588,24 @@ Perl_ibcmp_utf8(pTHX_ const char *s1, char **pe1, register UV l1, bool u1, const
         * only go as far as the goal */
         e1 = g1;
     }
-    else assert(e1);    /* Must have an end for looking at s1 */
+    else {
+       assert(e1);    /* Must have an end for looking at s1 */
+    }
 
     /* Same for goal for s2 */
     if (g2) {
         assert(! e2  || e2 >= g2);
         e2 = g2;
     }
-    else assert(e2);
+    else {
+       assert(e2);
+    }
 
     /* Look through both strings, a character at a time */
     while (p1 < e1 && p2 < e2) {
 
-        /* If at the beginning of a new character in s1, get its fold to use */
+        /* If at the beginning of a new character in s1, get its fold to use
+         * and the length of the fold */
         if (n1 == 0) {
             if (u1) {
                 to_utf8_fold(p1, foldbuf1, &n1);
@@ -2629,7 +2638,7 @@ Perl_ibcmp_utf8(pTHX_ const char *s1, char **pe1, register UV l1, bool u1, const
                                                        character */
                 || memNE((char*)f1, (char*)f2, fold_length))
             {
-                return 1; /* mismatch */
+                return 0; /* mismatch */
             }
 
             /* Here, they matched, advance past them */
@@ -2653,7 +2662,7 @@ Perl_ibcmp_utf8(pTHX_ const char *s1, char **pe1, register UV l1, bool u1, const
     * character (which can happen when the fold of a character is more than one
     * character). */
     if (! ((g1 == 0 || p1 == g1) && (g2 == 0 || p2 == g2)) || n1 || n2) {
-        return 1;
+        return 0;
     }
 
     /* Successful match.  Set output pointers */
@@ -2663,7 +2672,7 @@ Perl_ibcmp_utf8(pTHX_ const char *s1, char **pe1, register UV l1, bool u1, const
     if (pe2) {
         *pe2 = (char*)p2;
     }
-    return 0;
+    return 1;
 }
 
 /*