1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
|
#include <wchar.h>
#include <assert.h>
int main()
{
assert(""[0]==0);
assert("\033\\"[0]==27);
assert("\033\\"[1]=='\\');
assert("\xcZ\\"[0]==12);
assert("\xcZ\\"[1]=='Z');
assert("\""[0]=='"');
assert("\%"[0]=='%');
assert("\n"[0]==10);
// spliced to avoid hex ambiguity
assert("\x5" "five"[0]==0x5);
// spliced accoss multiple lines
const char some_string[]=
"\x5"
#pragma whatnot
"five";
assert(some_string[0]==0x5);
// wide strings
assert(L"abc"[0]=='a');
assert(L"abc"[1]=='b');
assert(L"abc"[3]==0);
assert(L"\x1234"[0]==0x1234);
// spliced wide strings
assert(sizeof(L"1" "2")==sizeof(wchar_t)*3);
// the following is a C11 UTF-8 string literal
const char euro_sign[]=u8"\x20ac";
assert((unsigned char)euro_sign[0]==0xe2);
assert((unsigned char)euro_sign[1]==0x82);
assert((unsigned char)euro_sign[2]==0xac);
assert(euro_sign[3]==0);
assert(sizeof(euro_sign)==4);
// the following is C++ and C99
const wchar_t wide_amount[]=L"\u20AC123,00"; //€123,00
assert(wide_amount[0]==0x20ac);
assert(wide_amount[1]=='1');
// C11 unicode string literals
assert(sizeof(u8""[0])==sizeof(char));
assert(sizeof(u""[0])==2);
assert(sizeof(U""[0])==4);
// generic wide string, OS-dependent
assert(sizeof(L""[0])==sizeof(wchar_t));
}
|