diff options
author | Ilya Zakharevich <ilya@math.berkeley.edu> | 2002-03-03 21:31:04 -0500 |
---|---|---|
committer | Abhijit Menon-Sen <ams@wiw.org> | 2002-03-04 08:40:46 +0000 |
commit | 0d3b7757875e39a336d967574233c80ebdc2f8b6 (patch) | |
tree | 22b4bc180b4848f30cac711cedc72237922494c6 /util.c | |
parent | 99c4c5e8b3aed6f7ee0c58ddf8ec0fe3dfc7e3a6 (diff) | |
download | perl-0d3b7757875e39a336d967574233c80ebdc2f8b6.tar.gz |
sv_cmp and friends
Message-Id: <20020304023103.A14140@math.ohio-state.edu>
p4raw-link: @14577 on //depot/perl: 0ad5258ff3f3328f321188cbb4fcd6a74b365431
p4raw-id: //depot/perl@14985
Diffstat (limited to 'util.c')
-rw-r--r-- | util.c | 33 |
1 files changed, 33 insertions, 0 deletions
@@ -4346,5 +4346,38 @@ Perl_sv_nounlocking(pTHX_ SV *sv) { } +/* +=for apidoc memcmp_byte_utf8 + +Similar to memcmp(), but the first string is with bytes, the second +with utf8. Takes into account that the lengths may be different. +=cut +*/ +int +Perl_memcmp_byte_utf8(pTHX_ char *sb, STRLEN lbyte, char *su, STRLEN lutf) +{ + U8 *sbyte = (U8*)sb; + U8 *sutf = (U8*)su; + U8 *ebyte = sbyte + lbyte; + U8 *eutf = sutf + lutf; + + while (sbyte < ebyte) { + if (sutf >= eutf) + return 1; /* utf one shorter */ + if (*sbyte < 128) { + if (*sbyte != *sutf) + return *sbyte - *sutf; + sbyte++; sutf++; /* CONTINUE */ + } else if ((*sutf & 0x3F) == (*sbyte >> 6)) { /* byte 0xFF: 0xC3 BF */ + if ((sutf[1] & 0x3F) != (*sbyte & 0x3F)) + return (*sbyte & 0x3F) - (*sutf & 0x3F); + sbyte++, sutf += 2; /* CONTINUE */ + } else + return (*sbyte >> 6) - (*sutf & 0x3F); + } + if (sutf >= eutf) + return 0; + return -1; /* byte one shorter */ +} |