(svn r25653) -Add: Caret movement by words for CJK languages.

This commit is contained in:
michi_cc
2013-08-05 20:35:31 +00:00
parent e7dc14b25a
commit 76367f6bf1
5 changed files with 220 additions and 123 deletions

View File

@@ -90,7 +90,6 @@ static inline WChar Utf8Consume(const char **s)
return c;
}
/**
* Return the length of a UTF-8 encoded character.
* @param c Unicode character.
@@ -156,6 +155,51 @@ static inline const char *Utf8PrevChar(const char *s)
size_t Utf8StringLength(const char *s);
/**
* Is the given character a lead surrogate code point?
* @param c The character to test.
* @return True if the character is a lead surrogate code point.
*/
static inline bool Utf16IsLeadSurrogate(uint c)
{
return c >= 0xD800 && c <= 0xDBFF;
}
/**
* Is the given character a lead surrogate code point?
* @param c The character to test.
* @return True if the character is a lead surrogate code point.
*/
static inline bool Utf16IsTrailSurrogate(uint c)
{
return c >= 0xDC00 && c <= 0xDFFF;
}
/**
* Convert an UTF-16 surrogate pair to the corresponding Unicode character.
* @param lead Lead surrogate code point.
* @param trail Trail surrogate code point.
* @return Decoded Unicode character.
*/
static inline WChar Utf16DecodeSurrogate(uint lead, uint trail)
{
return 0x10000 + (((lead - 0xD800) << 10) | (trail - 0xDC00));
}
/**
* Decode an UTF-16 character.
* @param c Pointer to one or two UTF-16 code points.
* @return Decoded Unicode character.
*/
static inline WChar Utf16DecodeChar(const uint16 *c)
{
if (Utf16IsLeadSurrogate(c[0])) {
return Utf16DecodeSurrogate(c[0], c[1]);
} else {
return *c;
}
}
/**
* Is the given character a text direction character.
* @param c The character to test.