4 ms·
Ownership is nice, but how can a zero terminated buffer library still call itself string? We have unicode for a while. UTF-8 only, not less. Strings must suppor
by rurban 6y ago
Ownership is nice, but how can a zero terminated buffer library still call itself string? We have unicode for a while. UTF-8 only, not less. Strings must support unicode.
This impacts sort and comparisons mostly. But without cmp you cannot search in strings.
- flohofwoe 6y agoUTF-8 strings can be compared with strcmp(), you just can't get alphabetical sorting out of it. Most other str*() functions also work with UTF-8 encoded strings, you just need to know what to expect (e.g. splitting with strtok() works as long as the delimiters are all 7-bit ASCII chars, etc...).
- deathanatos 6y ago> UTF-8 strings can be compared with strcmp() No, they can't? These two UTF-8 byte sequences in a C char pointer, c3 a9 00 65 cc 81 00 Represent the same string, but do not compare equal with strcmp. And it's not just that; you've noted how strtok will break down. strchr() can't be used w/ a non-ASCII needle, there is no support for code units, etc.
- account42 6y ago> you just can't get alphabetical sorting out of it Lexicographical sorting over UTF-8 strings is actually the same as lexicographical sorting over the corresponding Unicode code point sequence.
- topspin 6y ago> zero terminated buffer library Indeed.
- GoblinSlayer 6y agoAFAIK, comparison is language dependent, but how do you tell the string's language and how do you compare strings from different languages and multilingual strings?
- qwerty456127 6y agoThere is the Unicode Collation Algorithm standard to address this. An example of its implementation is the utf8_unicode_ci collation in MySQL.