Is this a mistake in evaluating a Vim string expression?

I was debugging a problem with a plugin running on Vim73 on Arch Linux, and it seems to be due to an error in evaluating string expressions.

In this installation of Vim, the expression 'xxx' > ''evaluates to 0 (false), and in all the other Vims I've seen, the expression evaluates (as it should) to 1 (true).

Does anyone know an explanation for this? Arch Linux Vim has not been compiled with many built-in functions, but can there be any feature that changes the evaluation of string expressions?

Is there any Vim parameter (encoding?) That could change the result of string comparison? It was a simple installation of Vim (nothing remarkable in vimrc), giving a bad result, did not see that the parameter could be changed, even if there are some settings that affect this result.

Thanks for any info.

UPDATE: It turns out that this problem was caused by an error in the string comparison function in the latest version of 64-bit Vim when the Vim ignorecase flag was set. A non-empty string should be larger than the empty string, regardless of whether the case was ignored, but Vim returned false. The bug report is here: http://groups.google.com/group/vim_dev/browse_thread/thread/313bc7c46a19cd40

Workarounds would be: (1) use a comparison operator that forcibly compares the comparison, for example, mystring_var ># ''or (2) use !empty(mystring_var).

+3
source share
1 answer

To find out the answer to this question, you should take a look at the documentation. Here is a section quote *41.4* Conditionals:

Boolean operators work for both numbers and strings. When comparing two lines, the mathematical difference is used. This compares byte values, which may be incorrect for some languages.

When comparing a string with a number, the string is first converted to a number. This is a little tricky because when the string does not look like a number, the number is zero. Example:

:if 0 == "one"
:  echo "yes"
:endif

It will sound “yes,” because “one” is not like a number, and it converts to zero.

, vim , , . , *strlen()*.

+1

All Articles