As everyone says, ANSI raw strings are very simple. Just use simple C or C ++ std :: string strings if you like to compile Objective C ++.
However, Cocoa's own string format is UCS-2 β 2-byte fixed-width characters. NSStrings are stored internally as UCS-2, i.e. e. as arrays of an unsigned short circuit. (As in Win32 and Java, by the way.) The system aliases for this data type are unichar and UniChar. Here where things get tricky.
GCC includes the wchar_t data type and allows you to define a string constant with wide char as follows:
wchar_t * ws = L "This is a wide char string.";
However, by default, this data type is defined as a 4-byte int and therefore does not match Cocoa unichar! You can override this by specifying the following compiler option:
-fshort-wchar
but then you lose the RTL functions with wide char C (wcslen (), wcscpy (), etc.) - RTL was compiled without this option and assumes a 4-byte wchar_t. This is not particularly difficult to implement manually. Your call.
When you have really 2-byte wchar_t raw strings, you can trivially convert them to NSStrings and vice versa:
wchar_t *ws = L"Hello"; NSString *s = [NSString stringWithCharacters:(const unichar*)ws length:5];
Unlike all other [stringWi thanksXX] methods, this is not related to code page conversions.
source share