diff options
author | Jarkko Hietaniemi <jhi@iki.fi> | 2000-11-18 22:50:28 +0000 |
---|---|---|
committer | Jarkko Hietaniemi <jhi@iki.fi> | 2000-11-18 22:50:28 +0000 |
commit | b76347f2eb34c85a0a38543b2f57ca474fedab4d (patch) | |
tree | 31cc323c41bcb1ac42ff13659898c6589d43cf19 /utf8.c | |
parent | 5a2dd41731da4a994683b80fc75b362161912f47 (diff) | |
download | perl-b76347f2eb34c85a0a38543b2f57ca474fedab4d.tar.gz |
Introduce Perl_utf8_length(). Use it.
p4raw-id: //depot/perl@7744
Diffstat (limited to 'utf8.c')
-rw-r--r-- | utf8.c | 29 |
1 files changed, 29 insertions, 0 deletions
@@ -353,6 +353,35 @@ Perl_utf8_to_uv_simple(pTHX_ U8* s, STRLEN* retlen) return Perl_utf8_to_uv(aTHX_ s, (STRLEN)-1, retlen, 0); } +/* +=for apidoc|utf8_length|U8 *s|U8 *e + +Return the length of the UTF-8 char encoded string C<s> in characters. +Stops at string C<e>. If C<e E<lt> s> or if the scan would end up +past C<e>, return -1. + +=cut +*/ + +STRLEN +Perl_utf8_length(pTHX_ U8* s, U8* e) +{ + STRLEN len = 0; + + if (e < s) + return -1; + while (s < e) { + STRLEN t = UTF8SKIP(s); + + if (e - s < t) + return -1; + s += t; + len++; + } + + return len; +} + /* utf8_distance(a,b) returns the number of UTF8 characters between the pointers a and b */ |