Page 1 of 1
How to make a ulong array that can be used as a string?
Posted: Mon Sep 21, 2015 1:50 pm
by abcdef4bfd
I'm today starting implementing UTF-8 for my OS, and got a problem. I'm shortly rewritten the vgaPutchar function declaration, and it's working fine. But when i'm trying to print strings, i don't know what to do. Simple char* string can't handle ulong numbers, and overflow is appearing. So, how to properly declare an unsigned long array or pointer to make it initializable with extended string literals, and, if it's not available all the way, how to just write Unicode strings?
Re: How to make a ulong array that can be used as a string?
Posted: Mon Sep 21, 2015 3:14 pm
by jnc100
You need to decide how you wish to store Unicode strings internally. There are many formats varying on both the data type used and the actual encoding. There is an overview
here of how the various string literal operators ("", L"", u"", U"", and u8"") map to data types.
Note that UTF-8 (which you want to use), is normally stored as a char[] array, with the difference from a normal string being that there is not a direct one-to-one mapping between array entries and code points.
I don't understand why you are trying to use a numeric type to store the characters. What exactly are you trying to do?
Regards,
John.
Re: How to make a ulong array that can be used as a string?
Posted: Mon Sep 21, 2015 3:30 pm
by araxestroy
C11 includes char16_t and char32_t types for storing UTF-16 and UTF-32 encoded data. Prefixing character literals and string literals with u and U will respectively declare the literals as UTF-16 and UTF-32 respectively. In C11, these types aren't fundamental, but rather implemented in uchar.h, so you'll need to include them. In C++11, they're fundamental types.
uchar.h also contains function declarations for four functions for handling conversion between multibyte character sequences (UTF-8) and fixed-width Unicode characters (UTF-16 and UTF-32). You need to implement them yourself though.
Re: How to make a ulong array that can be used as a string?
Posted: Tue Sep 22, 2015 3:17 am
by Combuster
The slightly older way is to use wchar_t strings, which you can initialize just like char strings. This will let the compiler configuration dictate the character size though