utf8.c
/*
=for apidoc is_utf8_string

Returns true if the first C<len> bytes of string C<s> form a valid
UTF-8 string, false otherwise.  If C<len> is 0, it will be calculated
using C<strlen(s)> (which means if you use this option, that C<s> has to have a
terminating NUL byte).  Note that all characters being ASCII constitute 'a
valid UTF-8 string'.

See also L</is_ascii_string>(), L</is_utf8_string_loclen>(), and L</is_utf8_string_loc>().

=cut
*/
for apidoc is_utf8_string
Returns true if the first C bytes of string C form a valid
UTF-8 string, false otherwise.  If C is 0, it will be calculated
using C (which means if you use this option, that C has to have a
terminating NUL byte).  Note that all characters being ASCII constitute 'a
valid UTF-8 string'.



cut
for apidoc is_utf8_string Returns true if the first C bytes of string C form a valid UTF - 8 string false otherwise . If C is 0 it will be calculated using C ( which means if you use this option that C has to have a terminating NUL byte ) . Note that all characters being ASCII constitute ' a valid UTF - 8 string ' . cut
bool
Perl_is_utf8_string(const U8 *s, STRLEN len)
{
    const U8* const send = s + (len ? len : strlen((const char *)s));
    const U8* x = s;
    PERL_ARGS_ASSERT_IS_UTF8_STRING;
    while (x < send) {
	 if (UTF8_IS_INVARIANT(*x)) {
	    x++;
	 }
	 else if (!UTF8_IS_START(*x))
	     return FALSE;
	 else {
	     const STRLEN c = UTF8SKIP(x);
	     const U8* const next_char_ptr = x + c;
	     if (next_char_ptr > send) {
		 return FALSE;
	     }
	     if (IS_UTF8_CHAR_FAST(c)) {
	         if (!IS_UTF8_CHAR(x, c))
		     return FALSE;
	     }
	     else if (! is_utf8_char_slow(x, c)) {
		 return FALSE;
	     }
	     x = next_char_ptr;
	 }
    }
    return TRUE;
}
bool Perl_is_utf8_string ( const U8 * s , STRLEN len ) { const U8 * const send = s + ( len ? len : strlen ( ( const char * ) s ) ) ; const U8 * x = s ; PERL_ARGS_ASSERT_IS_UTF8_STRING ; while ( x < send ) { if ( UTF8_IS_INVARIANT ( * x ) ) { x ++ ; } else if ( ! UTF8_IS_START ( * x ) ) return FALSE ; else { const STRLEN c = UTF8SKIP ( x ) ; const U8 * const next_char_ptr = x + c ; if ( next_char_ptr > send ) { return FALSE ; } if ( IS_UTF8_CHAR_FAST ( c ) ) { if ( ! IS_UTF8_CHAR ( x , c ) ) return FALSE ; } else if ( ! is_utf8_char_slow ( x , c ) ) { return FALSE ; } x = next_char_ptr ; } } return TRUE ; }
for apidoc is_utf8_string
Returns true if the first C<len> bytes of string C<s> form a valid
UTF-8 string, false otherwise.
for apidoc is_utf8_string Returns true if the first C<len > bytes of string C<s > form a valid UTF - 8 string false otherwise .
/* Inline the easy bits of is_utf8_char() here for speed... */ /* ... and call is_utf8_char() only if really needed. */