summaryrefslogtreecommitdiff
path: root/utf8.c
diff options
context:
space:
mode:
authorNicholas Clark <nick@ccl4.org>2006-03-20 12:37:22 +0000
committerNicholas Clark <nick@ccl4.org>2006-03-20 12:37:22 +0000
commitbf1665bcc8f6722faa3c19404edba61541d05501 (patch)
tree92d71f2de7ae463a97c869519b2ad213e5e26374 /utf8.c
parenteb63405fd7f24e5bad9ec7f42adce6af6314724e (diff)
downloadperl-bf1665bcc8f6722faa3c19404edba61541d05501.tar.gz
Perl_utf8_distance can be implemented as a call to Perl_utf8_length.
p4raw-id: //depot/perl@27553
Diffstat (limited to 'utf8.c')
-rw-r--r--utf8.c34
1 files changed, 1 insertions, 33 deletions
diff --git a/utf8.c b/utf8.c
index af63ac3766..2de924ff8c 100644
--- a/utf8.c
+++ b/utf8.c
@@ -703,39 +703,7 @@ same UTF-8 buffer.
IV
Perl_utf8_distance(pTHX_ const U8 *a, const U8 *b)
{
- dVAR;
- IV off = 0;
- IV sign = 1;
-
- /* Note: cannot use UTF8_IS_...() too eagerly here since e.g.
- * the bitops (especially ~) can create illegal UTF-8.
- * In other words: in Perl UTF-8 is not just for Unicode. */
-
- if (a < b) {
- const U8 *const temp = a;
- a = b;
- b = temp;
- sign = -1;
- }
-
- while (b < a) {
- const U8 c = UTF8SKIP(b);
-
- if (a - b < c) {
- if (ckWARN_d(WARN_UTF8)) {
- if (PL_op)
- Perl_warner(aTHX_ packWARN(WARN_UTF8),
- "%s in %s", unees, OP_DESC(PL_op));
- else
- Perl_warner(aTHX_ packWARN(WARN_UTF8), unees);
- }
- return off * sign;
- }
- b += c;
- off++;
- }
-
- return off * sign;
+ return (a < b) ? -1 * (IV) utf8_length(a, b) : (IV) utf8_length(b, a);
}
/*