From da51dc9cf202772f60bd2da975dbef257bd9237c Mon Sep 17 00:00:00 2001 From: Eliseo Martínez Date: Mon, 12 May 2014 02:25:17 +0200 Subject: Introduce nvim namespace: Move files. Move files from src/ to src/nvim/. - src/nvim/ becomes the new root dir for nvim executable sources. - src/libnvim/ is planned to become root dir of the neovim library. --- src/mbyte.c | 4041 ----------------------------------------------------------- 1 file changed, 4041 deletions(-) delete mode 100644 src/mbyte.c (limited to 'src/mbyte.c') diff --git a/src/mbyte.c b/src/mbyte.c deleted file mode 100644 index 09cb1ce35b..0000000000 --- a/src/mbyte.c +++ /dev/null @@ -1,4041 +0,0 @@ -/* - * VIM - Vi IMproved by Bram Moolenaar - * Multibyte extensions partly by Sung-Hoon Baek - * - * Do ":help uganda" in Vim to read copying and usage conditions. - * Do ":help credits" in Vim to see a list of people who contributed. - * See README.txt for an overview of the Vim source code. - */ -/* - * mbyte.c: Code specifically for handling multi-byte characters. - * - * The encoding used in the core is set with 'encoding'. When 'encoding' is - * changed, the following four variables are set (for speed). - * Currently these types of character encodings are supported: - * - * "enc_dbcs" When non-zero it tells the type of double byte character - * encoding (Chinese, Korean, Japanese, etc.). - * The cell width on the display is equal to the number of - * bytes. (exception: DBCS_JPNU with first byte 0x8e) - * Recognizing the first or second byte is difficult, it - * requires checking a byte sequence from the start. - * "enc_utf8" When TRUE use Unicode characters in UTF-8 encoding. - * The cell width on the display needs to be determined from - * the character value. - * Recognizing bytes is easy: 0xxx.xxxx is a single-byte - * char, 10xx.xxxx is a trailing byte, 11xx.xxxx is a leading - * byte of a multi-byte character. - * To make things complicated, up to six composing characters - * are allowed. These are drawn on top of the first char. - * For most editing the sequence of bytes with composing - * characters included is considered to be one character. - * "enc_unicode" When 2 use 16-bit Unicode characters (or UTF-16). - * When 4 use 32-but Unicode characters. - * Internally characters are stored in UTF-8 encoding to - * avoid NUL bytes. Conversion happens when doing I/O. - * "enc_utf8" will also be TRUE. - * - * "has_mbyte" is set when "enc_dbcs" or "enc_utf8" is non-zero. - * - * If none of these is TRUE, 8-bit bytes are used for a character. The - * encoding isn't currently specified (TODO). - * - * 'encoding' specifies the encoding used in the core. This is in registers, - * text manipulation, buffers, etc. Conversion has to be done when characters - * in another encoding are received or send: - * - * clipboard - * ^ - * | (2) - * V - * +---------------+ - * (1) | | (3) - * keyboard ----->| core |-----> display - * | | - * +---------------+ - * ^ - * | (4) - * V - * file - * - * (1) Typed characters arrive in the current locale. Conversion is to be - * done when 'encoding' is different from 'termencoding'. - * (2) Text will be made available with the encoding specified with - * 'encoding'. If this is not sufficient, system-specific conversion - * might be required. - * (3) For the GUI the correct font must be selected, no conversion done. - * Otherwise, conversion is to be done when 'encoding' differs from - * 'termencoding'. (Different in the GTK+ 2 port -- 'termencoding' - * is always used for both input and output and must always be set to - * "utf-8". gui_mch_init() does this automatically.) - * (4) The encoding of the file is specified with 'fileencoding'. Conversion - * is to be done when it's different from 'encoding'. - * - * The viminfo file is a special case: Only text is converted, not file names. - * Vim scripts may contain an ":encoding" command. This has an effect for - * some commands, like ":menutrans" - */ - -#include -# include - -#include "vim.h" -#include "mbyte.h" -#include "charset.h" -#include "fileio.h" -#include "memline.h" -#include "message.h" -#include "misc1.h" -#include "misc2.h" -#include "memory.h" -#include "option.h" -#include "screen.h" -#include "spell.h" -#include "ui.h" -#include "os/os.h" - -# define WINBYTE BYTE - -static int enc_canon_search(char_u *name); -static int dbcs_char2len(int c); -static int dbcs_char2bytes(int c, char_u *buf); -static int dbcs_ptr2len(char_u *p); -static int dbcs_ptr2len_len(char_u *p, int size); -static int utf_ptr2cells_len(char_u *p, int size); -static int dbcs_char2cells(int c); -static int dbcs_ptr2cells_len(char_u *p, int size); -static int dbcs_ptr2char(char_u *p); -static int utf_safe_read_char_adv(char_u **s, size_t *n); - -/* - * Lookup table to quickly get the length in bytes of a UTF-8 character from - * the first byte of a UTF-8 string. - * Bytes which are illegal when used as the first byte have a 1. - * The NUL byte has length 1. - */ -static char utf8len_tab[256] = -{ - 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, - 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, - 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, - 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, - 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, - 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, - 2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2, - 3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,4,4,4,4,4,4,4,4,5,5,5,5,6,6,1,1, -}; - -/* - * Like utf8len_tab above, but using a zero for illegal lead bytes. - */ -static char utf8len_tab_zero[256] = -{ - 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, - 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, - 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, - 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2, - 3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,4,4,4,4,4,4,4,4,5,5,5,5,6,6,0,0, -}; - -/* - * Canonical encoding names and their properties. - * "iso-8859-n" is handled by enc_canonize() directly. - */ -static struct -{ char *name; int prop; int codepage; } -enc_canon_table[] = -{ -#define IDX_LATIN_1 0 - {"latin1", ENC_8BIT + ENC_LATIN1, 1252}, -#define IDX_ISO_2 1 - {"iso-8859-2", ENC_8BIT, 0}, -#define IDX_ISO_3 2 - {"iso-8859-3", ENC_8BIT, 0}, -#define IDX_ISO_4 3 - {"iso-8859-4", ENC_8BIT, 0}, -#define IDX_ISO_5 4 - {"iso-8859-5", ENC_8BIT, 0}, -#define IDX_ISO_6 5 - {"iso-8859-6", ENC_8BIT, 0}, -#define IDX_ISO_7 6 - {"iso-8859-7", ENC_8BIT, 0}, -#define IDX_ISO_8 7 - {"iso-8859-8", ENC_8BIT, 0}, -#define IDX_ISO_9 8 - {"iso-8859-9", ENC_8BIT, 0}, -#define IDX_ISO_10 9 - {"iso-8859-10", ENC_8BIT, 0}, -#define IDX_ISO_11 10 - {"iso-8859-11", ENC_8BIT, 0}, -#define IDX_ISO_13 11 - {"iso-8859-13", ENC_8BIT, 0}, -#define IDX_ISO_14 12 - {"iso-8859-14", ENC_8BIT, 0}, -#define IDX_ISO_15 13 - {"iso-8859-15", ENC_8BIT + ENC_LATIN9, 0}, -#define IDX_KOI8_R 14 - {"koi8-r", ENC_8BIT, 0}, -#define IDX_KOI8_U 15 - {"koi8-u", ENC_8BIT, 0}, -#define IDX_UTF8 16 - {"utf-8", ENC_UNICODE, 0}, -#define IDX_UCS2 17 - {"ucs-2", ENC_UNICODE + ENC_ENDIAN_B + ENC_2BYTE, 0}, -#define IDX_UCS2LE 18 - {"ucs-2le", ENC_UNICODE + ENC_ENDIAN_L + ENC_2BYTE, 0}, -#define IDX_UTF16 19 - {"utf-16", ENC_UNICODE + ENC_ENDIAN_B + ENC_2WORD, 0}, -#define IDX_UTF16LE 20 - {"utf-16le", ENC_UNICODE + ENC_ENDIAN_L + ENC_2WORD, 0}, -#define IDX_UCS4 21 - {"ucs-4", ENC_UNICODE + ENC_ENDIAN_B + ENC_4BYTE, 0}, -#define IDX_UCS4LE 22 - {"ucs-4le", ENC_UNICODE + ENC_ENDIAN_L + ENC_4BYTE, 0}, - - /* For debugging DBCS encoding on Unix. */ -#define IDX_DEBUG 23 - {"debug", ENC_DBCS, DBCS_DEBUG}, -#define IDX_EUC_JP 24 - {"euc-jp", ENC_DBCS, DBCS_JPNU}, -#define IDX_SJIS 25 - {"sjis", ENC_DBCS, DBCS_JPN}, -#define IDX_EUC_KR 26 - {"euc-kr", ENC_DBCS, DBCS_KORU}, -#define IDX_EUC_CN 27 - {"euc-cn", ENC_DBCS, DBCS_CHSU}, -#define IDX_EUC_TW 28 - {"euc-tw", ENC_DBCS, DBCS_CHTU}, -#define IDX_BIG5 29 - {"big5", ENC_DBCS, DBCS_CHT}, - - /* MS-DOS and MS-Windows codepages are included here, so that they can be - * used on Unix too. Most of them are similar to ISO-8859 encodings, but - * not exactly the same. */ -#define IDX_CP437 30 - {"cp437", ENC_8BIT, 437}, /* like iso-8859-1 */ -#define IDX_CP737 31 - {"cp737", ENC_8BIT, 737}, /* like iso-8859-7 */ -#define IDX_CP775 32 - {"cp775", ENC_8BIT, 775}, /* Baltic */ -#define IDX_CP850 33 - {"cp850", ENC_8BIT, 850}, /* like iso-8859-4 */ -#define IDX_CP852 34 - {"cp852", ENC_8BIT, 852}, /* like iso-8859-1 */ -#define IDX_CP855 35 - {"cp855", ENC_8BIT, 855}, /* like iso-8859-2 */ -#define IDX_CP857 36 - {"cp857", ENC_8BIT, 857}, /* like iso-8859-5 */ -#define IDX_CP860 37 - {"cp860", ENC_8BIT, 860}, /* like iso-8859-9 */ -#define IDX_CP861 38 - {"cp861", ENC_8BIT, 861}, /* like iso-8859-1 */ -#define IDX_CP862 39 - {"cp862", ENC_8BIT, 862}, /* like iso-8859-1 */ -#define IDX_CP863 40 - {"cp863", ENC_8BIT, 863}, /* like iso-8859-8 */ -#define IDX_CP865 41 - {"cp865", ENC_8BIT, 865}, /* like iso-8859-1 */ -#define IDX_CP866 42 - {"cp866", ENC_8BIT, 866}, /* like iso-8859-5 */ -#define IDX_CP869 43 - {"cp869", ENC_8BIT, 869}, /* like iso-8859-7 */ -#define IDX_CP874 44 - {"cp874", ENC_8BIT, 874}, /* Thai */ -#define IDX_CP932 45 - {"cp932", ENC_DBCS, DBCS_JPN}, -#define IDX_CP936 46 - {"cp936", ENC_DBCS, DBCS_CHS}, -#define IDX_CP949 47 - {"cp949", ENC_DBCS, DBCS_KOR}, -#define IDX_CP950 48 - {"cp950", ENC_DBCS, DBCS_CHT}, -#define IDX_CP1250 49 - {"cp1250", ENC_8BIT, 1250}, /* Czech, Polish, etc. */ -#define IDX_CP1251 50 - {"cp1251", ENC_8BIT, 1251}, /* Cyrillic */ - /* cp1252 is considered to be equal to latin1 */ -#define IDX_CP1253 51 - {"cp1253", ENC_8BIT, 1253}, /* Greek */ -#define IDX_CP1254 52 - {"cp1254", ENC_8BIT, 1254}, /* Turkish */ -#define IDX_CP1255 53 - {"cp1255", ENC_8BIT, 1255}, /* Hebrew */ -#define IDX_CP1256 54 - {"cp1256", ENC_8BIT, 1256}, /* Arabic */ -#define IDX_CP1257 55 - {"cp1257", ENC_8BIT, 1257}, /* Baltic */ -#define IDX_CP1258 56 - {"cp1258", ENC_8BIT, 1258}, /* Vietnamese */ - -#define IDX_MACROMAN 57 - {"macroman", ENC_8BIT + ENC_MACROMAN, 0}, /* Mac OS */ -#define IDX_DECMCS 58 - {"dec-mcs", ENC_8BIT, 0}, /* DEC MCS */ -#define IDX_HPROMAN8 59 - {"hp-roman8", ENC_8BIT, 0}, /* HP Roman8 */ -#define IDX_COUNT 60 -}; - -/* - * Aliases for encoding names. - */ -static struct -{ char *name; int canon; } -enc_alias_table[] = -{ - {"ansi", IDX_LATIN_1}, - {"iso-8859-1", IDX_LATIN_1}, - {"latin2", IDX_ISO_2}, - {"latin3", IDX_ISO_3}, - {"latin4", IDX_ISO_4}, - {"cyrillic", IDX_ISO_5}, - {"arabic", IDX_ISO_6}, - {"greek", IDX_ISO_7}, - {"hebrew", IDX_ISO_8}, - {"latin5", IDX_ISO_9}, - {"turkish", IDX_ISO_9}, /* ? */ - {"latin6", IDX_ISO_10}, - {"nordic", IDX_ISO_10}, /* ? */ - {"thai", IDX_ISO_11}, /* ? */ - {"latin7", IDX_ISO_13}, - {"latin8", IDX_ISO_14}, - {"latin9", IDX_ISO_15}, - {"utf8", IDX_UTF8}, - {"unicode", IDX_UCS2}, - {"ucs2", IDX_UCS2}, - {"ucs2be", IDX_UCS2}, - {"ucs-2be", IDX_UCS2}, - {"ucs2le", IDX_UCS2LE}, - {"utf16", IDX_UTF16}, - {"utf16be", IDX_UTF16}, - {"utf-16be", IDX_UTF16}, - {"utf16le", IDX_UTF16LE}, - {"ucs4", IDX_UCS4}, - {"ucs4be", IDX_UCS4}, - {"ucs-4be", IDX_UCS4}, - {"ucs4le", IDX_UCS4LE}, - {"utf32", IDX_UCS4}, - {"utf-32", IDX_UCS4}, - {"utf32be", IDX_UCS4}, - {"utf-32be", IDX_UCS4}, - {"utf32le", IDX_UCS4LE}, - {"utf-32le", IDX_UCS4LE}, - {"932", IDX_CP932}, - {"949", IDX_CP949}, - {"936", IDX_CP936}, - {"gbk", IDX_CP936}, - {"950", IDX_CP950}, - {"eucjp", IDX_EUC_JP}, - {"unix-jis", IDX_EUC_JP}, - {"ujis", IDX_EUC_JP}, - {"shift-jis", IDX_SJIS}, - {"euckr", IDX_EUC_KR}, - {"5601", IDX_EUC_KR}, /* Sun: KS C 5601 */ - {"euccn", IDX_EUC_CN}, - {"gb2312", IDX_EUC_CN}, - {"euctw", IDX_EUC_TW}, - {"japan", IDX_EUC_JP}, - {"korea", IDX_EUC_KR}, - {"prc", IDX_EUC_CN}, - {"chinese", IDX_EUC_CN}, - {"taiwan", IDX_EUC_TW}, - {"cp950", IDX_BIG5}, - {"950", IDX_BIG5}, - {"mac", IDX_MACROMAN}, - {"mac-roman", IDX_MACROMAN}, - {NULL, 0} -}; - -#ifndef CP_UTF8 -# define CP_UTF8 65001 /* magic number from winnls.h */ -#endif - -/* - * Find encoding "name" in the list of canonical encoding names. - * Returns -1 if not found. - */ -static int enc_canon_search(char_u *name) -{ - int i; - - for (i = 0; i < IDX_COUNT; ++i) - if (STRCMP(name, enc_canon_table[i].name) == 0) - return i; - return -1; -} - - - -/* - * Find canonical encoding "name" in the list and return its properties. - * Returns 0 if not found. - */ -int enc_canon_props(char_u *name) -{ - int i; - - i = enc_canon_search(name); - if (i >= 0) - return enc_canon_table[i].prop; - if (STRNCMP(name, "2byte-", 6) == 0) - return ENC_DBCS; - if (STRNCMP(name, "8bit-", 5) == 0 || STRNCMP(name, "iso-8859-", 9) == 0) - return ENC_8BIT; - return 0; -} - -/* - * Set up for using multi-byte characters. - * Called in three cases: - * - by main() to initialize (p_enc == NULL) - * - by set_init_1() after 'encoding' was set to its default. - * - by do_set() when 'encoding' has been set. - * p_enc must have been passed through enc_canonize() already. - * Sets the "enc_unicode", "enc_utf8", "enc_dbcs" and "has_mbyte" flags. - * Fills mb_bytelen_tab[] and returns NULL when there are no problems. - * When there is something wrong: Returns an error message and doesn't change - * anything. - */ -char_u * mb_init() -{ - int i; - int idx; - int n; - int enc_dbcs_new = 0; -#if defined(USE_ICONV) && !defined(WIN3264) && !defined(WIN32UNIX) \ - && !defined(MACOS) -# define LEN_FROM_CONV - vimconv_T vimconv; - char_u *p; -#endif - - if (p_enc == NULL) { - /* Just starting up: set the whole table to one's. */ - for (i = 0; i < 256; ++i) - mb_bytelen_tab[i] = 1; - input_conv.vc_type = CONV_NONE; - input_conv.vc_factor = 1; - output_conv.vc_type = CONV_NONE; - return NULL; - } else if (STRNCMP(p_enc, "8bit-", 5) == 0 - || STRNCMP(p_enc, "iso-8859-", 9) == 0) { - /* Accept any "8bit-" or "iso-8859-" name. */ - enc_unicode = 0; - enc_utf8 = FALSE; - } else if (STRNCMP(p_enc, "2byte-", 6) == 0) { - /* Unix: accept any "2byte-" name, assume current locale. */ - enc_dbcs_new = DBCS_2BYTE; - } else if ((idx = enc_canon_search(p_enc)) >= 0) { - i = enc_canon_table[idx].prop; - if (i & ENC_UNICODE) { - /* Unicode */ - enc_utf8 = TRUE; - if (i & (ENC_2BYTE | ENC_2WORD)) - enc_unicode = 2; - else if (i & ENC_4BYTE) - enc_unicode = 4; - else - enc_unicode = 0; - } else if (i & ENC_DBCS) { - /* 2byte, handle below */ - enc_dbcs_new = enc_canon_table[idx].codepage; - } else { - /* Must be 8-bit. */ - enc_unicode = 0; - enc_utf8 = FALSE; - } - } else /* Don't know what encoding this is, reject it. */ - return e_invarg; - - if (enc_dbcs_new != 0) { - enc_unicode = 0; - enc_utf8 = FALSE; - } - enc_dbcs = enc_dbcs_new; - has_mbyte = (enc_dbcs != 0 || enc_utf8); - - - /* Detect an encoding that uses latin1 characters. */ - enc_latin1like = (enc_utf8 || STRCMP(p_enc, "latin1") == 0 - || STRCMP(p_enc, "iso-8859-15") == 0); - - /* - * Set the function pointers. - */ - if (enc_utf8) { - mb_ptr2len = utfc_ptr2len; - mb_ptr2len_len = utfc_ptr2len_len; - mb_char2len = utf_char2len; - mb_char2bytes = utf_char2bytes; - mb_ptr2cells = utf_ptr2cells; - mb_ptr2cells_len = utf_ptr2cells_len; - mb_char2cells = utf_char2cells; - mb_off2cells = utf_off2cells; - mb_ptr2char = utf_ptr2char; - mb_head_off = utf_head_off; - } else if (enc_dbcs != 0) { - mb_ptr2len = dbcs_ptr2len; - mb_ptr2len_len = dbcs_ptr2len_len; - mb_char2len = dbcs_char2len; - mb_char2bytes = dbcs_char2bytes; - mb_ptr2cells = dbcs_ptr2cells; - mb_ptr2cells_len = dbcs_ptr2cells_len; - mb_char2cells = dbcs_char2cells; - mb_off2cells = dbcs_off2cells; - mb_ptr2char = dbcs_ptr2char; - mb_head_off = dbcs_head_off; - } else { - mb_ptr2len = latin_ptr2len; - mb_ptr2len_len = latin_ptr2len_len; - mb_char2len = latin_char2len; - mb_char2bytes = latin_char2bytes; - mb_ptr2cells = latin_ptr2cells; - mb_ptr2cells_len = latin_ptr2cells_len; - mb_char2cells = latin_char2cells; - mb_off2cells = latin_off2cells; - mb_ptr2char = latin_ptr2char; - mb_head_off = latin_head_off; - } - - /* - * Fill the mb_bytelen_tab[] for MB_BYTE2LEN(). - */ -#ifdef LEN_FROM_CONV - /* When 'encoding' is different from the current locale mblen() won't - * work. Use conversion to "utf-8" instead. */ - vimconv.vc_type = CONV_NONE; - if (enc_dbcs) { - p = enc_locale(); - if (p == NULL || STRCMP(p, p_enc) != 0) { - convert_setup(&vimconv, p_enc, (char_u *)"utf-8"); - vimconv.vc_fail = TRUE; - } - free(p); - } -#endif - - for (i = 0; i < 256; ++i) { - /* Our own function to reliably check the length of UTF-8 characters, - * independent of mblen(). */ - if (enc_utf8) - n = utf8len_tab[i]; - else if (enc_dbcs == 0) - n = 1; - else { - char buf[MB_MAXBYTES + 1]; - if (i == NUL) /* just in case mblen() can't handle "" */ - n = 1; - else { - buf[0] = i; - buf[1] = 0; -#ifdef LEN_FROM_CONV - if (vimconv.vc_type != CONV_NONE) { - /* - * string_convert() should fail when converting the first - * byte of a double-byte character. - */ - p = string_convert(&vimconv, (char_u *)buf, NULL); - if (p != NULL) { - free(p); - n = 1; - } else - n = 2; - } else -#endif - { - /* - * mblen() should return -1 for invalid (means the leading - * multibyte) character. However there are some platforms - * where mblen() returns 0 for invalid character. - * Therefore, following condition includes 0. - */ - ignored = mblen(NULL, 0); /* First reset the state. */ - if (mblen(buf, (size_t)1) <= 0) - n = 2; - else - n = 1; - } - } - } - mb_bytelen_tab[i] = n; - } - -#ifdef LEN_FROM_CONV - convert_setup(&vimconv, NULL, NULL); -#endif - - /* The cell width depends on the type of multi-byte characters. */ - (void)init_chartab(); - - /* When enc_utf8 is set or reset, (de)allocate ScreenLinesUC[] */ - screenalloc(FALSE); - - /* When using Unicode, set default for 'fileencodings'. */ - if (enc_utf8 && !option_was_set((char_u *)"fencs")) - set_string_option_direct((char_u *)"fencs", -1, - (char_u *)"ucs-bom,utf-8,default,latin1", OPT_FREE, 0); - -#ifdef HAVE_WORKING_LIBINTL - /* GNU gettext 0.10.37 supports this feature: set the codeset used for - * translated messages independently from the current locale. */ - (void)bind_textdomain_codeset(VIMPACKAGE, - enc_utf8 ? "utf-8" : (char *)p_enc); -#endif - - - /* Fire an autocommand to let people do custom font setup. This must be - * after Vim has been setup for the new encoding. */ - apply_autocmds(EVENT_ENCODINGCHANGED, NULL, (char_u *)"", FALSE, curbuf); - - /* Need to reload spell dictionaries */ - spell_reload(); - - return NULL; -} - -/* - * Return the size of the BOM for the current buffer: - * 0 - no BOM - * 2 - UCS-2 or UTF-16 BOM - * 4 - UCS-4 BOM - * 3 - UTF-8 BOM - */ -int bomb_size() -{ - int n = 0; - - if (curbuf->b_p_bomb && !curbuf->b_p_bin) { - if (*curbuf->b_p_fenc == NUL) { - if (enc_utf8) { - if (enc_unicode != 0) - n = enc_unicode; - else - n = 3; - } - } else if (STRCMP(curbuf->b_p_fenc, "utf-8") == 0) - n = 3; - else if (STRNCMP(curbuf->b_p_fenc, "ucs-2", 5) == 0 - || STRNCMP(curbuf->b_p_fenc, "utf-16", 6) == 0) - n = 2; - else if (STRNCMP(curbuf->b_p_fenc, "ucs-4", 5) == 0) - n = 4; - } - return n; -} - -/* - * Remove all BOM from "s" by moving remaining text. - */ -void remove_bom(char_u *s) -{ - if (enc_utf8) { - char_u *p = s; - - while ((p = vim_strbyte(p, 0xef)) != NULL) { - if (p[1] == 0xbb && p[2] == 0xbf) - STRMOVE(p, p + 3); - else - ++p; - } - } -} - -/* - * Get class of pointer: - * 0 for blank or NUL - * 1 for punctuation - * 2 for an (ASCII) word character - * >2 for other word characters - */ -int mb_get_class(char_u *p) -{ - return mb_get_class_buf(p, curbuf); -} - -int mb_get_class_buf(char_u *p, buf_T *buf) -{ - if (MB_BYTE2LEN(p[0]) == 1) { - if (p[0] == NUL || vim_iswhite(p[0])) - return 0; - if (vim_iswordc_buf(p[0], buf)) - return 2; - return 1; - } - if (enc_dbcs != 0 && p[0] != NUL && p[1] != NUL) - return dbcs_class(p[0], p[1]); - if (enc_utf8) - return utf_class(utf_ptr2char(p)); - return 0; -} - -/* - * Get class of a double-byte character. This always returns 3 or bigger. - * TODO: Should return 1 for punctuation. - */ -int dbcs_class(unsigned lead, unsigned trail) -{ - switch (enc_dbcs) { - /* please add classify routine for your language in here */ - - case DBCS_JPNU: /* ? */ - case DBCS_JPN: - { - /* JIS code classification */ - unsigned char lb = lead; - unsigned char tb = trail; - - /* convert process code to JIS */ - /* - * XXX: Code page identification can not use with all - * system! So, some other encoding information - * will be needed. - * In japanese: SJIS,EUC,UNICODE,(JIS) - * Note that JIS-code system don't use as - * process code in most system because it uses - * escape sequences(JIS is context depend encoding). - */ - /* assume process code is JAPANESE-EUC */ - lb &= 0x7f; - tb &= 0x7f; - /* exceptions */ - switch (lb << 8 | tb) { - case 0x2121: /* ZENKAKU space */ - return 0; - case 0x2122: /* TOU-TEN (Japanese comma) */ - case 0x2123: /* KU-TEN (Japanese period) */ - case 0x2124: /* ZENKAKU comma */ - case 0x2125: /* ZENKAKU period */ - return 1; - case 0x213c: /* prolongedsound handled as KATAKANA */ - return 13; - } - /* sieved by KU code */ - switch (lb) { - case 0x21: - case 0x22: - /* special symbols */ - return 10; - case 0x23: - /* alpha-numeric */ - return 11; - case 0x24: - /* hiragana */ - return 12; - case 0x25: - /* katakana */ - return 13; - case 0x26: - /* greek */ - return 14; - case 0x27: - /* russian */ - return 15; - case 0x28: - /* lines */ - return 16; - default: - /* kanji */ - return 17; - } - } - - case DBCS_KORU: /* ? */ - case DBCS_KOR: - { - /* KS code classification */ - unsigned char c1 = lead; - unsigned char c2 = trail; - - /* - * 20 : Hangul - * 21 : Hanja - * 22 : Symbols - * 23 : Alpha-numeric/Roman Letter (Full width) - * 24 : Hangul Letter(Alphabet) - * 25 : Roman Numeral/Greek Letter - * 26 : Box Drawings - * 27 : Unit Symbols - * 28 : Circled/Parenthesized Letter - * 29 : Hiragana/Katakana - * 30 : Cyrillic Letter - */ - - if (c1 >= 0xB0 && c1 <= 0xC8) - /* Hangul */ - return 20; - - else if (c1 >= 0xCA && c1 <= 0xFD) - /* Hanja */ - return 21; - else switch (c1) { - case 0xA1: - case 0xA2: - /* Symbols */ - return 22; - case 0xA3: - /* Alpha-numeric */ - return 23; - case 0xA4: - /* Hangul Letter(Alphabet) */ - return 24; - case 0xA5: - /* Roman Numeral/Greek Letter */ - return 25; - case 0xA6: - /* Box Drawings */ - return 26; - case 0xA7: - /* Unit Symbols */ - return 27; - case 0xA8: - case 0xA9: - if (c2 <= 0xAF) - return 25; /* Roman Letter */ - else if (c2 >= 0xF6) - return 22; /* Symbols */ - else - /* Circled/Parenthesized Letter */ - return 28; - case 0xAA: - case 0xAB: - /* Hiragana/Katakana */ - return 29; - case 0xAC: - /* Cyrillic Letter */ - return 30; - } - } - default: - break; - } - return 3; -} - -/* - * mb_char2len() function pointer. - * Return length in bytes of character "c". - * Returns 1 for a single-byte character. - */ -int latin_char2len(int c) -{ - return 1; -} - -static int dbcs_char2len(int c) -{ - if (c >= 0x100) - return 2; - return 1; -} - -/* - * mb_char2bytes() function pointer. - * Convert a character to its bytes. - * Returns the length in bytes. - */ -int latin_char2bytes(int c, char_u *buf) -{ - buf[0] = c; - return 1; -} - -static int dbcs_char2bytes(int c, char_u *buf) -{ - if (c >= 0x100) { - buf[0] = (unsigned)c >> 8; - buf[1] = c; - /* Never use a NUL byte, it causes lots of trouble. It's an invalid - * character anyway. */ - if (buf[1] == NUL) - buf[1] = '\n'; - return 2; - } - buf[0] = c; - return 1; -} - -/* - * mb_ptr2len() function pointer. - * Get byte length of character at "*p" but stop at a NUL. - * For UTF-8 this includes following composing characters. - * Returns 0 when *p is NUL. - */ -int latin_ptr2len(char_u *p) -{ - return MB_BYTE2LEN(*p); -} - -static int dbcs_ptr2len(char_u *p) -{ - int len; - - /* Check if second byte is not missing. */ - len = MB_BYTE2LEN(*p); - if (len == 2 && p[1] == NUL) - len = 1; - return len; -} - -/* - * mb_ptr2len_len() function pointer. - * Like mb_ptr2len(), but limit to read "size" bytes. - * Returns 0 for an empty string. - * Returns 1 for an illegal char or an incomplete byte sequence. - */ -int latin_ptr2len_len(char_u *p, int size) -{ - if (size < 1 || *p == NUL) - return 0; - return 1; -} - -static int dbcs_ptr2len_len(char_u *p, int size) -{ - int len; - - if (size < 1 || *p == NUL) - return 0; - if (size == 1) - return 1; - /* Check that second byte is not missing. */ - len = MB_BYTE2LEN(*p); - if (len == 2 && p[1] == NUL) - len = 1; - return len; -} - -struct interval { - long first; - long last; -}; -static int intable(struct interval *table, size_t size, int c); - -/* - * Return TRUE if "c" is in "table[size / sizeof(struct interval)]". - */ -static int intable(struct interval *table, size_t size, int c) -{ - int mid, bot, top; - - /* first quick check for Latin1 etc. characters */ - if (c < table[0].first) - return FALSE; - - /* binary search in table */ - bot = 0; - top = (int)(size / sizeof(struct interval) - 1); - while (top >= bot) { - mid = (bot + top) / 2; - if (table[mid].last < c) - bot = mid + 1; - else if (table[mid].first > c) - top = mid - 1; - else - return TRUE; - } - return FALSE; -} - -/* - * For UTF-8 character "c" return 2 for a double-width character, 1 for others. - * Returns 4 or 6 for an unprintable character. - * Is only correct for characters >= 0x80. - * When p_ambw is "double", return 2 for a character with East Asian Width - * class 'A'(mbiguous). - */ -int utf_char2cells(int c) -{ - /* Sorted list of non-overlapping intervals of East Asian double width - * characters, generated with ../runtime/tools/unicode.vim. */ - static struct interval doublewidth[] = - { - {0x1100, 0x115f}, - {0x11a3, 0x11a7}, - {0x11fa, 0x11ff}, - {0x2329, 0x232a}, - {0x2e80, 0x2e99}, - {0x2e9b, 0x2ef3}, - {0x2f00, 0x2fd5}, - {0x2ff0, 0x2ffb}, - {0x3000, 0x3029}, - {0x3030, 0x303e}, - {0x3041, 0x3096}, - {0x309b, 0x30ff}, - {0x3105, 0x312d}, - {0x3131, 0x318e}, - {0x3190, 0x31b7}, - {0x31c0, 0x31e3}, - {0x31f0, 0x321e}, - {0x3220, 0x3247}, - {0x3250, 0x32fe}, - {0x3300, 0x4dbf}, - {0x4e00, 0xa48c}, - {0xa490, 0xa4c6}, - {0xa960, 0xa97c}, - {0xac00, 0xd7a3}, - {0xd7b0, 0xd7c6}, - {0xd7cb, 0xd7fb}, - {0xf900, 0xfaff}, - {0xfe10, 0xfe19}, - {0xfe30, 0xfe52}, - {0xfe54, 0xfe66}, - {0xfe68, 0xfe6b}, - {0xff01, 0xff60}, - {0xffe0, 0xffe6}, - {0x1f200, 0x1f200}, - {0x1f210, 0x1f231}, - {0x1f240, 0x1f248}, - {0x20000, 0x2fffd}, - {0x30000, 0x3fffd} - }; - /* Sorted list of non-overlapping intervals of East Asian Ambiguous - * characters, generated with ../runtime/tools/unicode.vim. */ - static struct interval ambiguous[] = - { - {0x00a1, 0x00a1}, - {0x00a4, 0x00a4}, - {0x00a7, 0x00a8}, - {0x00aa, 0x00aa}, - {0x00ad, 0x00ae}, - {0x00b0, 0x00b4}, - {0x00b6, 0x00ba}, - {0x00bc, 0x00bf}, - {0x00c6, 0x00c6}, - {0x00d0, 0x00d0}, - {0x00d7, 0x00d8}, - {0x00de, 0x00e1}, - {0x00e6, 0x00e6}, - {0x00e8, 0x00ea}, - {0x00ec, 0x00ed}, - {0x00f0, 0x00f0}, - {0x00f2, 0x00f3}, - {0x00f7, 0x00fa}, - {0x00fc, 0x00fc}, - {0x00fe, 0x00fe}, - {0x0101, 0x0101}, - {0x0111, 0x0111}, - {0x0113, 0x0113}, - {0x011b, 0x011b}, - {0x0126, 0x0127}, - {0x012b, 0x012b}, - {0x0131, 0x0133}, - {0x0138, 0x0138}, - {0x013f, 0x0142}, - {0x0144, 0x0144}, - {0x0148, 0x014b}, - {0x014d, 0x014d}, - {0x0152, 0x0153}, - {0x0166, 0x0167}, - {0x016b, 0x016b}, - {0x01ce, 0x01ce}, - {0x01d0, 0x01d0}, - {0x01d2, 0x01d2}, - {0x01d4, 0x01d4}, - {0x01d6, 0x01d6}, - {0x01d8, 0x01d8}, - {0x01da, 0x01da}, - {0x01dc, 0x01dc}, - {0x0251, 0x0251}, - {0x0261, 0x0261}, - {0x02c4, 0x02c4}, - {0x02c7, 0x02c7}, - {0x02c9, 0x02cb}, - {0x02cd, 0x02cd}, - {0x02d0, 0x02d0}, - {0x02d8, 0x02db}, - {0x02dd, 0x02dd}, - {0x02df, 0x02df}, - {0x0391, 0x03a1}, - {0x03a3, 0x03a9}, - {0x03b1, 0x03c1}, - {0x03c3, 0x03c9}, - {0x0401, 0x0401}, - {0x0410, 0x044f}, - {0x0451, 0x0451}, - {0x2010, 0x2010}, - {0x2013, 0x2016}, - {0x2018, 0x2019}, - {0x201c, 0x201d}, - {0x2020, 0x2022}, - {0x2024, 0x2027}, - {0x2030, 0x2030}, - {0x2032, 0x2033}, - {0x2035, 0x2035}, - {0x203b, 0x203b}, - {0x203e, 0x203e}, - {0x2074, 0x2074}, - {0x207f, 0x207f}, - {0x2081, 0x2084}, - {0x20ac, 0x20ac}, - {0x2103, 0x2103}, - {0x2105, 0x2105}, - {0x2109, 0x2109}, - {0x2113, 0x2113}, - {0x2116, 0x2116}, - {0x2121, 0x2122}, - {0x2126, 0x2126}, - {0x212b, 0x212b}, - {0x2153, 0x2154}, - {0x215b, 0x215e}, - {0x2160, 0x216b}, - {0x2170, 0x2179}, - {0x2189, 0x2189}, - {0x2190, 0x2199}, - {0x21b8, 0x21b9}, - {0x21d2, 0x21d2}, - {0x21d4, 0x21d4}, - {0x21e7, 0x21e7}, - {0x2200, 0x2200}, - {0x2202, 0x2203}, - {0x2207, 0x2208}, - {0x220b, 0x220b}, - {0x220f, 0x220f}, - {0x2211, 0x2211}, - {0x2215, 0x2215}, - {0x221a, 0x221a}, - {0x221d, 0x2220}, - {0x2223, 0x2223}, - {0x2225, 0x2225}, - {0x2227, 0x222c}, - {0x222e, 0x222e}, - {0x2234, 0x2237}, - {0x223c, 0x223d}, - {0x2248, 0x2248}, - {0x224c, 0x224c}, - {0x2252, 0x2252}, - {0x2260, 0x2261}, - {0x2264, 0x2267}, - {0x226a, 0x226b}, - {0x226e, 0x226f}, - {0x2282, 0x2283}, - {0x2286, 0x2287}, - {0x2295, 0x2295}, - {0x2299, 0x2299}, - {0x22a5, 0x22a5}, - {0x22bf, 0x22bf}, - {0x2312, 0x2312}, - {0x2460, 0x24e9}, - {0x24eb, 0x254b}, - {0x2550, 0x2573}, - {0x2580, 0x258f}, - {0x2592, 0x2595}, - {0x25a0, 0x25a1}, - {0x25a3, 0x25a9}, - {0x25b2, 0x25b3}, - {0x25b6, 0x25b7}, - {0x25bc, 0x25bd}, - {0x25c0, 0x25c1}, - {0x25c6, 0x25c8}, - {0x25cb, 0x25cb}, - {0x25ce, 0x25d1}, - {0x25e2, 0x25e5}, - {0x25ef, 0x25ef}, - {0x2605, 0x2606}, - {0x2609, 0x2609}, - {0x260e, 0x260f}, - {0x2614, 0x2615}, - {0x261c, 0x261c}, - {0x261e, 0x261e}, - {0x2640, 0x2640}, - {0x2642, 0x2642}, - {0x2660, 0x2661}, - {0x2663, 0x2665}, - {0x2667, 0x266a}, - {0x266c, 0x266d}, - {0x266f, 0x266f}, - {0x269e, 0x269f}, - {0x26be, 0x26bf}, - {0x26c4, 0x26cd}, - {0x26cf, 0x26e1}, - {0x26e3, 0x26e3}, - {0x26e8, 0x26ff}, - {0x273d, 0x273d}, - {0x2757, 0x2757}, - {0x2776, 0x277f}, - {0x2b55, 0x2b59}, - {0x3248, 0x324f}, - {0xe000, 0xf8ff}, - {0xfffd, 0xfffd}, - {0x1f100, 0x1f10a}, - {0x1f110, 0x1f12d}, - {0x1f131, 0x1f131}, - {0x1f13d, 0x1f13d}, - {0x1f13f, 0x1f13f}, - {0x1f142, 0x1f142}, - {0x1f146, 0x1f146}, - {0x1f14a, 0x1f14e}, - {0x1f157, 0x1f157}, - {0x1f15f, 0x1f15f}, - {0x1f179, 0x1f179}, - {0x1f17b, 0x1f17c}, - {0x1f17f, 0x1f17f}, - {0x1f18a, 0x1f18d}, - {0x1f190, 0x1f190}, - {0xf0000, 0xffffd}, - {0x100000, 0x10fffd} - }; - - if (c >= 0x100) { -#ifdef USE_WCHAR_FUNCTIONS - /* - * Assume the library function wcwidth() works better than our own - * stuff. It should return 1 for ambiguous width chars! - */ - int n = wcwidth(c); - - if (n < 0) - return 6; /* unprintable, displays */ - if (n > 1) - return n; -#else - if (!utf_printable(c)) - return 6; /* unprintable, displays */ - if (intable(doublewidth, sizeof(doublewidth), c)) - return 2; -#endif - } - /* Characters below 0x100 are influenced by 'isprint' option */ - else if (c >= 0x80 && !vim_isprintc(c)) - return 4; /* unprintable, displays */ - - if (c >= 0x80 && *p_ambw == 'd' && intable(ambiguous, sizeof(ambiguous), c)) - return 2; - - return 1; -} - -/* - * mb_ptr2cells() function pointer. - * Return the number of display cells character at "*p" occupies. - * This doesn't take care of unprintable characters, use ptr2cells() for that. - */ -int latin_ptr2cells(char_u *p) -{ - return 1; -} - -int utf_ptr2cells(char_u *p) -{ - int c; - - /* Need to convert to a wide character. */ - if (*p >= 0x80) { - c = utf_ptr2char(p); - /* An illegal byte is displayed as . */ - if (utf_ptr2len(p) == 1 || c == NUL) - return 4; - /* If the char is ASCII it must be an overlong sequence. */ - if (c < 0x80) - return char2cells(c); - return utf_char2cells(c); - } - return 1; -} - -int dbcs_ptr2cells(char_u *p) -{ - /* Number of cells is equal to number of bytes, except for euc-jp when - * the first byte is 0x8e. */ - if (enc_dbcs == DBCS_JPNU && *p == 0x8e) - return 1; - return MB_BYTE2LEN(*p); -} - -/* - * mb_ptr2cells_len() function pointer. - * Like mb_ptr2cells(), but limit string length to "size". - * For an empty string or truncated character returns 1. - */ -int latin_ptr2cells_len(char_u *p, int size) -{ - return 1; -} - -static int utf_ptr2cells_len(char_u *p, int size) -{ - int c; - - /* Need to convert to a wide character. */ - if (size > 0 && *p >= 0x80) { - if (utf_ptr2len_len(p, size) < utf8len_tab[*p]) - return 1; /* truncated */ - c = utf_ptr2char(p); - /* An illegal byte is displayed as . */ - if (utf_ptr2len(p) == 1 || c == NUL) - return 4; - /* If the char is ASCII it must be an overlong sequence. */ - if (c < 0x80) - return char2cells(c); - return utf_char2cells(c); - } - return 1; -} - -static int dbcs_ptr2cells_len(char_u *p, int size) -{ - /* Number of cells is equal to number of bytes, except for euc-jp when - * the first byte is 0x8e. */ - if (size <= 1 || (enc_dbcs == DBCS_JPNU && *p == 0x8e)) - return 1; - return MB_BYTE2LEN(*p); -} - -/* - * mb_char2cells() function pointer. - * Return the number of display cells character "c" occupies. - * Only takes care of multi-byte chars, not "^C" and such. - */ -int latin_char2cells(int c) -{ - return 1; -} - -static int dbcs_char2cells(int c) -{ - /* Number of cells is equal to number of bytes, except for euc-jp when - * the first byte is 0x8e. */ - if (enc_dbcs == DBCS_JPNU && ((unsigned)c >> 8) == 0x8e) - return 1; - /* use the first byte */ - return MB_BYTE2LEN((unsigned)c >> 8); -} - -/* - * Return the number of cells occupied by string "p". - * Stop at a NUL character. When "len" >= 0 stop at character "p[len]". - */ -int mb_string2cells(char_u *p, int len) -{ - int i; - int clen = 0; - - for (i = 0; (len < 0 || i < len) && p[i] != NUL; i += (*mb_ptr2len)(p + i)) - clen += (*mb_ptr2cells)(p + i); - return clen; -} - -/* - * mb_off2cells() function pointer. - * Return number of display cells for char at ScreenLines[off]. - * We make sure that the offset used is less than "max_off". - */ -int latin_off2cells(unsigned off, unsigned max_off) -{ - return 1; -} - -int dbcs_off2cells(unsigned off, unsigned max_off) -{ - /* never check beyond end of the line */ - if (off >= max_off) - return 1; - - /* Number of cells is equal to number of bytes, except for euc-jp when - * the first byte is 0x8e. */ - if (enc_dbcs == DBCS_JPNU && ScreenLines[off] == 0x8e) - return 1; - return MB_BYTE2LEN(ScreenLines[off]); -} - -int utf_off2cells(unsigned off, unsigned max_off) -{ - return (off + 1 < max_off && ScreenLines[off + 1] == 0) ? 2 : 1; -} - -/* - * mb_ptr2char() function pointer. - * Convert a byte sequence into a character. - */ -int latin_ptr2char(char_u *p) -{ - return *p; -} - -static int dbcs_ptr2char(char_u *p) -{ - if (MB_BYTE2LEN(*p) > 1 && p[1] != NUL) - return (p[0] << 8) + p[1]; - return *p; -} - -/* - * Convert a UTF-8 byte sequence to a wide character. - * If the sequence is illegal or truncated by a NUL the first byte is - * returned. - * Does not include composing characters, of course. - */ -int utf_ptr2char(char_u *p) -{ - int len; - - if (p[0] < 0x80) /* be quick for ASCII */ - return p[0]; - - len = utf8len_tab_zero[p[0]]; - if (len > 1 && (p[1] & 0xc0) == 0x80) { - if (len == 2) - return ((p[0] & 0x1f) << 6) + (p[1] & 0x3f); - if ((p[2] & 0xc0) == 0x80) { - if (len == 3) - return ((p[0] & 0x0f) << 12) + ((p[1] & 0x3f) << 6) - + (p[2] & 0x3f); - if ((p[3] & 0xc0) == 0x80) { - if (len == 4) - return ((p[0] & 0x07) << 18) + ((p[1] & 0x3f) << 12) - + ((p[2] & 0x3f) << 6) + (p[3] & 0x3f); - if ((p[4] & 0xc0) == 0x80) { - if (len == 5) - return ((p[0] & 0x03) << 24) + ((p[1] & 0x3f) << 18) - + ((p[2] & 0x3f) << 12) + ((p[3] & 0x3f) << 6) - + (p[4] & 0x3f); - if ((p[5] & 0xc0) == 0x80 && len == 6) - return ((p[0] & 0x01) << 30) + ((p[1] & 0x3f) << 24) - + ((p[2] & 0x3f) << 18) + ((p[3] & 0x3f) << 12) - + ((p[4] & 0x3f) << 6) + (p[5] & 0x3f); - } - } - } - } - /* Illegal value, just return the first byte */ - return p[0]; -} - -/* - * Convert a UTF-8 byte sequence to a wide character. - * String is assumed to be terminated by NUL or after "n" bytes, whichever - * comes first. - * The function is safe in the sense that it never accesses memory beyond the - * first "n" bytes of "s". - * - * On success, returns decoded codepoint, advances "s" to the beginning of - * next character and decreases "n" accordingly. - * - * If end of string was reached, returns 0 and, if "n" > 0, advances "s" past - * NUL byte. - * - * If byte sequence is illegal or incomplete, returns -1 and does not advance - * "s". - */ -static int utf_safe_read_char_adv(char_u **s, size_t *n) -{ - int c, k; - - if (*n == 0) /* end of buffer */ - return 0; - - k = utf8len_tab_zero[**s]; - - if (k == 1) { - /* ASCII character or NUL */ - (*n)--; - return *(*s)++; - } - - if ((size_t)k <= *n) { - /* We have a multibyte sequence and it isn't truncated by buffer - * limits so utf_ptr2char() is safe to use. Or the first byte is - * illegal (k=0), and it's also safe to use utf_ptr2char(). */ - c = utf_ptr2char(*s); - - /* On failure, utf_ptr2char() returns the first byte, so here we - * check equality with the first byte. The only non-ASCII character - * which equals the first byte of its own UTF-8 representation is - * U+00C3 (UTF-8: 0xC3 0x83), so need to check that special case too. - * It's safe even if n=1, else we would have k=2 > n. */ - if (c != (int)(**s) || (c == 0xC3 && (*s)[1] == 0x83)) { - /* byte sequence was successfully decoded */ - *s += k; - *n -= k; - return c; - } - } - - /* byte sequence is incomplete or illegal */ - return -1; -} - -/* - * Get character at **pp and advance *pp to the next character. - * Note: composing characters are skipped! - */ -int mb_ptr2char_adv(char_u **pp) -{ - int c; - - c = (*mb_ptr2char)(*pp); - *pp += (*mb_ptr2len)(*pp); - return c; -} - -/* - * Get character at **pp and advance *pp to the next character. - * Note: composing characters are returned as separate characters. - */ -int mb_cptr2char_adv(char_u **pp) -{ - int c; - - c = (*mb_ptr2char)(*pp); - if (enc_utf8) - *pp += utf_ptr2len(*pp); - else - *pp += (*mb_ptr2len)(*pp); - return c; -} - -/* - * Check if the character pointed to by "p2" is a composing character when it - * comes after "p1". For Arabic sometimes "ab" is replaced with "c", which - * behaves like a composing character. - */ -int utf_composinglike(char_u *p1, char_u *p2) -{ - int c2; - - c2 = utf_ptr2char(p2); - if (utf_iscomposing(c2)) - return TRUE; - if (!arabic_maycombine(c2)) - return FALSE; - return arabic_combine(utf_ptr2char(p1), c2); -} - -/* - * Convert a UTF-8 byte string to a wide character. Also get up to MAX_MCO - * composing characters. - */ -int utfc_ptr2char( - char_u *p, - int *pcc /* return: composing chars, last one is 0 */ - ) -{ - int len; - int c; - int cc; - int i = 0; - - c = utf_ptr2char(p); - len = utf_ptr2len(p); - - /* Only accept a composing char when the first char isn't illegal. */ - if ((len > 1 || *p < 0x80) - && p[len] >= 0x80 - && UTF_COMPOSINGLIKE(p, p + len)) { - cc = utf_ptr2char(p + len); - for (;; ) { - pcc[i++] = cc; - if (i == MAX_MCO) - break; - len += utf_ptr2len(p + len); - if (p[len] < 0x80 || !utf_iscomposing(cc = utf_ptr2char(p + len))) - break; - } - } - - if (i < MAX_MCO) /* last composing char must be 0 */ - pcc[i] = 0; - - return c; -} - -/* - * Convert a UTF-8 byte string to a wide character. Also get up to MAX_MCO - * composing characters. Use no more than p[maxlen]. - */ -int utfc_ptr2char_len( - char_u *p, - int *pcc, /* return: composing chars, last one is 0 */ - int maxlen - ) -{ - int len; - int c; - int cc; - int i = 0; - - c = utf_ptr2char(p); - len = utf_ptr2len_len(p, maxlen); - /* Only accept a composing char when the first char isn't illegal. */ - if ((len > 1 || *p < 0x80) - && len < maxlen - && p[len] >= 0x80 - && UTF_COMPOSINGLIKE(p, p + len)) { - cc = utf_ptr2char(p + len); - for (;; ) { - pcc[i++] = cc; - if (i == MAX_MCO) - break; - len += utf_ptr2len_len(p + len, maxlen - len); - if (len >= maxlen - || p[len] < 0x80 - || !utf_iscomposing(cc = utf_ptr2char(p + len))) - break; - } - } - - if (i < MAX_MCO) /* last composing char must be 0 */ - pcc[i] = 0; - - return c; -} - -/* - * Convert the character at screen position "off" to a sequence of bytes. - * Includes the composing characters. - * "buf" must at least have the length MB_MAXBYTES + 1. - * Only to be used when ScreenLinesUC[off] != 0. - * Returns the produced number of bytes. - */ -int utfc_char2bytes(int off, char_u *buf) -{ - int len; - int i; - - len = utf_char2bytes(ScreenLinesUC[off], buf); - for (i = 0; i < Screen_mco; ++i) { - if (ScreenLinesC[i][off] == 0) - break; - len += utf_char2bytes(ScreenLinesC[i][off], buf + len); - } - return len; -} - -/* - * Get the length of a UTF-8 byte sequence, not including any following - * composing characters. - * Returns 0 for "". - * Returns 1 for an illegal byte sequence. - */ -int utf_ptr2len(char_u *p) -{ - int len; - int i; - - if (*p == NUL) - return 0; - len = utf8len_tab[*p]; - for (i = 1; i < len; ++i) - if ((p[i] & 0xc0) != 0x80) - return 1; - return len; -} - -/* - * Return length of UTF-8 character, obtained from the first byte. - * "b" must be between 0 and 255! - * Returns 1 for an invalid first byte value. - */ -int utf_byte2len(int b) -{ - return utf8len_tab[b]; -} - -/* - * Get the length of UTF-8 byte sequence "p[size]". Does not include any - * following composing characters. - * Returns 1 for "". - * Returns 1 for an illegal byte sequence (also in incomplete byte seq.). - * Returns number > "size" for an incomplete byte sequence. - * Never returns zero. - */ -int utf_ptr2len_len(char_u *p, int size) -{ - int len; - int i; - int m; - - len = utf8len_tab[*p]; - if (len == 1) - return 1; /* NUL, ascii or illegal lead byte */ - if (len > size) - m = size; /* incomplete byte sequence. */ - else - m = len; - for (i = 1; i < m; ++i) - if ((p[i] & 0xc0) != 0x80) - return 1; - return len; -} - -/* - * Return the number of bytes the UTF-8 encoding of the character at "p" takes. - * This includes following composing characters. - */ -int utfc_ptr2len(char_u *p) -{ - int len; - int b0 = *p; - int prevlen; - - if (b0 == NUL) - return 0; - if (b0 < 0x80 && p[1] < 0x80) /* be quick for ASCII */ - return 1; - - /* Skip over first UTF-8 char, stopping at a NUL byte. */ - len = utf_ptr2len(p); - - /* Check for illegal byte. */ - if (len == 1 && b0 >= 0x80) - return 1; - - /* - * Check for composing characters. We can handle only the first six, but - * skip all of them (otherwise the cursor would get stuck). - */ - prevlen = 0; - for (;; ) { - if (p[len] < 0x80 || !UTF_COMPOSINGLIKE(p + prevlen, p + len)) - return len; - - /* Skip over composing char */ - prevlen = len; - len += utf_ptr2len(p + len); - } -} - -/* - * Return the number of bytes the UTF-8 encoding of the character at "p[size]" - * takes. This includes following composing characters. - * Returns 0 for an empty string. - * Returns 1 for an illegal char or an incomplete byte sequence. - */ -int utfc_ptr2len_len(char_u *p, int size) -{ - int len; - int prevlen; - - if (size < 1 || *p == NUL) - return 0; - if (p[0] < 0x80 && (size == 1 || p[1] < 0x80)) /* be quick for ASCII */ - return 1; - - /* Skip over first UTF-8 char, stopping at a NUL byte. */ - len = utf_ptr2len_len(p, size); - - /* Check for illegal byte and incomplete byte sequence. */ - if ((len == 1 && p[0] >= 0x80) || len > size) - return 1; - - /* - * Check for composing characters. We can handle only the first six, but - * skip all of them (otherwise the cursor would get stuck). - */ - prevlen = 0; - while (len < size) { - int len_next_char; - - if (p[len] < 0x80) - break; - - /* - * Next character length should not go beyond size to ensure that - * UTF_COMPOSINGLIKE(...) does not read beyond size. - */ - len_next_char = utf_ptr2len_len(p + len, size - len); - if (len_next_char > size - len) - break; - - if (!UTF_COMPOSINGLIKE(p + prevlen, p + len)) - break; - - /* Skip over composing char */ - prevlen = len; - len += len_next_char; - } - return len; -} - -/* - * Return the number of bytes the UTF-8 encoding of character "c" takes. - * This does not include composing characters. - */ -int utf_char2len(int c) -{ - if (c < 0x80) - return 1; - if (c < 0x800) - return 2; - if (c < 0x10000) - return 3; - if (c < 0x200000) - return 4; - if (c < 0x4000000) - return 5; - return 6; -} - -/* - * Convert Unicode character "c" to UTF-8 string in "buf[]". - * Returns the number of bytes. - * This does not include composing characters. - */ -int utf_char2bytes(int c, char_u *buf) -{ - if (c < 0x80) { /* 7 bits */ - buf[0] = c; - return 1; - } - if (c < 0x800) { /* 11 bits */ - buf[0] = 0xc0 + ((unsigned)c >> 6); - buf[1] = 0x80 + (c & 0x3f); - return 2; - } - if (c < 0x10000) { /* 16 bits */ - buf[0] = 0xe0 + ((unsigned)c >> 12); - buf[1] = 0x80 + (((unsigned)c >> 6) & 0x3f); - buf[2] = 0x80 + (c & 0x3f); - return 3; - } - if (c < 0x200000) { /* 21 bits */ - buf[0] = 0xf0 + ((unsigned)c >> 18); - buf[1] = 0x80 + (((unsigned)c >> 12) & 0x3f); - buf[2] = 0x80 + (((unsigned)c >> 6) & 0x3f); - buf[3] = 0x80 + (c & 0x3f); - return 4; - } - if (c < 0x4000000) { /* 26 bits */ - buf[0] = 0xf8 + ((unsigned)c >> 24); - buf[1] = 0x80 + (((unsigned)c >> 18) & 0x3f); - buf[2] = 0x80 + (((unsigned)c >> 12) & 0x3f); - buf[3] = 0x80 + (((unsigned)c >> 6) & 0x3f); - buf[4] = 0x80 + (c & 0x3f); - return 5; - } - /* 31 bits */ - buf[0] = 0xfc + ((unsigned)c >> 30); - buf[1] = 0x80 + (((unsigned)c >> 24) & 0x3f); - buf[2] = 0x80 + (((unsigned)c >> 18) & 0x3f); - buf[3] = 0x80 + (((unsigned)c >> 12) & 0x3f); - buf[4] = 0x80 + (((unsigned)c >> 6) & 0x3f); - buf[5] = 0x80 + (c & 0x3f); - return 6; -} - -/* - * Return TRUE if "c" is a composing UTF-8 character. This means it will be - * drawn on top of the preceding character. - * Based on code from Markus Kuhn. - */ -int utf_iscomposing(int c) -{ - /* Sorted list of non-overlapping intervals. - * Generated by ../runtime/tools/unicode.vim. */ - static struct interval combining[] = - { - {0x0300, 0x036f}, - {0x0483, 0x0489}, - {0x0591, 0x05bd}, - {0x05bf, 0x05bf}, - {0x05c1, 0x05c2}, - {0x05c4, 0x05c5}, - {0x05c7, 0x05c7}, - {0x0610, 0x061a}, - {0x064b, 0x065e}, - {0x0670, 0x0670}, - {0x06d6, 0x06dc}, - {0x06de, 0x06e4}, - {0x06e7, 0x06e8}, - {0x06ea, 0x06ed}, - {0x0711, 0x0711}, - {0x0730, 0x074a}, - {0x07a6, 0x07b0}, - {0x07eb, 0x07f3}, - {0x0816, 0x0819}, - {0x081b, 0x0823}, - {0x0825, 0x0827}, - {0x0829, 0x082d}, - {0x0900, 0x0903}, - {0x093c, 0x093c}, - {0x093e, 0x094e}, - {0x0951, 0x0955}, - {0x0962, 0x0963}, - {0x0981, 0x0983}, - {0x09bc, 0x09bc}, - {0x09be, 0x09c4}, - {0x09c7, 0x09c8}, - {0x09cb, 0x09cd}, - {0x09d7, 0x09d7}, - {0x09e2, 0x09e3}, - {0x0a01, 0x0a03}, - {0x0a3c, 0x0a3c}, - {0x0a3e, 0x0a42}, - {0x0a47, 0x0a48}, - {0x0a4b, 0x0a4d}, - {0x0a51, 0x0a51}, - {0x0a70, 0x0a71}, - {0x0a75, 0x0a75}, - {0x0a81, 0x0a83}, - {0x0abc, 0x0abc}, - {0x0abe, 0x0ac5}, - {0x0ac7, 0x0ac9}, - {0x0acb, 0x0acd}, - {0x0ae2, 0x0ae3}, - {0x0b01, 0x0b03}, - {0x0b3c, 0x0b3c}, - {0x0b3e, 0x0b44}, - {0x0b47, 0x0b48}, - {0x0b4b, 0x0b4d}, - {0x0b56, 0x0b57}, - {0x0b62, 0x0b63}, - {0x0b82, 0x0b82}, - {0x0bbe, 0x0bc2}, - {0x0bc6, 0x0bc8}, - {0x0bca, 0x0bcd}, - {0x0bd7, 0x0bd7}, - {0x0c01, 0x0c03}, - {0x0c3e, 0x0c44}, - {0x0c46, 0x0c48}, - {0x0c4a, 0x0c4d}, - {0x0c55, 0x0c56}, - {0x0c62, 0x0c63}, - {0x0c82, 0x0c83}, - {0x0cbc, 0x0cbc}, - {0x0cbe, 0x0cc4}, - {0x0cc6, 0x0cc8}, - {0x0cca, 0x0ccd}, - {0x0cd5, 0x0cd6}, - {0x0ce2, 0x0ce3}, - {0x0d02, 0x0d03}, - {0x0d3e, 0x0d44}, - {0x0d46, 0x0d48}, - {0x0d4a, 0x0d4d}, - {0x0d57, 0x0d57}, - {0x0d62, 0x0d63}, - {0x0d82, 0x0d83}, - {0x0dca, 0x0dca}, - {0x0dcf, 0x0dd4}, - {0x0dd6, 0x0dd6}, - {0x0dd8, 0x0ddf}, - {0x0df2, 0x0df3}, - {0x0e31, 0x0e31}, - {0x0e34, 0x0e3a}, - {0x0e47, 0x0e4e}, - {0x0eb1, 0x0eb1}, - {0x0eb4, 0x0eb9}, - {0x0ebb, 0x0ebc}, - {0x0ec8, 0x0ecd}, - {0x0f18, 0x0f19}, - {0x0f35, 0x0f35}, - {0x0f37, 0x0f37}, - {0x0f39, 0x0f39}, - {0x0f3e, 0x0f3f}, - {0x0f71, 0x0f84}, - {0x0f86, 0x0f87}, - {0x0f90, 0x0f97}, - {0x0f99, 0x0fbc}, - {0x0fc6, 0x0fc6}, - {0x102b, 0x103e}, - {0x1056, 0x1059}, - {0x105e, 0x1060}, - {0x1062, 0x1064}, - {0x1067, 0x106d}, - {0x1071, 0x1074}, - {0x1082, 0x108d}, - {0x108f, 0x108f}, - {0x109a, 0x109d}, - {0x135f, 0x135f}, - {0x1712, 0x1714}, - {0x1732, 0x1734}, - {0x1752, 0x1753}, - {0x1772, 0x1773}, - {0x17b6, 0x17d3}, - {0x17dd, 0x17dd}, - {0x180b, 0x180d}, - {0x18a9, 0x18a9}, - {0x1920, 0x192b}, - {0x1930, 0x193b}, - {0x19b0, 0x19c0}, - {0x19c8, 0x19c9}, - {0x1a17, 0x1a1b}, - {0x1a55, 0x1a5e}, - {0x1a60, 0x1a7c}, - {0x1a7f, 0x1a7f}, - {0x1b00, 0x1b04}, - {0x1b34, 0x1b44}, - {0x1b6b, 0x1b73}, - {0x1b80, 0x1b82}, - {0x1ba1, 0x1baa}, - {0x1c24, 0x1c37}, - {0x1cd0, 0x1cd2}, - {0x1cd4, 0x1ce8}, - {0x1ced, 0x1ced}, - {0x1cf2, 0x1cf2}, - {0x1dc0, 0x1de6}, - {0x1dfd, 0x1dff}, - {0x20d0, 0x20f0}, - {0x2cef, 0x2cf1}, - {0x2de0, 0x2dff}, - {0x302a, 0x302f}, - {0x3099, 0x309a}, - {0xa66f, 0xa672}, - {0xa67c, 0xa67d}, - {0xa6f0, 0xa6f1}, - {0xa802, 0xa802}, - {0xa806, 0xa806}, - {0xa80b, 0xa80b}, - {0xa823, 0xa827}, - {0xa880, 0xa881}, - {0xa8b4, 0xa8c4}, - {0xa8e0, 0xa8f1}, - {0xa926, 0xa92d}, - {0xa947, 0xa953}, - {0xa980, 0xa983}, - {0xa9b3, 0xa9c0}, - {0xaa29, 0xaa36}, - {0xaa43, 0xaa43}, - {0xaa4c, 0xaa4d}, - {0xaa7b, 0xaa7b}, - {0xaab0, 0xaab0}, - {0xaab2, 0xaab4}, - {0xaab7, 0xaab8}, - {0xaabe, 0xaabf}, - {0xaac1, 0xaac1}, - {0xabe3, 0xabea}, - {0xabec, 0xabed}, - {0xfb1e, 0xfb1e}, - {0xfe00, 0xfe0f}, - {0xfe20, 0xfe26}, - {0x101fd, 0x101fd}, - {0x10a01, 0x10a03}, - {0x10a05, 0x10a06}, - {0x10a0c, 0x10a0f}, - {0x10a38, 0x10a3a}, - {0x10a3f, 0x10a3f}, - {0x11080, 0x11082}, - {0x110b0, 0x110ba}, - {0x1d165, 0x1d169}, - {0x1d16d, 0x1d172}, - {0x1d17b, 0x1d182}, - {0x1d185, 0x1d18b}, - {0x1d1aa, 0x1d1ad}, - {0x1d242, 0x1d244}, - {0xe0100, 0xe01ef} - }; - - return intable(combining, sizeof(combining), c); -} - -/* - * Return TRUE for characters that can be displayed in a normal way. - * Only for characters of 0x100 and above! - */ -int utf_printable(int c) -{ -#ifdef USE_WCHAR_FUNCTIONS - /* - * Assume the iswprint() library function works better than our own stuff. - */ - return iswprint(c); -#else - /* Sorted list of non-overlapping intervals. - * 0xd800-0xdfff is reserved for UTF-16, actually illegal. */ - static struct interval nonprint[] = - { - {0x070f, 0x070f}, {0x180b, 0x180e}, {0x200b, 0x200f}, {0x202a, 0x202e}, - {0x206a, 0x206f}, {0xd800, 0xdfff}, {0xfeff, 0xfeff}, {0xfff9, 0xfffb}, - {0xfffe, 0xffff} - }; - - return !intable(nonprint, sizeof(nonprint), c); -#endif -} - -/* - * Get class of a Unicode character. - * 0: white space - * 1: punctuation - * 2 or bigger: some class of word character. - */ -int utf_class(int c) -{ - /* sorted list of non-overlapping intervals */ - static struct clinterval { - unsigned int first; - unsigned int last; - unsigned int class; - } classes[] = - { - {0x037e, 0x037e, 1}, /* Greek question mark */ - {0x0387, 0x0387, 1}, /* Greek ano teleia */ - {0x055a, 0x055f, 1}, /* Armenian punctuation */ - {0x0589, 0x0589, 1}, /* Armenian full stop */ - {0x05be, 0x05be, 1}, - {0x05c0, 0x05c0, 1}, - {0x05c3, 0x05c3, 1}, - {0x05f3, 0x05f4, 1}, - {0x060c, 0x060c, 1}, - {0x061b, 0x061b, 1}, - {0x061f, 0x061f, 1}, - {0x066a, 0x066d, 1}, - {0x06d4, 0x06d4, 1}, - {0x0700, 0x070d, 1}, /* Syriac punctuation */ - {0x0964, 0x0965, 1}, - {0x0970, 0x0970, 1}, - {0x0df4, 0x0df4, 1}, - {0x0e4f, 0x0e4f, 1}, - {0x0e5a, 0x0e5b, 1}, - {0x0f04, 0x0f12, 1}, - {0x0f3a, 0x0f3d, 1}, - {0x0f85, 0x0f85, 1}, - {0x104a, 0x104f, 1}, /* Myanmar punctuation */ - {0x10fb, 0x10fb, 1}, /* Georgian punctuation */ - {0x1361, 0x1368, 1}, /* Ethiopic punctuation */ - {0x166d, 0x166e, 1}, /* Canadian Syl. punctuation */ - {0x1680, 0x1680, 0}, - {0x169b, 0x169c, 1}, - {0x16eb, 0x16ed, 1}, - {0x1735, 0x1736, 1}, - {0x17d4, 0x17dc, 1}, /* Khmer punctuation */ - {0x1800, 0x180a, 1}, /* Mongolian punctuation */ - {0x2000, 0x200b, 0}, /* spaces */ - {0x200c, 0x2027, 1}, /* punctuation and symbols */ - {0x2028, 0x2029, 0}, - {0x202a, 0x202e, 1}, /* punctuation and symbols */ - {0x202f, 0x202f, 0}, - {0x2030, 0x205e, 1}, /* punctuation and symbols */ - {0x205f, 0x205f, 0}, - {0x2060, 0x27ff, 1}, /* punctuation and symbols */ - {0x2070, 0x207f, 0x2070}, /* superscript */ - {0x2080, 0x2094, 0x2080}, /* subscript */ - {0x20a0, 0x27ff, 1}, /* all kinds of symbols */ - {0x2800, 0x28ff, 0x2800}, /* braille */ - {0x2900, 0x2998, 1}, /* arrows, brackets, etc. */ - {0x29d8, 0x29db, 1}, - {0x29fc, 0x29fd, 1}, - {0x3000, 0x3000, 0}, /* ideographic space */ - {0x3001, 0x3020, 1}, /* ideographic punctuation */ - {0x3030, 0x3030, 1}, - {0x303d, 0x303d, 1}, - {0x3040, 0x309f, 0x3040}, /* Hiragana */ - {0x30a0, 0x30ff, 0x30a0}, /* Katakana */ - {0x3300, 0x9fff, 0x4e00}, /* CJK Ideographs */ - {0xac00, 0xd7a3, 0xac00}, /* Hangul Syllables */ - {0xf900, 0xfaff, 0x4e00}, /* CJK Ideographs */ - {0xfd3e, 0xfd3f, 1}, - {0xfe30, 0xfe6b, 1}, /* punctuation forms */ - {0xff00, 0xff0f, 1}, /* half/fullwidth ASCII */ - {0xff1a, 0xff20, 1}, /* half/fullwidth ASCII */ - {0xff3b, 0xff40, 1}, /* half/fullwidth ASCII */ - {0xff5b, 0xff65, 1}, /* half/fullwidth ASCII */ - {0x20000, 0x2a6df, 0x4e00}, /* CJK Ideographs */ - {0x2a700, 0x2b73f, 0x4e00}, /* CJK Ideographs */ - {0x2b740, 0x2b81f, 0x4e00}, /* CJK Ideographs */ - {0x2f800, 0x2fa1f, 0x4e00}, /* CJK Ideographs */ - }; - int bot = 0; - int top = sizeof(classes) / sizeof(struct clinterval) - 1; - int mid; - - /* First quick check for Latin1 characters, use 'iskeyword'. */ - if (c < 0x100) { - if (c == ' ' || c == '\t' || c == NUL || c == 0xa0) - return 0; /* blank */ - if (vim_iswordc(c)) - return 2; /* word character */ - return 1; /* punctuation */ - } - - /* binary search in table */ - while (top >= bot) { - mid = (bot + top) / 2; - if (classes[mid].last < (unsigned int)c) - bot = mid + 1; - else if (classes[mid].first > (unsigned int)c) - top = mid - 1; - else - return (int)classes[mid].class; - } - - /* most other characters are "word" characters */ - return 2; -} - -/* - * Code for Unicode case-dependent operations. Based on notes in - * http://www.unicode.org/Public/UNIDATA/CaseFolding.txt - * This code uses simple case folding, not full case folding. - * Last updated for Unicode 5.2. - */ - -/* - * The following tables are built by ../runtime/tools/unicode.vim. - * They must be in numeric order, because we use binary search. - * An entry such as {0x41,0x5a,1,32} means that Unicode characters in the - * range from 0x41 to 0x5a inclusive, stepping by 1, are changed to - * folded/upper/lower by adding 32. - */ -typedef struct { - int rangeStart; - int rangeEnd; - int step; - int offset; -} convertStruct; - -static convertStruct foldCase[] = -{ - {0x41,0x5a,1,32}, - {0xb5,0xb5,-1,775}, - {0xc0,0xd6,1,32}, - {0xd8,0xde,1,32}, - {0x100,0x12e,2,1}, - {0x132,0x136,2,1}, - {0x139,0x147,2,1}, - {0x14a,0x176,2,1}, - {0x178,0x178,-1,-121}, - {0x179,0x17d,2,1}, - {0x17f,0x17f,-1,-268}, - {0x181,0x181,-1,210}, - {0x182,0x184,2,1}, - {0x186,0x186,-1,206}, - {0x187,0x187,-1,1}, - {0x189,0x18a,1,205}, - {0x18b,0x18b,-1,1}, - {0x18e,0x18e,-1,79}, - {0x18f,0x18f,-1,202}, - {0x190,0x190,-1,203}, - {0x191,0x191,-1,1}, - {0x193,0x193,-1,205}, - {0x194,0x194,-1,207}, - {0x196,0x196,-1,211}, - {0x197,0x197,-1,209}, - {0x198,0x198,-1,1}, - {0x19c,0x19c,-1,211}, - {0x19d,0x19d,-1,213}, - {0x19f,0x19f,-1,214}, - {0x1a0,0x1a4,2,1}, - {0x1a6,0x1a6,-1,218}, - {0x1a7,0x1a7,-1,1}, - {0x1a9,0x1a9,-1,218}, - {0x1ac,0x1ac,-1,1}, - {0x1ae,0x1ae,-1,218}, - {0x1af,0x1af,-1,1}, - {0x1b1,0x1b2,1,217}, - {0x1b3,0x1b5,2,1}, - {0x1b7,0x1b7,-1,219}, - {0x1b8,0x1bc,4,1}, - {0x1c4,0x1c4,-1,2}, - {0x1c5,0x1c5,-1,1}, - {0x1c7,0x1c7,-1,2}, - {0x1c8,0x1c8,-1,1}, - {0x1ca,0x1ca,-1,2}, - {0x1cb,0x1db,2,1}, - {0x1de,0x1ee,2,1}, - {0x1f1,0x1f1,-1,2}, - {0x1f2,0x1f4,2,1}, - {0x1f6,0x1f6,-1,-97}, - {0x1f7,0x1f7,-1,-56}, - {0x1f8,0x21e,2,1}, - {0x220,0x220,-1,-130}, - {0x222,0x232,2,1}, - {0x23a,0x23a,-1,10795}, - {0x23b,0x23b,-1,1}, - {0x23d,0x23d,-1,-163}, - {0x23e,0x23e,-1,10792}, - {0x241,0x241,-1,1}, - {0x243,0x243,-1,-195}, - {0x244,0x244,-1,69}, - {0x245,0x245,-1,71}, - {0x246,0x24e,2,1}, - {0x345,0x345,-1,116}, - {0x370,0x372,2,1}, - {0x376,0x376,-1,1}, - {0x386,0x386,-1,38}, - {0x388,0x38a,1,37}, - {0x38c,0x38c,-1,64}, - {0x38e,0x38f,1,63}, - {0x391,0x3a1,1,32}, - {0x3a3,0x3ab,1,32}, - {0x3c2,0x3c2,-1,1}, - {0x3cf,0x3cf,-1,8}, - {0x3d0,0x3d0,-1,-30}, - {0x3d1,0x3d1,-1,-25}, - {0x3d5,0x3d5,-1,-15}, - {0x3d6,0x3d6,-1,-22}, - {0x3d8,0x3ee,2,1}, - {0x3f0,0x3f0,-1,-54}, - {0x3f1,0x3f1,-1,-48}, - {0x3f4,0x3f4,-1,-60}, - {0x3f5,0x3f5,-1,-64}, - {0x3f7,0x3f7,-1,1}, - {0x3f9,0x3f9,-1,-7}, - {0x3fa,0x3fa,-1,1}, - {0x3fd,0x3ff,1,-130}, - {0x400,0x40f,1,80}, - {0x410,0x42f,1,32}, - {0x460,0x480,2,1}, - {0x48a,0x4be,2,1}, - {0x4c0,0x4c0,-1,15}, - {0x4c1,0x4cd,2,1},