Permalink
Browse files

Add xolox#misc#format#pluralize() function

  • Loading branch information...
1 parent 2a8eaa7 commit d250b06df7255f021b999b74c58f88287c929190 @xolox committed Jun 2, 2013
Showing with 29 additions and 4 deletions.
  1. +7 −1 README.md
  2. +1 −1 autoload/xolox/misc.vim
  3. +11 −0 autoload/xolox/misc/format.vim
  4. +10 −2 doc/misc.txt
View
@@ -38,7 +38,7 @@ that I haven't published yet.
<!-- Start of generated documentation -->
-The documentation of the 43 functions below was extracted from
+The documentation of the 44 functions below was extracted from
14 Vim scripts on June 2, 2013 at 21:27.
### Handling of special buffers
@@ -129,6 +129,12 @@ Microsoft Windows).
### Human friendly string formatting for Vim
+#### The `xolox#misc#format#pluralize()` function
+
+Concatenate a counter (the first argument, expected to be an integer) with
+a singular or plural label (the second and third arguments, both expected
+to be strings).
+
#### The `xolox#misc#format#timestamp()` function
Format a time stamp (a string containing a formatted floating point
View
@@ -4,4 +4,4 @@
" Last Change: June 2, 2013
" URL: http://peterodding.com/code/vim/misc/
-let g:xolox#misc#version = '1.2'
+let g:xolox#misc#version = '1.3'
@@ -4,6 +4,17 @@
" Last Change: June 2, 2013
" URL: http://peterodding.com/code/vim/misc/
+function! xolox#misc#format#pluralize(count, singular, plural) " {{{1
+ " Concatenate a counter (the first argument, expected to be an integer) with
+ " a singular or plural label (the second and third arguments, both expected
+ " to be strings).
+ if a:count == 0
+ return printf('no %s', a:plural)
+ else
+ return printf('%i %s', a:count, a:count == 1 ? a:singular : a:plural)
+ endif
+endfunction
+
function! xolox#misc#format#timestamp(ts) " {{{1
" Format a time stamp (a string containing a formatted floating point
" number) into a human friendly format, for example 70 seconds is phrased as
View
@@ -18,7 +18,8 @@ Contents ~
2. The |xolox#misc#escape#substitute()| function
3. The |xolox#misc#escape#shell()| function
4. Human friendly string formatting for Vim |misc-human-friendly-string-formatting-for-vim|
- 1. The |xolox#misc#format#timestamp()| function
+ 1. The |xolox#misc#format#pluralize()| function
+ 2. The |xolox#misc#format#timestamp()| function
5. List handling functions |misc-list-handling-functions|
1. The |xolox#misc#list#unique()| function
2. The |xolox#misc#list#binsert()| function
@@ -111,7 +112,7 @@ that I haven't published yet.
Start of generated documentation
-The documentation of the 43 functions below was extracted from 14 Vim scripts
+The documentation of the 44 functions below was extracted from 14 Vim scripts
on June 2, 2013 at 21:27.
-------------------------------------------------------------------------------
@@ -205,6 +206,13 @@ purpose (running a UNIX style shell on Microsoft Windows).
Human friendly string formatting for Vim ~
-------------------------------------------------------------------------------
+The *xolox#misc#format#pluralize()* function
+
+Concatenate a counter (the first argument, expected to be an integer) with a
+singular or plural label (the second and third arguments, both expected to be
+strings).
+
+-------------------------------------------------------------------------------
The *xolox#misc#format#timestamp()* function
Format a time stamp (a string containing a formatted floating point number)

0 comments on commit d250b06

Please sign in to comment.