About Monkey 2 › Forums › Monkey 2 Programming Help › String vs CString vs WString
This topic contains 2 replies, has 2 voices, and was last updated by
nerobot 1 year, 4 months ago.
-
AuthorPosts
-
November 23, 2017 at 11:08 am #11927
I have a few questions about strings types.
1. What is String type under the hood? Is it utf-8 string?
2. Is it ok that LoadString/SaveString using CString instead of WString?
I tried to use russian letters for window title and I got abrakadabra when app started.
But if I load the same letters from file – everything is OK.
2.5. Is it something wrong with stored file format on disk or with mx2cc itself?
I can see russian letters normally after re-load files.
3. Is WString the same as Utf8String? There is an String.Utf8Length property, but there is no From/To/Utf8String methods – WString only.
November 23, 2017 at 8:06 pm #11932What is String type under the hood? Is it utf-8 string?
No, it’s an internal custom 16 bit per char format.
Is it ok that LoadString/SaveString using CString instead of WString?
CString means ‘utf-8’ encoded null terminated string, so yes. WString is not really technically supported yet.
I tried to use russian letters for window title and I got abrakadabra when app started.
But if I load the same letters from file – everything is OK.
Not really sure what you mean here. Please post some sample code if you want me to look at something! This is especially important if international characters are involved as randomly copying and pasting stuff from google in an attempt to try to duplicate problems like this can only get me so far.
To clarify a bit on the whole windows+utf mess: The problem is typically with API calls where you have to pass a filename or something ‘visible’ (eg: window title) to an OS function.
All OS’s except windows accept utf-8 cstrings (ie: monkey2 CStrings) for filenames etc which are (conveniently, by design) backward compatible with plain ascii, and are fully handled by monkey2. When a monkey2 string is converted to a CString all information retained as its in utf-8 encoding.
However, windows requires you to use entirely different APIS if you want to use filenames etc that aren’t plain 7 bit ascii. Monkey2 doesn’t use such APIs yet, so non-ascii chars in filenames etc will cause problems, as monkey2 will still convert to utf-8 cstrings (which are still valid c strings, windows just doesn’t know how to deal with them properly).
These different APIs uses yet another string type – a WSTRING – which is very close to what monkey2 currently uses internally (although that could change) but needs to be null terminated etc. Note that there is also a c++ std::wstring which is similar to WSTRING but only on some targets. Fun stuff.
November 24, 2017 at 2:54 am #11936Thank you for explanation!
I made simple demo and add it as an issue here: https://github.com/blitz-research/monkey2/issues/277
-
AuthorPosts
You must be logged in to reply to this topic.