Trying to implement c++ code where we could use a non-utf8 char to be as delimiter inside a std::string.
Is there such a thing as a non-UTF-8 char ?
Trying to implement c++ code where we could use a non-utf8 char to be as delimiter inside a std::string.
Is there such a thing as a non-UTF-8 char ?
Yes. 0xC0, 0xC1, 0xF5, 0xF6, 0xF7, 0xF8, 0xF9, 0xFA, 0xFB, 0xFC, 0xFD, 0xFE, 0xFF are invalid UTF-8 code units. A UTF-8 code unit is 8 bits. If by char
you mean an 8-bit byte, then the invalid UTF-8 code units would be char
values that do not appear in UTF-8 encoded text.
std::string
only knows about raw char
values, it knows nothing about particular character encodings that use char
to hold encoded values.
Many common UTF-8 implementations use char
to hold encoded codeunits (though C++20 will introduce char8_t
and std::u8string
for this purpose instead). But other character encodings (Windows-12##, ISO-8859-#, etc) can also fit their encoded values in char
elements, too.
Any char
value that falls within the ASCII range (0x00 .. 0x7F) will fit in 1 char
and map to the same codepoint value in Unicode (U+0000 .. U+007F), but any char
value in the ANSI range but not in the ASCII range (0x80 .. 0xFF) is subject to interpretation by whatever character encoding created the char
values. Some encodings use 1 char
per character, some use multiple char
s.
So yes, there is such a thing as a "non-UTF-8 char".
You can check out the UTF-8 standard on Wiki. Not every sequence of bytes is a valid UTF-8 character. Even if it's a single byte: 0x11111000, 0x11111111 are not valid first bytes in UTF-8.
Though, I doubt that it is a good idea to use a non-UTF-8 character as a delimiter. You might find certain program (like Notepad++) having issues with reading output of your strings.