How to make a ulong array that can be used as a string?
- abcdef4bfd
- Member

- Posts: 492
- Joined: Fri Apr 03, 2015 9:41 am
How to make a ulong array that can be used as a string?
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?
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.
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.
- araxestroy
- Member

- Posts: 561
- Joined: Wed Jul 13, 2011 7:38 pm
- Libera.chat IRC: araxestroy
- Location: Vancouver, Canada
- Contact:
Re: How to make a ulong array that can be used as a string?
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.
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.
- Combuster
- Member

- Posts: 9301
- Joined: Wed Oct 18, 2006 3:45 am
- Libera.chat IRC: [com]buster
- Location: On the balcony, where I can actually keep 1½m distance
- Contact:
Re: How to make a ulong array that can be used as a string?
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