ZyX <[email protected]> wrote:
> # HG changeset patch
> # User ZyX <[email protected]>
> # Date 1347557709 -14400
> # Node ID 4eaeb62c1871c95e59c3f232f98e6f664fa8435c
> # Parent 35fbcce08538a7540ab0e3a3c64305951ebbe589
> Use empty() for testing string emptiness
>
> diff -r 35fbcce08538 -r 4eaeb62c1871 runtime/doc/eval.txt
> --- a/runtime/doc/eval.txt Thu Sep 13 19:45:10 2012 +0400
> +++ b/runtime/doc/eval.txt Thu Sep 13 21:34:44 2012 +0400
> @@ -91,8 +91,8 @@
> Note that in the command >
> :if "foo"
> "foo" is converted to 0, which means FALSE. To test for a non-empty string,
> -use strlen(): >
> - :if strlen("foo")
> +use empty(): >
> + :if !empty("foo")
> < *E745* *E728* *E703* *E729* *E730* *E731*
> List, Dictionary and Funcref types are not automatically converted.
Good catch. There are several scripts that could benefit from using:
- empty(x) instead of strlen(x) == 0 or len(x) == 0
- !empty(x) instead of strlen(x) > 0 or len(x) > 0
I found those:
$ find . -name '*.vim' -print | \
xargs egrep -n '\<(strlen|len)\([^)]*\)\s*\S*\s*0\>'
./runtime/indent/java.vim:96: if strlen(cont_kw) > 0
./runtime/menu.vim:364: while strlen(s:n) > 0
./runtime/menu.vim:572:while strlen(s:n) > 0
./runtime/menu.vim:907: if len(s:suglist) > 0
./runtime/menu.vim:1037: if strlen(v:this_session) > 0
./runtime/menu.vim:1047: if strlen(v:this_session) == 0
./runtime/syntax/tex.vim:1089: if strlen(a:{i}) == 0 || a:{i} ==
' ' || a:{i} == '?'
./runtime/syntax/2html.vim:1015: if strlen(s:expandedtab) > 0
./runtime/ftplugin/pdf.vim:30:nnoremap <silent><buffer> <C-T> :if
len(b:pdf_tagstack) > 0 <Bar> call setpos('.',remove(b:pdf_tagstack,
-1)) <Bar> else <Bar> exe "norm! \<Lt>C-T>" <Bar> endif<CR>
./runtime/ftplugin/spec.vim:24: if strlen(a:format) == 0
./runtime/ftplugin/cucumber.vim:30: if len(steps) == 0 || len(steps) < a:count
./runtime/macros/justify.vim:249: if strlen(indent_orig) > 0
./runtime/autoload/javascriptcomplete.vim:35: if len(b:js_extfiles) > 0
./runtime/autoload/javascriptcomplete.vim:398: if len(object) > 0
./runtime/autoload/javascriptcomplete.vim:415: if
len(dext_line) > 0
./runtime/autoload/javascriptcomplete.vim:422:
if len(dext_line) > 0
./runtime/autoload/xmlcomplete.vim:120: if len(b:compl_context) == 0
&& !exists("b:entitiescompl")
./runtime/autoload/xmlcomplete.vim:151: if len(entdecl) > 0
./runtime/autoload/xmlcomplete.vim:219: if len(values) == 0
./runtime/autoload/xmlcomplete.vim:282: if tag !~
'^[?!]' &&
len(g:xmldata{'_'.g:xmldata_connection[b:xml_namespace]}[tag][1][item])
> 0 && g:xmldata{'_'.g:xmldata_connection[b:xml_namespace]}[tag][1][item][0]
=~ '^\(BOOL\|'.item.'\)$'
./runtime/autoload/xmlcomplete.vim:292: if tag !~
'^[?!]' &&
len(g:xmldata{'_'.g:xmldata_connection[b:xml_namespace]}[tag][1][item])
> 0 && g:xmldata{'_'.g:xmldata_connection[b:xml_namespace]}[tag][1][item][0]
=~ '^\(BOOL\|'.item.'\)$'
./runtime/autoload/htmlcomplete.vim:146: if len(b:compl_context)
== 0
&& !exists("b:entitiescompl")
./runtime/autoload/htmlcomplete.vim:276:
if len(secimport) > 0
./runtime/autoload/htmlcomplete.vim:480: if len(values)
== 0
./runtime/autoload/htmlcomplete.vim:547: if
len(b:html_omni[tag][1][item]) > 0 && b:html_omni[tag][1][item][0] =~
'^\(BOOL\|'.item.'\)$'
./runtime/autoload/htmlcomplete.vim:559: if
len(b:html_omni[tag][1][item]) > 0 && b:html_omni[tag][1][item][0] =~
'^\(BOOL\|'.item.'\)$'
./runtime/autoload/phpcomplete.vim:94: if len(qflist) > 0
./runtime/autoload/phpcomplete.vim:275: if len(qflist) > 0
./runtime/autoload/phpcomplete.vim:314: if len(qflist) > 0
./runtime/autoload/phpcomplete.vim:410: if len(qflist) > 0
./runtime/autoload/phpcomplete.vim:481: if len(qflist) > 0
./runtime/autoload/phpcomplete.vim:518: if len(qflist) > 0
./runtime/autoload/phpcomplete.vim:596: if len(qflist) == 0
./runtime/autoload/phpcomplete.vim:630: if len(qflist) > 0
./runtime/autoload/csscomplete.vim:86:if len(borders) == 0 ||
borders[max(keys(borders))] =~
'^\%(openbrace\|semicolon\|opencomm\|closecomm\|style\)$'
./runtime/autoload/pythoncomplete.vim:80: elseif
strlen(cword) > 0 || idx == 0
./runtime/autoload/pythoncomplete.vim:191: if len(arg_text) == 0:
./runtime/autoload/pythoncomplete.vim:205: if len(arg_text) ==
0: arg_text = ')'
./runtime/autoload/pythoncomplete.vim:217: if len(stmt) > 0
and stmt[-1] == '(':
./runtime/autoload/pythoncomplete.vim:316: if len(self.docstr)
> 0: str += '"""'+self.docstr+'"""\n'
./runtime/autoload/pythoncomplete.vim:353: if len(self.supers)
> 0: str += '(%s)' % ','.join(self.supers)
./runtime/autoload/pythoncomplete.vim:355: if len(self.docstr)
> 0: str += self.childindent()+'"""'+self.docstr+'"""\n'
./runtime/autoload/pythoncomplete.vim:356: if len(self.subscopes) > 0:
./runtime/autoload/pythoncomplete.vim:372: if len(self.docstr)
> 0: str += self.childindent()+'"""'+self.docstr+'"""\n'
./runtime/autoload/pythoncomplete.vim:514: if
len(p) == 0: continue
./runtime/autoload/pythoncomplete.vim:577: if
len(alias) > 0: loc += " as %s" % alias
./runtime/autoload/pythoncomplete.vim:588: if
len(alias) > 0: loc += " as %s" % alias
./runtime/autoload/python3complete.vim:82: elseif
strlen(cword) > 0 || idx == 0
./runtime/autoload/python3complete.vim:173: if len(arg_text) == 0:
./runtime/autoload/python3complete.vim:187: if len(arg_text) ==
0: arg_text = ')'
./runtime/autoload/python3complete.vim:199: if len(stmt) >
0 and stmt[-1] == '(':
./runtime/autoload/python3complete.vim:298: if len(self.docstr)
> 0: str += '"""'+self.docstr+'"""\n'
./runtime/autoload/python3complete.vim:335: if len(self.supers)
> 0: str += '(%s)' % ','.join(self.supers)
./runtime/autoload/python3complete.vim:337: if len(self.docstr)
> 0: str += self.childindent()+'"""'+self.docstr+'"""\n'
./runtime/autoload/python3complete.vim:338: if len(self.subscopes) > 0:
./runtime/autoload/python3complete.vim:354: if len(self.docstr)
> 0: str += self.childindent()+'"""'+self.docstr+'"""\n'
./runtime/autoload/python3complete.vim:496: if
len(p) == 0: continue
./runtime/autoload/python3complete.vim:559: if
len(alias) > 0: loc += " as %s" % alias
./runtime/autoload/python3complete.vim:570: if
len(alias) > 0: loc += " as %s" % alias
./runtime/autoload/ccomplete.vim:154: if len(res) > 0
./runtime/autoload/ccomplete.vim:183: if len(res) == 0
./runtime/autoload/ccomplete.vim:211: if len(res) == 0 &&
searchdecl(items[0], 1) == 0
./runtime/autoload/ccomplete.vim:468: if len(res) > 0
./runtime/autoload/ccomplete.vim:506: if len(qflist) > 0 ||
match(typename, "::") < 0
./runtime/autoload/ccomplete.vim:542: if len(matches) > 0
./runtime/autoload/ccomplete.vim:602: if a:all == 0 && len(res) > 0
./runtime/autoload/tohtml.vim:535: if len(style) > 0
./runtime/autoload/spellfile.vim:43: if len(dirlist) == 0
./runtime/autoload/spellfile.vim:55: if len(dirlist) == 0
./runtime/spell/check_locales.vim:14:if len(not_supported) > 0
-- Dominique
--
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php