Permalink
Browse files

Updates required by vim-notes 0.22

  • Loading branch information...
1 parent c0e7620 commit 19803c121d74eaafc8b0eeddf5a5da8749d66608 @xolox committed Jun 23, 2013
Showing with 181 additions and 26 deletions.
  1. +37 −6 README.md
  2. +1 −0 addon-info.json
  3. +54 −8 autoload/xolox/misc/str.vim
  4. +35 −1 autoload/xolox/misc/tests.vim
  5. +54 −11 doc/misc.txt
View
@@ -37,8 +37,8 @@ from the source code of the miscellaneous scripts using the Python module
<!-- Start of generated documentation -->
-The documentation of the 72 functions below was extracted from
-16 Vim scripts on June 22, 2013 at 02:08.
+The documentation of the 79 functions below was extracted from
+16 Vim scripts on June 23, 2013 at 23:13.
### Handling of special buffers
@@ -423,18 +423,33 @@ Create a temporary directory and return the pathname of the directory.
### String handling
+#### The `xolox#misc#str#slug()` function
+
+Convert a string to a "slug" - something that can be safely used in
+filenames and URLs without worrying about quoting/escaping of special
+characters.
+
#### The `xolox#misc#str#ucfirst()` function
-Uppercase the first character in a string.
+Uppercase the first character in a string (the first argument).
#### The `xolox#misc#str#compact()` function
-Compact whitespace in the string given as the first argument.
+Compact whitespace in a string (the first argument).
#### The `xolox#misc#str#trim()` function
-Trim all whitespace from the start and end of the string given as the
-first argument.
+Trim all whitespace from the start and end of a string (the first
+argument).
+
+#### The `xolox#misc#str#indent()` function
+
+Indent all lines in a multi-line string (the first argument) with a
+specific number of *space characters* (the second argument, an integer).
+
+#### The `xolox#misc#str#dedent()` function
+
+Remove common whitespace from a multi line string.
### Test runner & infrastructure for Vim plug-ins
@@ -570,6 +585,22 @@ Test synchronous command execution without raising of errors with
Test basic functionality of asynchronous command execution with
`xolox#misc#os#exec()`.
+#### The `xolox#misc#tests#string_case_transformation()` function
+
+Test string case transformation with `xolox#misc#str#ucfirst()`.
+
+#### The `xolox#misc#tests#string_whitespace_compaction()` function
+
+Test compaction of whitespace in strings with `xolox#misc#str#compact()`.
+
+#### The `xolox#misc#tests#string_whitespace_trimming()` function
+
+Test trimming of whitespace in strings with `xolox#misc#str#trim()`.
+
+#### The `xolox#misc#tests#multiline_string_dedent()` function
+
+Test dedenting of multi-line strings with `xolox#misc#str#dedent()`.
+
#### The `xolox#misc#tests#version_string_parsing()` function
Test parsing of version strings with `xolox#misc#version#parse()`.
View
@@ -0,0 +1 @@
+{"vim_script_nr": 4597, "dependencies": {}, "homepage": "http://peterodding.com/code/vim/misc", "name": "vim-misc"}
@@ -1,23 +1,69 @@
" String handling.
"
" Author: Peter Odding <peter@peterodding.com>
-" Last Change: June 3, 2013
+" Last Change: June 23, 2013
" URL: http://peterodding.com/code/vim/misc/
-function! xolox#misc#str#ucfirst(s)
- " Uppercase the first character in a string.
+function! xolox#misc#str#slug(s) " {{{1
+ " Convert a string to a "slug" - something that can be safely used in
+ " filenames and URLs without worrying about quoting/escaping of special
+ " characters.
+ return join(split(tolower(a:s), '\W\+'), '-')
+endfunction
+
+function! xolox#misc#str#ucfirst(s) " {{{1
+ " Uppercase the first character in a string (the first argument).
return substitute(a:s, '^.', '\U\0', '')
endfunction
-function! xolox#misc#str#compact(s)
- " Compact whitespace in the string given as the first argument.
+function! xolox#misc#str#compact(s) " {{{1
+ " Compact whitespace in a string (the first argument).
return join(split(a:s), " ")
endfunction
-function! xolox#misc#str#trim(s)
- " Trim all whitespace from the start and end of the string given as the
- " first argument.
+function! xolox#misc#str#trim(s) " {{{1
+ " Trim all whitespace from the start and end of a string (the first
+ " argument).
return substitute(a:s, '^\_s*\(.\{-}\)\_s*$', '\1', '')
endfunction
+function! xolox#misc#str#indent(text, num_spaces) " {{{1
+ " Indent all lines in a multi-line string (the first argument) with a
+ " specific number of *space characters* (the second argument, an integer).
+ let lines = split(a:text, "\n")
+ let indent = repeat(' ', a:num_spaces)
+ let [idx, limit] = [0, len(lines)]
+ while idx < limit
+ if lines[idx] =~ '\S'
+ let lines[idx] = indent . lines[idx]
+ endif
+ let idx += 1
+ endwhile
+ return join(lines, "\n")
+endfunction
+
+function! xolox#misc#str#dedent(text) " {{{1
+ " Remove common whitespace from a multi line string.
+ let lines = split(a:text, "\n")
+ " First we need to determine the common indentation of all non-empty lines.
+ for line in lines
+ if line =~ '\S'
+ let indent = matchstr(line, '^\s*')
+ if !exists('common_indent')
+ let common_indent = indent
+ elseif len(indent) < len(common_indent)
+ let common_indent = indent
+ endif
+ endif
+ endfor
+ " Now we will strip the common indentation.
+ let [idx, limit] = [0, len(lines)]
+ let pattern = '^' . common_indent
+ while idx < limit
+ let lines[idx] = substitute(lines[idx], pattern, '', '')
+ let idx += 1
+ endwhile
+ return join(lines, "\n")
+endfunction
+
" vim: ts=2 sw=2 et
@@ -1,7 +1,7 @@
" Tests for the miscellaneous Vim scripts.
"
" Author: Peter Odding <peter@peterodding.com>
-" Last Change: June 22, 2013
+" Last Change: June 23, 2013
" URL: http://peterodding.com/code/vim/misc/
"
" The Vim auto-load script `autoload/xolox/misc/tests.vim` contains the
@@ -17,6 +17,7 @@ function! xolox#misc#tests#run() " {{{1
call s:test_list_handling()
call s:test_option_handling()
call s:test_command_execution()
+ call s:test_string_handling()
call s:test_version_handling()
" Report a short summary to the user.
call xolox#misc#test#summarize()
@@ -230,6 +231,39 @@ function! xolox#misc#tests#asynchronous_command_execution() " {{{2
call xolox#misc#test#assert_equals([expected_value], readfile(tempfile))
endfunction
+" Tests for autoload/xolox/misc/str.vim {{{1
+
+function! s:test_string_handling()
+ call xolox#misc#test#wrap('xolox#misc#tests#string_case_transformation')
+ call xolox#misc#test#wrap('xolox#misc#tests#string_whitespace_compaction')
+ call xolox#misc#test#wrap('xolox#misc#tests#string_whitespace_trimming')
+ call xolox#misc#test#wrap('xolox#misc#tests#multiline_string_dedent')
+endfunction
+
+function! xolox#misc#tests#string_case_transformation()
+ " Test string case transformation with `xolox#misc#str#ucfirst()`.
+ call xolox#misc#test#assert_equals('Foo', xolox#misc#str#ucfirst('foo'))
+ call xolox#misc#test#assert_equals('BAR', xolox#misc#str#ucfirst('BAR'))
+endfunction
+
+function! xolox#misc#tests#string_whitespace_compaction()
+ " Test compaction of whitespace in strings with `xolox#misc#str#compact()`.
+ call xolox#misc#test#assert_equals('foo bar baz', xolox#misc#str#compact(' foo bar baz '))
+ call xolox#misc#test#assert_equals('test', xolox#misc#str#compact("\ntest "))
+endfunction
+
+function! xolox#misc#tests#string_whitespace_trimming()
+ " Test trimming of whitespace in strings with `xolox#misc#str#trim()`.
+ call xolox#misc#test#assert_equals('foo bar baz', xolox#misc#str#trim("\nfoo bar baz "))
+endfunction
+
+function! xolox#misc#tests#multiline_string_dedent()
+ " Test dedenting of multi-line strings with `xolox#misc#str#dedent()`.
+ call xolox#misc#test#assert_equals('test', xolox#misc#str#dedent(' test'))
+ call xolox#misc#test#assert_equals("1\n\n2", xolox#misc#str#dedent(" 1\n\n 2"))
+ call xolox#misc#test#assert_equals("1\n\n 2", xolox#misc#str#dedent(" 1\n\n 2"))
+endfunction
+
" Tests for autoload/xolox/misc/version.vim {{{1
function! s:test_version_handling()
View
@@ -56,9 +56,12 @@ Contents ~
11. The |xolox#misc#path#is_relative()| function
12. The |xolox#misc#path#tempdir()| function
11. String handling |misc-string-handling|
- 1. The |xolox#misc#str#ucfirst()| function
- 2. The |xolox#misc#str#compact()| function
- 3. The |xolox#misc#str#trim()| function
+ 1. The |xolox#misc#str#slug()| function
+ 2. The |xolox#misc#str#ucfirst()| function
+ 3. The |xolox#misc#str#compact()| function
+ 4. The |xolox#misc#str#trim()| function
+ 5. The |xolox#misc#str#indent()| function
+ 6. The |xolox#misc#str#dedent()| function
12. Test runner & infrastructure for Vim plug-ins |misc-test-runner-infrastructure-for-vim-plug-ins|
1. The |xolox#misc#test#reset()| function
2. The |xolox#misc#test#summarize()| function
@@ -86,8 +89,12 @@ function
14. The |xolox#misc#tests#synchronous_command_execution_without_raising_errors()|
function
15. The |xolox#misc#tests#asynchronous_command_execution()| function
- 16. The |xolox#misc#tests#version_string_parsing()| function
- 17. The |xolox#misc#tests#version_string_comparison()| function
+ 16. The |xolox#misc#tests#string_case_transformation()| function
+ 17. The |xolox#misc#tests#string_whitespace_compaction()| function
+ 18. The |xolox#misc#tests#string_whitespace_trimming()| function
+ 19. The |xolox#misc#tests#multiline_string_dedent()| function
+ 20. The |xolox#misc#tests#version_string_parsing()| function
+ 21. The |xolox#misc#tests#version_string_comparison()| function
14. Timing of long during operations |misc-timing-of-long-during-operations|
1. The |xolox#misc#timer#start()| function
2. The |xolox#misc#timer#stop()| function
@@ -142,8 +149,8 @@ For those who are curious: The function descriptions given below were extracted
from the source code of the miscellaneous scripts using the Python module
'vimdoctool.py' included in vim-tools [5].
-The documentation of the 72 functions below was extracted from 16 Vim scripts
-on June 22, 2013 at 02:08.
+The documentation of the 79 functions below was extracted from 16 Vim scripts
+on June 23, 2013 at 23:13.
-------------------------------------------------------------------------------
*misc-handling-of-special-buffers*
@@ -561,20 +568,36 @@ Create a temporary directory and return the pathname of the directory.
String handling ~
-------------------------------------------------------------------------------
+The *xolox#misc#str#slug()* function
+
+Convert a string to a "slug" - something that can be safely used in filenames
+and URLs without worrying about quoting/escaping of special characters.
+
+-------------------------------------------------------------------------------
The *xolox#misc#str#ucfirst()* function
-Uppercase the first character in a string.
+Uppercase the first character in a string (the first argument).
-------------------------------------------------------------------------------
The *xolox#misc#str#compact()* function
-Compact whitespace in the string given as the first argument.
+Compact whitespace in a string (the first argument).
-------------------------------------------------------------------------------
The *xolox#misc#str#trim()* function
-Trim all whitespace from the start and end of the string given as the first
-argument.
+Trim all whitespace from the start and end of a string (the first argument).
+
+-------------------------------------------------------------------------------
+The *xolox#misc#str#indent()* function
+
+Indent all lines in a multi-line string (the first argument) with a specific
+number of _space characters_ (the second argument, an integer).
+
+-------------------------------------------------------------------------------
+The *xolox#misc#str#dedent()* function
+
+Remove common whitespace from a multi line string.
-------------------------------------------------------------------------------
*misc-test-runner-infrastructure-for-vim-plug-ins*
@@ -729,6 +752,26 @@ Test basic functionality of asynchronous command execution with
|xolox#misc#os#exec()|.
-------------------------------------------------------------------------------
+The *xolox#misc#tests#string_case_transformation()* function
+
+Test string case transformation with |xolox#misc#str#ucfirst()|.
+
+-------------------------------------------------------------------------------
+The *xolox#misc#tests#string_whitespace_compaction()* function
+
+Test compaction of whitespace in strings with |xolox#misc#str#compact()|.
+
+-------------------------------------------------------------------------------
+The *xolox#misc#tests#string_whitespace_trimming()* function
+
+Test trimming of whitespace in strings with |xolox#misc#str#trim()|.
+
+-------------------------------------------------------------------------------
+The *xolox#misc#tests#multiline_string_dedent()* function
+
+Test dedenting of multi-line strings with |xolox#misc#str#dedent()|.
+
+-------------------------------------------------------------------------------
The *xolox#misc#tests#version_string_parsing()* function
Test parsing of version strings with |xolox#misc#version#parse()|.

0 comments on commit 19803c1

Please sign in to comment.