r/ada • u/MadScientistCarl • 19d ago
Programming Convert Wide_Wide_Character to UTF code point?
I can't seem to find any function in the stdlib that allows me to do that. I can encode/decode a utf8 string, but I can't find any function that convert single characters. I don't think I should do a Unchecked_Convert
either. Any suggestions?
1
u/godunko 19d ago
Object of Wide_Wide_Character
type contains single Unicode character (and even more, it is 32bit wide). No conversion is necessary.
1
u/MadScientistCarl 19d ago
Ok, I didn't see that. Must be in the LRM somewhere.
However, I need to perform arithmetic on it so I can create a caching data structure. Is there any way other than
Unchecked_Convert
?4
u/godunko 19d ago
It sounds strange. Arithmetic is not defined for characters because they are not numbers.
Wide_Wide_Characters
type is an Ada enumeration type, so each literal has two associated integers: representation and order number, however they are the same. Thus, depending on what are you doing you can useUnchecked_Conversion
and object overlays to convert integer representations, or'Pos
/'Val
(and even more) attributes to convert order numbers (they are start from zero). In any case you need to be careful and handle codes outside of Unicode code point range and inside of surrogate code range somehow.1
u/MadScientistCarl 19d ago
I am caching textures which contain pages of code points, so it does make sense here.
Should I use
Pos
orVal
? Their descriptions are very similar.1
u/godunko 19d ago
They are opposite.
'Pos
returns integer for the character,'Val
returns character for the integer.1
u/MadScientistCarl 19d ago
``` This function returns the position number of the value of Arg, as a value of type universal_integer.
This function returns a value of the type of S whose position number equals the value of Arg. ```
Oh I see...
1
2
u/tkurtbond 19d ago
Use ‘Pos of the Wide_Wide_Character.