mirror of
https://github.com/vim/vim.git
synced 2025-09-25 03:54:15 -04:00
patch 8.0.0794: checking translations fails with multiple NL
Problem: The script to check translations fails if there is more than one NL in one line. Solution: Count the number of NL characters. Make count() accept a string.
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
*eval.txt* For Vim version 8.0. Last change: 2017 Jul 22
|
*eval.txt* For Vim version 8.0. Last change: 2017 Jul 28
|
||||||
|
|
||||||
|
|
||||||
VIM REFERENCE MANUAL by Bram Moolenaar
|
VIM REFERENCE MANUAL by Bram Moolenaar
|
||||||
@@ -3255,11 +3255,16 @@ cosh({expr}) *cosh()*
|
|||||||
|
|
||||||
count({comp}, {expr} [, {ic} [, {start}]]) *count()*
|
count({comp}, {expr} [, {ic} [, {start}]]) *count()*
|
||||||
Return the number of times an item with value {expr} appears
|
Return the number of times an item with value {expr} appears
|
||||||
in |List| or |Dictionary| {comp}.
|
in |String|, |List| or |Dictionary| {comp}.
|
||||||
|
|
||||||
If {start} is given then start with the item with this index.
|
If {start} is given then start with the item with this index.
|
||||||
{start} can only be used with a |List|.
|
{start} can only be used with a |List|.
|
||||||
|
|
||||||
When {ic} is given and it's |TRUE| then case is ignored.
|
When {ic} is given and it's |TRUE| then case is ignored.
|
||||||
|
|
||||||
|
When {comp} is a string then the number of not overlapping
|
||||||
|
occurences of {expr} is returned.
|
||||||
|
|
||||||
|
|
||||||
*cscope_connection()*
|
*cscope_connection()*
|
||||||
cscope_connection([{num} , {dbpath} [, {prepend}]])
|
cscope_connection([{num} , {dbpath} [, {prepend}]])
|
||||||
|
@@ -2314,8 +2314,45 @@ f_count(typval_T *argvars, typval_T *rettv)
|
|||||||
{
|
{
|
||||||
long n = 0;
|
long n = 0;
|
||||||
int ic = FALSE;
|
int ic = FALSE;
|
||||||
|
int error = FALSE;
|
||||||
|
|
||||||
if (argvars[0].v_type == VAR_LIST)
|
if (argvars[2].v_type != VAR_UNKNOWN)
|
||||||
|
ic = (int)get_tv_number_chk(&argvars[2], &error);
|
||||||
|
|
||||||
|
if (argvars[0].v_type == VAR_STRING)
|
||||||
|
{
|
||||||
|
char_u *expr = get_tv_string_chk(&argvars[1]);
|
||||||
|
char_u *p = argvars[0].vval.v_string;
|
||||||
|
char_u *next;
|
||||||
|
|
||||||
|
if (!error && expr != NULL && p != NULL)
|
||||||
|
{
|
||||||
|
if (ic)
|
||||||
|
{
|
||||||
|
size_t len = STRLEN(expr);
|
||||||
|
|
||||||
|
while (*p != NUL)
|
||||||
|
{
|
||||||
|
if (MB_STRNICMP(p, expr, len) == 0)
|
||||||
|
{
|
||||||
|
++n;
|
||||||
|
p += len;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
MB_PTR_ADV(p);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
while ((next = (char_u *)strstr((char *)p, (char *)expr))
|
||||||
|
!= NULL)
|
||||||
|
{
|
||||||
|
++n;
|
||||||
|
p = next + STRLEN(expr);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
else if (argvars[0].v_type == VAR_LIST)
|
||||||
{
|
{
|
||||||
listitem_T *li;
|
listitem_T *li;
|
||||||
list_T *l;
|
list_T *l;
|
||||||
@@ -2326,9 +2363,6 @@ f_count(typval_T *argvars, typval_T *rettv)
|
|||||||
li = l->lv_first;
|
li = l->lv_first;
|
||||||
if (argvars[2].v_type != VAR_UNKNOWN)
|
if (argvars[2].v_type != VAR_UNKNOWN)
|
||||||
{
|
{
|
||||||
int error = FALSE;
|
|
||||||
|
|
||||||
ic = (int)get_tv_number_chk(&argvars[2], &error);
|
|
||||||
if (argvars[3].v_type != VAR_UNKNOWN)
|
if (argvars[3].v_type != VAR_UNKNOWN)
|
||||||
{
|
{
|
||||||
idx = (long)get_tv_number_chk(&argvars[3], &error);
|
idx = (long)get_tv_number_chk(&argvars[3], &error);
|
||||||
@@ -2356,11 +2390,8 @@ f_count(typval_T *argvars, typval_T *rettv)
|
|||||||
|
|
||||||
if ((d = argvars[0].vval.v_dict) != NULL)
|
if ((d = argvars[0].vval.v_dict) != NULL)
|
||||||
{
|
{
|
||||||
int error = FALSE;
|
|
||||||
|
|
||||||
if (argvars[2].v_type != VAR_UNKNOWN)
|
if (argvars[2].v_type != VAR_UNKNOWN)
|
||||||
{
|
{
|
||||||
ic = (int)get_tv_number_chk(&argvars[2], &error);
|
|
||||||
if (argvars[3].v_type != VAR_UNKNOWN)
|
if (argvars[3].v_type != VAR_UNKNOWN)
|
||||||
EMSG(_(e_invarg));
|
EMSG(_(e_invarg));
|
||||||
}
|
}
|
||||||
|
@@ -114,14 +114,12 @@ endif
|
|||||||
func! CountNl(first, last)
|
func! CountNl(first, last)
|
||||||
let nl = 0
|
let nl = 0
|
||||||
for lnum in range(a:first, a:last)
|
for lnum in range(a:first, a:last)
|
||||||
if getline(lnum) =~ '\\n'
|
let nl += count(getline(lnum), "\n")
|
||||||
let nl += 1
|
|
||||||
endif
|
|
||||||
endfor
|
endfor
|
||||||
return nl
|
return nl
|
||||||
endfunc
|
endfunc
|
||||||
|
|
||||||
" Check that the \n at the end of the msid line is also present in the msgstr
|
" Check that the \n at the end of the msgid line is also present in the msgstr
|
||||||
" line. Skip over the header.
|
" line. Skip over the header.
|
||||||
/^"MIME-Version:
|
/^"MIME-Version:
|
||||||
while 1
|
while 1
|
||||||
@@ -138,7 +136,7 @@ while 1
|
|||||||
let transcount = CountNl(strlnum, end - 1)
|
let transcount = CountNl(strlnum, end - 1)
|
||||||
" Allow for a few more or less line breaks when there are 2 or more
|
" Allow for a few more or less line breaks when there are 2 or more
|
||||||
if origcount != transcount && (origcount <= 2 || transcount <= 2)
|
if origcount != transcount && (origcount <= 2 || transcount <= 2)
|
||||||
echomsg 'Mismatching "\\n" in line ' . line('.')
|
echomsg 'Mismatching "\n" in line ' . line('.')
|
||||||
if error == 0
|
if error == 0
|
||||||
let error = lnum
|
let error = lnum
|
||||||
endif
|
endif
|
||||||
|
@@ -635,7 +635,13 @@ func Test_count()
|
|||||||
call assert_equal(0, count(d, 'c', 1))
|
call assert_equal(0, count(d, 'c', 1))
|
||||||
|
|
||||||
call assert_fails('call count(d, "a", 0, 1)', 'E474:')
|
call assert_fails('call count(d, "a", 0, 1)', 'E474:')
|
||||||
call assert_fails('call count("a", "a")', 'E712:')
|
|
||||||
|
call assert_equal(0, count("foo", "bar"))
|
||||||
|
call assert_equal(1, count("foo", "oo"))
|
||||||
|
call assert_equal(2, count("foo", "o"))
|
||||||
|
call assert_equal(0, count("foo", "O"))
|
||||||
|
call assert_equal(2, count("foo", "O", 1))
|
||||||
|
call assert_equal(2, count("fooooo", "oo"))
|
||||||
endfunc
|
endfunc
|
||||||
|
|
||||||
func Test_changenr()
|
func Test_changenr()
|
||||||
|
@@ -769,6 +769,8 @@ static char *(features[]) =
|
|||||||
|
|
||||||
static int included_patches[] =
|
static int included_patches[] =
|
||||||
{ /* Add new patch number below this line */
|
{ /* Add new patch number below this line */
|
||||||
|
/**/
|
||||||
|
794,
|
||||||
/**/
|
/**/
|
||||||
793,
|
793,
|
||||||
/**/
|
/**/
|
||||||
|
Reference in New Issue
Block a user