aboutsummaryrefslogtreecommitdiffstats
path: root/native/src/char_utils.h
diff options
context:
space:
mode:
authorTadashi G. Takaoka <takaoka@google.com>2011-11-11 15:59:17 -0800
committerAndroid Git Automerger <android-git-automerger@android.com>2011-11-11 15:59:17 -0800
commita8ee9386d2fdc9efc4541d6c6b9e1c991885060e (patch)
tree37d9df7774aa03c4897860c8fda6941549398c3f /native/src/char_utils.h
parent99a114e529912bdb9a5ad9d0f573ad4fa10ef56d (diff)
parent6e3cb27cffa525d555b289111678f6fa0495447e (diff)
downloadlatinime-a8ee9386d2fdc9efc4541d6c6b9e1c991885060e.tar.gz
latinime-a8ee9386d2fdc9efc4541d6c6b9e1c991885060e.tar.xz
latinime-a8ee9386d2fdc9efc4541d6c6b9e1c991885060e.zip
am 6e3cb27c: Reorganize char_utils.h and basechars.h
* commit '6e3cb27cffa525d555b289111678f6fa0495447e': Reorganize char_utils.h and basechars.h
Diffstat (limited to 'native/src/char_utils.h')
-rw-r--r--native/src/char_utils.h39
1 files changed, 39 insertions, 0 deletions
diff --git a/native/src/char_utils.h b/native/src/char_utils.h
index a69a35e7a..607dc5195 100644
--- a/native/src/char_utils.h
+++ b/native/src/char_utils.h
@@ -19,8 +19,47 @@
namespace latinime {
+inline static int isAsciiUpper(unsigned short c) {
+ return c >= 'A' && c <= 'Z';
+}
+
+inline static unsigned short toAsciiLower(unsigned short c) {
+ return c - 'A' + 'a';
+}
+
+inline static int isAscii(unsigned short c) {
+ return c <= 127;
+}
+
unsigned short latin_tolower(unsigned short c);
+/**
+ * Table mapping most combined Latin, Greek, and Cyrillic characters
+ * to their base characters. If c is in range, BASE_CHARS[c] == c
+ * if c is not a combined character, or the base character if it
+ * is combined.
+ */
+
+static const int BASE_CHARS_SIZE = 0x0500;
+extern const unsigned short BASE_CHARS[BASE_CHARS_SIZE];
+
+inline static unsigned short toBaseChar(unsigned short c) {
+ if (c < BASE_CHARS_SIZE) {
+ return BASE_CHARS[c];
+ }
+ return c;
+}
+
+inline static unsigned short toBaseLowerCase(unsigned short c) {
+ c = toBaseChar(c);
+ if (isAsciiUpper(c)) {
+ return toAsciiLower(c);
+ } else if (isAscii(c)) {
+ return c;
+ }
+ return latin_tolower(c);
+}
+
} // namespace latinime
#endif // LATINIME_CHAR_UTILS_H