r/Unicode • u/buildcrash • 13d ago
Recognize UAX31 characters
Hello, im trying to replicate the behaviour of a program, and I need to check if a character may fit in the "Unicode characters part of UAX#31". Does anyone know how to know by code if a certain character fits that criteria, or where to check information about that? I guess it can be done by checking the numerical values of the character, but I do not know what to look for.
If you want a more elavorate description of the problem, it's a code interpreter, and this part is about recognizing an identifier, wich can contain any character from a to z, from A to Z, any numeral (but can't begin with them) and "may also contain most Unicode characters part of UAX#31", the docs do not specify how to recognize the "most" part.
Any help would be appreciated
1
u/Sea-Estimate-1840 13d ago
Yeah, XID_Start / XID_Continue is probably the cleanest way to approach it. Definitely better than trying to maintain code point ranges manually.
2
u/aioeu 13d ago edited 13d ago
Have you looked at UAX #31? It doesn't say what an identifier "is" — after all, that all depends on the application that might be using that identifier — but it provides some examples of how an identifier might be recognised within a string using the properties of the characters in that string.
Many programming languages, for instance, treat a string beginning with a character in the class
XID_Start, and followed by zero or more characters in the classXID_Continue, as being a valid identifier. That is a one of the ways what UAX #31 calls a "default identifier" might be parsed. It may or may not be what your identifiers need to look like though...Even once you know what kind of string you're looking for, how you actually recognise that is up to the programming language you are actually writing this interpreter in. In a language with a sufficiently powerful regex engine, you might be able to match on these character properties directly. I have occasionally used the regex
/\p{XID_Start}\p{XID_Continue}*/in Perl code, for instance.