in reply to How to know if a string has UTF-8?
Hi again, gmpassos :)
This is what I use: (I didn't write this myself)
# ValidUTF8 came from: http://people.netscape.com/ftang/utf8/isutf8.pl sub ValidUTF8 { local ( $utf8 ) = pop (@_); if($utf8 =~ /^(([\0-\x7F])|([\xC0-\xDF][\x80-\xBF])|([\xE0-\xE +F][\x80-\xBF][\x80-\xBF])|([\xF0-\xF7][\x80-\xBF][\x80-\xBF][\x80-\xB +F])|([\xF8-\xFB][\x80-\xBF][\x80-\xBF][\x80-\xBF][\x80-\xBF])|([\xFC- +\xFE][\x80-\xBF][\x80-\xBF][\x80-\xBF][\x80-\xBF][\x80-\xBF]))*$/) { return ! ($utf8 =~ /([\xC0-\xC1])|([\xE0][\x80-\x9F])| +([\xF0][\x80-\x8F])|([\xF8][\x80-\x87])|([\xFC][\x80-\x83])/); } else { return 0; } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: How to know if a string has UTF-8?
by gmpassos (Priest) on May 28, 2003 at 18:08 UTC | |
by graff (Chancellor) on May 28, 2003 at 22:10 UTC | |
by gmpassos (Priest) on May 29, 2003 at 05:44 UTC |