diff options
Diffstat (limited to 'src/charset.c')
-rw-r--r-- | src/charset.c | 91 |
1 files changed, 7 insertions, 84 deletions
diff --git a/src/charset.c b/src/charset.c index 0280954538..70e3bc2dcb 100644 --- a/src/charset.c +++ b/src/charset.c @@ -9,12 +9,10 @@ #include "vim.h" -#ifdef FEAT_MBYTE -# if defined(HAVE_WCHAR_H) -# include <wchar.h> /* for towupper() and towlower() */ -# endif -static int win_nolbr_chartabsize(win_T *wp, char_u *s, colnr_T col, int *headp); +#if defined(HAVE_WCHAR_H) +# include <wchar.h> /* for towupper() and towlower() */ #endif +static int win_nolbr_chartabsize(win_T *wp, char_u *s, colnr_T col, int *headp); static unsigned nr2hex(unsigned c); @@ -109,7 +107,6 @@ buf_init_chartab( #endif while (c < 256) { -#ifdef FEAT_MBYTE /* UTF-8: bytes 0xa0 - 0xff are printable (latin1) */ if (enc_utf8 && c >= 0xa0) g_chartab[c++] = CT_PRINT_CHAR + 1; @@ -120,26 +117,22 @@ buf_init_chartab( else if (enc_dbcs != 0 && MB_BYTE2LEN(c) == 2) g_chartab[c++] = CT_PRINT_CHAR + 2; else -#endif /* the rest is unprintable by default */ g_chartab[c++] = (dy_flags & DY_UHEX) ? 4 : 2; } -#ifdef FEAT_MBYTE /* Assume that every multi-byte char is a filename character. */ for (c = 1; c < 256; ++c) if ((enc_dbcs != 0 && MB_BYTE2LEN(c) > 1) || (enc_dbcs == DBCS_JPNU && c == 0x8e) || (enc_utf8 && c >= 0xa0)) g_chartab[c] |= CT_FNAME_CHAR; -#endif } /* * Init word char flags all to FALSE */ vim_memset(buf->b_chartab, 0, (size_t)32); -#ifdef FEAT_MBYTE if (enc_dbcs != 0) for (c = 0; c < 256; ++c) { @@ -147,7 +140,6 @@ buf_init_chartab( if (MB_BYTE2LEN(c) == 2) SET_CHARTAB(buf, c); } -#endif #ifdef FEAT_LISP /* @@ -184,11 +176,9 @@ buf_init_chartab( if (VIM_ISDIGIT(*p)) c = getdigits(&p); else -#ifdef FEAT_MBYTE if (has_mbyte) c = mb_ptr2char_adv(&p); else -#endif c = *p++; c2 = -1; if (*p == '-' && p[1] != NUL) @@ -197,11 +187,9 @@ buf_init_chartab( if (VIM_ISDIGIT(*p)) c2 = getdigits(&p); else -#ifdef FEAT_MBYTE if (has_mbyte) c2 = mb_ptr2char_adv(&p); else -#endif c2 = *p++; } if (c <= 0 || c >= 256 || (c2 < c && c2 != -1) || c2 >= 256 @@ -253,13 +241,9 @@ buf_init_chartab( || (p_altkeymap && (F_isalpha(c) || F_isdigit(c))) #endif - ) -#ifdef FEAT_MBYTE - /* For double-byte we keep the cell width, so - * that we can detect it from the first byte. */ - && !(enc_dbcs && MB_BYTE2LEN(c) == 2) -#endif - ) + // For double-byte we keep the cell width, so + // that we can detect it from the first byte. + ) && !(enc_dbcs && MB_BYTE2LEN(c) == 2)) { if (tilde) { @@ -322,12 +306,10 @@ trans_characters( room = bufsize - len; while (*buf != 0) { -# ifdef FEAT_MBYTE /* Assume a multi-byte character doesn't need translation. */ if (has_mbyte && (trs_len = (*mb_ptr2len)(buf)) > 1) len -= trs_len; else -# endif { trs = transchar_byte(*buf); trs_len = (int)STRLEN(trs); @@ -356,12 +338,9 @@ transstr(char_u *s) { char_u *res; char_u *p; -#ifdef FEAT_MBYTE int l, len, c; char_u hexbuf[11]; -#endif -#ifdef FEAT_MBYTE if (has_mbyte) { /* Compute the length of the result, taking account of unprintable @@ -394,7 +373,6 @@ transstr(char_u *s) res = alloc((unsigned)(len + 1)); } else -#endif res = alloc((unsigned)(vim_strsize(s) + 1)); if (res != NULL) { @@ -402,7 +380,6 @@ transstr(char_u *s) p = s; while (*p != NUL) { -#ifdef FEAT_MBYTE if (has_mbyte && (l = (*mb_ptr2len)(p)) > 1) { c = (*mb_ptr2char)(p); @@ -413,7 +390,6 @@ transstr(char_u *s) p += l; } else -#endif STRCAT(res, transchar_byte(*p++)); } } @@ -468,7 +444,6 @@ str_foldcase( i = 0; while (STR_CHAR(i) != NUL) { -#ifdef FEAT_MBYTE if (enc_utf8 || (has_mbyte && MB_BYTE2LEN(STR_CHAR(i)) > 1)) { if (enc_utf8) @@ -520,7 +495,6 @@ str_foldcase( i += (*mb_ptr2len)(STR_PTR(i)); } else -#endif { if (buf == NULL) GA_CHAR(i) = TOLOWER_LOC(GA_CHAR(i)); @@ -580,7 +554,6 @@ transchar(int c) return transchar_buf; } -#if defined(FEAT_MBYTE) || defined(PROTO) /* * Like transchar(), but called with a byte instead of a character. Checks * for an illegal UTF-8 byte. @@ -595,7 +568,6 @@ transchar_byte(int c) } return transchar(c); } -#endif /* * Convert non-printable character to two or more printable characters in @@ -632,12 +604,10 @@ transchar_nonprint(char_u *buf, int c) buf[2] = NUL; } -#ifdef FEAT_MBYTE else if (enc_utf8 && c >= 0x80) { transchar_hex(buf, c); } -#endif #ifndef EBCDIC else if (c >= ' ' + 0x80 && c <= '~' + 0x80) /* 0xa0 - 0xfe */ { @@ -675,13 +645,11 @@ transchar_hex(char_u *buf, int c) int i = 0; buf[0] = '<'; -#ifdef FEAT_MBYTE if (c > 255) { buf[++i] = nr2hex((unsigned)c >> 12); buf[++i] = nr2hex((unsigned)c >> 8); } -#endif buf[++i] = nr2hex((unsigned)c >> 4); buf[++i] = nr2hex((unsigned)c); buf[++i] = '>'; @@ -712,10 +680,8 @@ nr2hex(unsigned c) int byte2cells(int b) { -#ifdef FEAT_MBYTE if (enc_utf8 && b >= 0x80) return 0; -#endif return (g_chartab[b] & CT_CELL_MASK); } @@ -729,7 +695,6 @@ char2cells(int c) { if (IS_SPECIAL(c)) return char2cells(K_SECOND(c)) + 2; -#ifdef FEAT_MBYTE if (c >= 0x80) { /* UTF-8: above 0x80 need to check the value */ @@ -744,7 +709,6 @@ char2cells(int c) return 2; } } -#endif return (g_chartab[c & 0xff] & CT_CELL_MASK); } @@ -755,12 +719,10 @@ char2cells(int c) int ptr2cells(char_u *p) { -#ifdef FEAT_MBYTE /* For UTF-8 we need to look at more bytes if the first byte is >= 0x80. */ if (enc_utf8 && *p >= 0x80) return utf_ptr2cells(p); /* For DBCS we can tell the cell count from the first byte. */ -#endif return (g_chartab[*p] & CT_CELL_MASK); } @@ -784,8 +746,6 @@ vim_strnsize(char_u *s, int len) int size = 0; while (*s != NUL && --len >= 0) - { -#ifdef FEAT_MBYTE if (has_mbyte) { int l = (*mb_ptr2len)(s); @@ -795,9 +755,8 @@ vim_strnsize(char_u *s, int len) len -= l - 1; } else -#endif size += byte2cells(*s++); - } + return size; } @@ -907,12 +866,10 @@ vim_iswordc_buf(int c, buf_T *buf) { if (c >= 0x100) { -#ifdef FEAT_MBYTE if (enc_dbcs != 0) return dbcs_class((unsigned)c >> 8, (unsigned)(c & 0xff)) >= 2; if (enc_utf8) return utf_class_buf(c, buf) >= 2; -#endif return FALSE; } return (c > 0 && GET_CHARTAB(buf, c) != 0); @@ -932,10 +889,8 @@ vim_iswordp_buf(char_u *p, buf_T *buf) { int c = *p; -#ifdef FEAT_MBYTE if (has_mbyte && MB_BYTE2LEN(c) > 1) c = (*mb_ptr2char)(p); -#endif return vim_iswordc_buf(c, buf); } @@ -973,10 +928,8 @@ vim_isfilec_or_wc(int c) int vim_isprintc(int c) { -#ifdef FEAT_MBYTE if (enc_utf8 && c >= 0x100) return utf_printable(c); -#endif return (c >= 0x100 || (c > 0 && (g_chartab[c] & CT_PRINT_CHAR))); } @@ -987,12 +940,10 @@ vim_isprintc(int c) int vim_isprintc_strict(int c) { -#ifdef FEAT_MBYTE if (enc_dbcs != 0 && c < 0x100 && MB_BYTE2LEN(c) > 1) return FALSE; if (enc_utf8 && c >= 0x100) return utf_printable(c); -#endif return (c >= 0x100 || (c > 0 && (g_chartab[c] & CT_PRINT_CHAR))); } @@ -1009,10 +960,8 @@ lbr_chartabsize( if (!curwin->w_p_lbr && *p_sbr == NUL && !curwin->w_p_bri) { #endif -#ifdef FEAT_MBYTE if (curwin->w_p_wrap) return win_nolbr_chartabsize(curwin, s, col, NULL); -#endif RET_WIN_BUF_CHARTABSIZE(curwin, curbuf, s, col) #ifdef FEAT_LINEBREAK } @@ -1058,11 +1007,7 @@ win_lbr_chartabsize( colnr_T col_adj = 0; /* col + screen size of tab */ colnr_T colmax; int added; -# ifdef FEAT_MBYTE int mb_added = 0; -# else -# define mb_added 0 -# endif int numberextra; char_u *ps; int tab_corr = (*s == TAB); @@ -1074,10 +1019,8 @@ win_lbr_chartabsize( if (!wp->w_p_lbr && !wp->w_p_bri && *p_sbr == NUL) #endif { -#ifdef FEAT_MBYTE if (wp->w_p_wrap) return win_nolbr_chartabsize(wp, s, col, headp); -#endif RET_WIN_BUF_CHARTABSIZE(wp, wp->w_buffer, s, col) } @@ -1135,14 +1078,12 @@ win_lbr_chartabsize( } } } -# ifdef FEAT_MBYTE else if (has_mbyte && size == 2 && MB_BYTE2LEN(*s) > 1 && wp->w_p_wrap && in_win_border(wp, col)) { ++size; /* Count the ">" in the last column. */ mb_added = 1; } -# endif /* * May have to add something for 'breakindent' and/or 'showbreak' @@ -1210,7 +1151,6 @@ win_lbr_chartabsize( #endif } -#if defined(FEAT_MBYTE) || defined(PROTO) /* * Like win_lbr_chartabsize(), except that we know 'linebreak' is off and * 'wrap' is on. This means we need to check for a double-byte character that @@ -1269,7 +1209,6 @@ in_win_border(win_T *wp, colnr_T vcol) return FALSE; return ((vcol - width1) % width2 == width2 - 1); } -#endif /* FEAT_MBYTE */ /* * Get virtual column number of pos. @@ -1310,11 +1249,9 @@ getvcol( if (*ptr == NUL) pos->col = 0; posptr = ptr + pos->col; -#ifdef FEAT_MBYTE if (has_mbyte) /* always start on the first byte */ posptr -= (*mb_head_off)(line, posptr); -#endif } /* @@ -1329,14 +1266,10 @@ getvcol( #endif ) { -#ifndef FEAT_MBYTE head = 0; -#endif for (;;) { -#ifdef FEAT_MBYTE head = 0; -#endif c = *ptr; /* make sure we don't go past the end of the line */ if (c == NUL) @@ -1353,7 +1286,6 @@ getvcol( #endif else { -#ifdef FEAT_MBYTE if (has_mbyte) { /* For utf-8, if the byte is >= 0x80, need to look at @@ -1374,7 +1306,6 @@ getvcol( } } else -#endif incr = g_chartab[c] & CT_CELL_MASK; } @@ -1460,9 +1391,7 @@ getvvcol( colnr_T col; colnr_T coladd; colnr_T endadd; -# ifdef FEAT_MBYTE char_u *ptr; -# endif if (virtual_active()) { @@ -1471,7 +1400,6 @@ getvvcol( coladd = pos->coladd; endadd = 0; -# ifdef FEAT_MBYTE /* Cannot put the cursor on part of a wide character. */ ptr = ml_get_buf(wp->w_buffer, pos->lnum, FALSE); if (pos->col < (colnr_T)STRLEN(ptr)) @@ -1487,7 +1415,6 @@ getvvcol( coladd = 0; } } -# endif col += coladd; if (start != NULL) *start = col; @@ -1684,7 +1611,6 @@ vim_isbdigit(int c) return (c == '0' || c == '1'); } -#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 @@ -1797,7 +1723,6 @@ vim_tolower(int c) return TOLOWER_ASC(c); return TOLOWER_LOC(c); } -#endif /* * skiptowhite: skip over text until ' ' or '\t' or NUL. @@ -2077,9 +2002,7 @@ rem_backslash(char_u *str) { #ifdef BACKSLASH_IN_FILENAME return (str[0] == '\\' -# ifdef FEAT_MBYTE && str[1] < 0x80 -# endif && (str[1] == ' ' || (str[1] != NUL && str[1] != '*' |