summaryrefslogtreecommitdiff
path: root/src/charset.c
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2005-08-23 21:00:13 +0000
committerBram Moolenaar <Bram@vim.org>2005-08-23 21:00:13 +0000
commit7862282f2edc76533c5c0dcf49b57bf747a30ebc (patch)
tree8feddb7d932bf1d473752be7460746d706935df1 /src/charset.c
parenta6c840d7d4d51af2a15f64db5e5b908457b572cf (diff)
downloadvim-git-7862282f2edc76533c5c0dcf49b57bf747a30ebc.tar.gz
updated for version 7.0135
Diffstat (limited to 'src/charset.c')
-rw-r--r--src/charset.c116
1 files changed, 116 insertions, 0 deletions
diff --git a/src/charset.c b/src/charset.c
index c14bef03e..c769486cf 100644
--- a/src/charset.c
+++ b/src/charset.c
@@ -1531,6 +1531,122 @@ vim_isxdigit(c)
|| (c >= 'A' && c <= 'F');
}
+#if defined(FEAT_MBYTE) || defined(PROTO)
+/*
+ * Vim's own character class functions. These exist because many library
+ * islower()/toupper() etc. do not work properly: they crash when used with
+ * invalid values or can't handle latin1 when the locale is C.
+ * Speed is most important here.
+ */
+#define LATIN1LOWER 'l'
+#define LATIN1UPPER 'U'
+
+/* !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]%_'abcdefghijklmnopqrstuvwxyz{|}~ */
+static char_u latin1flags[256] = " UUUUUUUUUUUUUUUUUUUUUUUUUU llllllllllllllllllllllllll UUUUUUUUUUUUUUUUUUUUUUU UUUUUUUllllllllllllllllllllllll llllllll";
+static char_u latin1upper[256] = " !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`ABCDEFGHIJKLMNOPQRSTUVWXYZ{|}~";
+static char_u latin1lower[256] = " !\"#$%&'()*+,-./0123456789:;<=>?@abcdefghijklmnopqrstuvwxyz[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~";
+
+ int
+vim_islower(c)
+ int c;
+{
+ if (c <= '@')
+ return FALSE;
+ if (c >= 0x80)
+ {
+ if (enc_utf8)
+ return utf_islower(c);
+ if (c >= 0x100)
+ {
+#ifdef HAVE_ISWLOWER
+ if (has_mbyte)
+ return iswlower(c);
+#endif
+ /* islower() can't handle these chars and may crash */
+ return FALSE;
+ }
+ if (enc_latin1like)
+ return (latin1flags[c] & LATIN1LOWER) == LATIN1LOWER;
+ }
+ return islower(c);
+}
+
+ int
+vim_isupper(c)
+ int c;
+{
+ if (c <= '@')
+ return FALSE;
+ if (c >= 0x80)
+ {
+ if (enc_utf8)
+ return utf_isupper(c);
+ if (c >= 0x100)
+ {
+#ifdef HAVE_ISWUPPER
+ if (has_mbyte)
+ return iswupper(c);
+#endif
+ /* islower() can't handle these chars and may crash */
+ return FALSE;
+ }
+ if (enc_latin1like)
+ return (latin1flags[c] & LATIN1UPPER) == LATIN1UPPER;
+ }
+ return isupper(c);
+}
+
+ int
+vim_toupper(c)
+ int c;
+{
+ if (c <= '@')
+ return c;
+ if (c >= 0x80)
+ {
+ if (enc_utf8)
+ return utf_toupper(c);
+ if (c >= 0x100)
+ {
+#ifdef HAVE_TOWUPPER
+ if (has_mbyte)
+ return towupper(c);
+#endif
+ /* toupper() can't handle these chars and may crash */
+ return c;
+ }
+ if (enc_latin1like)
+ return latin1upper[c];
+ }
+ return TOUPPER_LOC(c);
+}
+
+ int
+vim_tolower(c)
+ int c;
+{
+ if (c <= '@')
+ return c;
+ if (c >= 0x80)
+ {
+ if (enc_utf8)
+ return utf_tolower(c);
+ if (c >= 0x100)
+ {
+#ifdef HAVE_TOWLOWER
+ if (has_mbyte)
+ return towlower(c);
+#endif
+ /* tolower() can't handle these chars and may crash */
+ return c;
+ }
+ if (enc_latin1like)
+ return latin1lower[c];
+ }
+ return TOLOWER_LOC(c);
+}
+#endif
+
/*
* skiptowhite: skip over text until ' ' or '\t' or NUL.
*/