4 ms·
You may be asked about using Unicode strings. What the interviewer is usually looking for is: - each character will be two bytes (so, for example, char
by panic 16y ago
You may be asked about using Unicode strings. What the interviewer is usually looking for is:
- each character will be two bytes (so, for example, char
lookup table you may have allocated needs to be
expanded from 256 to 256 x 256 = 65536 elements)
- that you would need to use wide char types (wchar_t
instead of char)
- that you would need to use wide string functions (like
wprintf instead of printf)
Unicode support involves more than just the minimum number of bits used per character.
Say you're writing a method to truncate a string to a certain length. What if your text contains a code point outside the basic multilingual plane, and each character can't be represented in just 16 bits? If you truncate in the middle of a character, the result will be an invalid string. What about combining characters? If you truncate in the middle of a combining character sequence, you'll end up with half-formed output (e.g., letters missing a diacritic). If you work with text, you should know this stuff!
- WildUtah 16y agoThe OP is a page from 2002 (or possibly 1902; didn't people remember Y2K back then?), so I expect the recent new code points beyond U+65535 were still outside the imagination of potential interviewers.
- panic 16y agoThe higher planes were added in 2001 with Unicode 3.1: http://unicode.org/reports/tr27/tr27-4.html http://unicode.org/reports/tr27/tr27-4.html
- Stormbringer 16y agoThese things normally take time to trickle down to us lesser mortals. I suggest a high level circle of protection and an astral binding. :D
- voidpointer 16y agoThis little thread illustrates nicely that the smart thing to do is not to implement list or string functions yourself but to use a library that has been tried and tested. Spend your brain cycles on the important stuff. I find it much more interesting to ask people when and why they would choose a linked or an array/buffer based list...