|
|
| We don't bite newbies here... much | |
| PerlMonks |
Re: How to test if a string is unicode string?by ikegami (Patriarch) |
| on Apr 04, 2025 at 15:36 UTC ( [id://11164579]=note: print w/replies, xml ) | Need Help?? |
|
All those are equivalent. The fastest way of writing it is probably
But do they do what you asked? Does it check if it's plain ASCII?No. ASCII only has 128 characters, so the following would be closer:
(!! just normalizes the result to be the true (&PL_sv_yes) or the false (&PL_sv_no).) But does it work? Not quite. It will always return true when provided ASCII, but it won't necessarily return false is provided non-ASCII.
Does it check if it's plain Unicode?What does "Unicode" mean?
Whichever one you want to do, it will run unto the same problem as checking if a string is ASCII: You can't eliminate false positives. (Well except checking the storage format. That can be done reliably, but relying on the result is a bug.) You can't tell if a string is ASCII or "Unicode" (whichever definition) reliably. If your code needs to deal with strings in multiple formats and distinguish between them, it will need to be told of the format of the strings.
In Section
Seekers of Perl Wisdom
|
|
||||||||||||||||||||||||||||||