canmove, Confirmed users, Bureaucrats and Sysops emeriti
1,334
edits
(→String: PRUnichar was replaced by char16_t) |
|||
| Line 712: | Line 712: | ||
=== String === | === String === | ||
XPCOM has string classes for representing sequences of characters. We have two parallel sets of classes, one for strings with 1-byte units (<code>char</code>, which may be signed or unsigned), and one for strings with 2-byte units (<code> | XPCOM has string classes for representing sequences of characters. We have two parallel sets of classes, one for strings with 1-byte units (<code>char</code>, which may be signed or unsigned), and one for strings with 2-byte units (<code>char16_t</code>, always unsigned). The classes are named such that the class for 2-byte characters ends with <code>String</code> and the corresponding class for 1-byte characters ends with <code>CString</code>. 2-byte strings are almost always used to encode [http://en.wikipedia.org/wiki/UTF-16 UTF-16]. 1-byte strings are usually used to encode either [http://en.wikipedia.org/wiki/ASCII ASCII] or [http://en.wikipedia.org/wiki/UTF-8 UTF-8], but are sometimes also used to hold data in some other encoding or just byte sequences. | ||
The string classes distinguish, as part of the type hierarchy, between strings that must have a null-terminator at the end of their buffer (<code>ns[C]String</code>) and strings that are not required to have a null-terminator (<code>ns[C]Substring</code>). <code>ns[C]Substring</code> is the base of the string classes (since it imposes fewer requirements) and <code>ns[C]String</code> is a class derived from it. Functions taking strings as parameters should generally take one of these four types. | The string classes distinguish, as part of the type hierarchy, between strings that must have a null-terminator at the end of their buffer (<code>ns[C]String</code>) and strings that are not required to have a null-terminator (<code>ns[C]Substring</code>). <code>ns[C]Substring</code> is the base of the string classes (since it imposes fewer requirements) and <code>ns[C]String</code> is a class derived from it. Functions taking strings as parameters should generally take one of these four types. | ||