diff options
author | Bram Moolenaar <Bram@vim.org> | 2013-11-02 23:29:26 +0100 |
---|---|---|
committer | Bram Moolenaar <Bram@vim.org> | 2013-11-02 23:29:26 +0100 |
commit | 0ffbbf9ea871dd64c2be933d6718f0b34fe960c4 (patch) | |
tree | cc8d2df9e03eca6b8a9c20f4c6f821c4f32525b2 /src | |
parent | 4cc95d1495706593d30ce2fae3fc592a2ffdaab8 (diff) | |
download | vim-0ffbbf9ea871dd64c2be933d6718f0b34fe960c4.zip |
updated for version 7.4.057
Problem: byteidx() does not work for composing characters.
Solution: Add byteidxcomp().
Diffstat (limited to 'src')
-rw-r--r-- | src/eval.c | 36 | ||||
-rw-r--r-- | src/testdir/test69.in | 16 | ||||
-rw-r--r-- | src/testdir/test69.ok | 8 | ||||
-rw-r--r-- | src/version.c | 2 |
4 files changed, 57 insertions, 5 deletions
diff --git a/src/eval.c b/src/eval.c index c3ac4673d..0468203cc 100644 --- a/src/eval.c +++ b/src/eval.c @@ -474,7 +474,9 @@ static void f_bufname __ARGS((typval_T *argvars, typval_T *rettv)); static void f_bufnr __ARGS((typval_T *argvars, typval_T *rettv)); static void f_bufwinnr __ARGS((typval_T *argvars, typval_T *rettv)); static void f_byte2line __ARGS((typval_T *argvars, typval_T *rettv)); +static void byteidx __ARGS((typval_T *argvars, typval_T *rettv, int comp)); static void f_byteidx __ARGS((typval_T *argvars, typval_T *rettv)); +static void f_byteidxcomp __ARGS((typval_T *argvars, typval_T *rettv)); static void f_call __ARGS((typval_T *argvars, typval_T *rettv)); #ifdef FEAT_FLOAT static void f_ceil __ARGS((typval_T *argvars, typval_T *rettv)); @@ -7861,6 +7863,7 @@ static struct fst {"bufwinnr", 1, 1, f_bufwinnr}, {"byte2line", 1, 1, f_byte2line}, {"byteidx", 2, 2, f_byteidx}, + {"byteidxcomp", 2, 2, f_byteidxcomp}, {"call", 2, 3, f_call}, #ifdef FEAT_FLOAT {"ceil", 1, 1, f_ceil}, @@ -9177,13 +9180,11 @@ f_byte2line(argvars, rettv) #endif } -/* - * "byteidx()" function - */ static void -f_byteidx(argvars, rettv) +byteidx(argvars, rettv, comp) typval_T *argvars; typval_T *rettv; + int comp; { #ifdef FEAT_MBYTE char_u *t; @@ -9203,7 +9204,10 @@ f_byteidx(argvars, rettv) { if (*t == NUL) /* EOL reached */ return; - t += (*mb_ptr2len)(t); + if (enc_utf8 && comp) + t += utf_ptr2len(t); + else + t += (*mb_ptr2len)(t); } rettv->vval.v_number = (varnumber_T)(t - str); #else @@ -9212,6 +9216,28 @@ f_byteidx(argvars, rettv) #endif } +/* + * "byteidx()" function + */ + static void +f_byteidx(argvars, rettv) + typval_T *argvars; + typval_T *rettv; +{ + byteidx(argvars, rettv, FALSE); +} + +/* + * "byteidxcomp()" function + */ + static void +f_byteidxcomp(argvars, rettv) + typval_T *argvars; + typval_T *rettv; +{ + byteidx(argvars, rettv, TRUE); +} + int func_call(name, args, selfdict, rettv) char_u *name; diff --git a/src/testdir/test69.in b/src/testdir/test69.in index 9558cb817..f18ee3790 100644 --- a/src/testdir/test69.in +++ b/src/testdir/test69.in @@ -1,6 +1,7 @@ Test for multi-byte text formatting. Also test, that 'mps' with multibyte chars works. And test "ra" on multi-byte characters. +Also test byteidx() and byteidxcomp() STARTTEST :so mbyte.vim @@ -154,6 +155,21 @@ ra test aab STARTTEST +:let a = '.é.' " one char of two bytes +:let b = '.é.' " normal e with composing char +/^byteidx +:put =string([byteidx(a, 0), byteidx(a, 1), byteidx(a, 2), byteidx(a, 3), byteidx(a, 4)]) +:put =string([byteidx(b, 0), byteidx(b, 1), byteidx(b, 2), byteidx(b, 3), byteidx(b, 4)]) +/^byteidxcomp +:put =string([byteidxcomp(a, 0), byteidxcomp(a, 1), byteidxcomp(a, 2), byteidxcomp(a, 3), byteidxcomp(a, 4)]) +:let b = '.é.' +:put =string([byteidxcomp(b, 0), byteidxcomp(b, 1), byteidxcomp(b, 2), byteidxcomp(b, 3), byteidxcomp(b, 4), byteidxcomp(b, 5)]) +ENDTEST + +byteidx +byteidxcomp + +STARTTEST :g/^STARTTEST/.,/^ENDTEST/d :1;/^Results/,$wq! test.out ENDTEST diff --git a/src/testdir/test69.ok b/src/testdir/test69.ok index f742ee174..1ff82f26b 100644 --- a/src/testdir/test69.ok +++ b/src/testdir/test69.ok @@ -149,3 +149,11 @@ ra test aaaa aaa + +byteidx +[0, 1, 3, 4, -1] +[0, 1, 4, 5, -1] +byteidxcomp +[0, 1, 3, 4, -1] +[0, 1, 2, 4, 5, -1] + diff --git a/src/version.c b/src/version.c index c68250893..d76370f60 100644 --- a/src/version.c +++ b/src/version.c @@ -739,6 +739,8 @@ static char *(features[]) = static int included_patches[] = { /* Add new patch number below this line */ /**/ + 57, +/**/ 56, /**/ 55, |