COMMON: Add string size computation to Encoding.
This commit is contained in:
parent
a9be9c1453
commit
8f930126e7
2 changed files with 28 additions and 0 deletions
|
@ -499,4 +499,20 @@ uint32 *Encoding::transliterateUTF32(const uint32 *string, size_t length) {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
size_t Encoding::stringLength(const char *string, const String &encoding) {
|
||||||
|
if (encoding.hasPrefixIgnoreCase("UTF-16")) {
|
||||||
|
const uint16 *i = (const uint16 *) string;
|
||||||
|
for (;*i != 0; i++) {}
|
||||||
|
return (const char *) i - string;
|
||||||
|
} else if (encoding.hasPrefixIgnoreCase("UTF-32")) {
|
||||||
|
const uint32 *i = (const uint32 *) string;
|
||||||
|
for (;*i != 0; i++) {}
|
||||||
|
return (const char *) i - string;
|
||||||
|
} else {
|
||||||
|
const char *i = string;
|
||||||
|
for (;*i != 0; i++) {}
|
||||||
|
return i - string;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -108,6 +108,18 @@ class Encoding {
|
||||||
* @return Array of characters with the opposite endianity
|
* @return Array of characters with the opposite endianity
|
||||||
*/
|
*/
|
||||||
static char *switchEndian(const char *string, int length, int bitCount);
|
static char *switchEndian(const char *string, int length, int bitCount);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Computes length (in bytes) of a string in a given encoding.
|
||||||
|
* The string must be zero ended. Similar to strlen
|
||||||
|
* (could be used instead of strlen).
|
||||||
|
*
|
||||||
|
* @param string String, which size should be computed.
|
||||||
|
* @param encoding Encoding of the string.
|
||||||
|
*
|
||||||
|
* @return Size of the string in bytes.
|
||||||
|
*/
|
||||||
|
static size_t stringLength(const char *string, const String &encoding);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
/** The encoding, which is currently being converted to */
|
/** The encoding, which is currently being converted to */
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue