diff options
author | Tom Ryder <tom@sanctum.geek.nz> | 2019-06-06 22:32:17 +1200 |
---|---|---|
committer | Tom Ryder <tom@sanctum.geek.nz> | 2019-06-06 22:32:17 +1200 |
commit | b18a4317213c1d92d9b6f89dcf5572037b8882f8 (patch) | |
tree | 1672404172bad29634bdd6ad43e4b7d6acc80b63 | |
parent | Simplify version comparison (diff) | |
download | dotfiles-b18a4317213c1d92d9b6f89dcf5572037b8882f8.tar.gz dotfiles-b18a4317213c1d92d9b6f89dcf5572037b8882f8.zip |
Stop wasting version pattern match, use submatches
-rw-r--r-- | vim/autoload/vimrc.vim | 16 |
1 files changed, 10 insertions, 6 deletions
diff --git a/vim/autoload/vimrc.vim b/vim/autoload/vimrc.vim index 92f6d27a..94922e93 100644 --- a/vim/autoload/vimrc.vim +++ b/vim/autoload/vimrc.vim @@ -30,16 +30,20 @@ endfunction " takes strings like 7.3.251 function! vimrc#Version(string) abort - " Throw toys if the string doesn't match the expected format - if a:string !~# '^\d\+\.\d\+\.\d\+$' + " Test the version string and get submatches for each part + let match = matchlist(a:string, '^\(\d\+\)\.\(\d\+\)\.\(\d\+\)$') + + " Throw toys if the string didn't match the expected format + if !len(match) echoerr 'Invalid version string: '.a:string + return endif - " Split version string into major, minor, and patch level integers - let [major, minor, patch] = split(a:string, '\.') + " Get the major, minor, and patch numbers from the submatches + let [major, minor, patch] = match[1:3] - " Create a string like 801 from a version number 8.1 to compare it to - " the v:version integer + " Create a string like 801 from a version number 8.1 to compare it to the + " v:version integer let ver = major * 100 + minor " Compare versions |