0
0
mirror of https://github.com/vim/vim.git synced 2025-09-23 03:43:49 -04:00

Added strwidth() and strchars() functions.

This commit is contained in:
Bram Moolenaar
2010-07-18 15:31:08 +02:00
parent 9855d6b361
commit 72597a57b5
10 changed files with 99 additions and 42 deletions

View File

@@ -1578,6 +1578,23 @@ dbcs_char2cells(c)
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(p, len)
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].
@@ -4364,12 +4381,12 @@ im_commit_cb(GtkIMContext *context UNUSED,
const gchar *str,
gpointer data UNUSED)
{
int slen = (int)STRLEN(str);
int add_to_input = TRUE;
int clen;
int len = slen;
int commit_with_preedit = TRUE;
char_u *im_str, *p;
int slen = (int)STRLEN(str);
int add_to_input = TRUE;
int clen;
int len = slen;
int commit_with_preedit = TRUE;
char_u *im_str;
#ifdef XIM_DEBUG
xim_log("im_commit_cb(): %s\n", str);
@@ -4402,9 +4419,9 @@ im_commit_cb(GtkIMContext *context UNUSED,
}
else
im_str = (char_u *)str;
clen = 0;
for (p = im_str; p < im_str + len; p += (*mb_ptr2len)(p))
clen += (*mb_ptr2cells)(p);
clen = mb_string2cells(im_str, len);
if (input_conv.vc_type != CONV_NONE)
vim_free(im_str);
preedit_start_col += clen;