Permalink
Browse files

New xolox#misc#path#starts_with() function

  • Loading branch information...
1 parent 92172c6 commit e3f28a74c472265c15a593e1c5523b65313feaf4 @xolox committed Jul 6, 2014
Showing with 37 additions and 13 deletions.
  1. +9 −2 README.md
  2. +2 −2 autoload/xolox/misc.vim
  3. +11 −3 autoload/xolox/misc/path.vim
  4. +15 −6 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 92 functions below was extracted from
-19 Vim scripts on June 30, 2014 at 02:47.
+The documentation of the 93 functions below was extracted from
+19 Vim scripts on July 6, 2014 at 18:28.
### Asynchronous Vim script evaluation
@@ -616,6 +616,13 @@ Join a directory pathname and filename into a single pathname.
Find the common prefix of path components in a list of pathnames.
+#### The `xolox#misc#path#starts_with()` function
+
+Check whether the first pathname starts with the second pathname (expected
+to be a directory). This does not perform a regular string comparison;
+first it normalizes both pathnames, then it splits them into their
+pathname segments and then it compares the segments.
+
#### The `xolox#misc#path#encode()` function
Encode a pathname so it can be used as a filename. This uses URL encoding
View
@@ -1,7 +1,7 @@
" The version of my miscellaneous scripts.
"
" Author: Peter Odding <peter@peterodding.com>
-" Last Change: June 30, 2014
+" Last Change: July 6, 2014
" URL: http://peterodding.com/code/vim/misc/
-let g:xolox#misc#version = '1.13.1'
+let g:xolox#misc#version = '1.14'
@@ -1,7 +1,7 @@
" Pathname manipulation functions.
"
" Author: Peter Odding <peter@peterodding.com>
-" Last Change: June 25, 2013
+" Last Change: July 6, 2014
" URL: http://peterodding.com/code/vim/misc/
let s:windows_compatible = xolox#misc#os#is_win()
@@ -154,7 +154,6 @@ function! xolox#misc#path#relative(path, base) " {{{1
return xolox#misc#path#join(distance + path)
endfunction
-
function! xolox#misc#path#merge(parent, child, ...) " {{{1
" Join a directory pathname and filename into a single pathname.
if type(a:parent) == type('') && type(a:child) == type('')
@@ -190,6 +189,16 @@ function! xolox#misc#path#commonprefix(paths) " {{{1
return xolox#misc#path#join(common)
endfunction
+function! xolox#misc#path#starts_with(a, b) " {{{1
+ " Check whether the first pathname starts with the second pathname (expected
+ " to be a directory). This does not perform a regular string comparison;
+ " first it normalizes both pathnames, then it splits them into their
+ " pathname segments and then it compares the segments.
+ let a = xolox#misc#path#split(xolox#misc#path#absolute(a:a))
+ let b = xolox#misc#path#split(xolox#misc#path#absolute(a:b))
+ return a[0 : len(b) - 1] == b
+endfunction
+
function! xolox#misc#path#encode(path) " {{{1
" Encode a pathname so it can be used as a filename. This uses URL encoding
" to encode special characters.
@@ -203,7 +212,6 @@ function! xolox#misc#path#encode(path) " {{{1
return substitute(a:path, mask, '\=printf("%%%x", char2nr(submatch(0)))', 'g')
endfunction
-
function! xolox#misc#path#decode(encoded_path) " {{{1
" Decode a pathname previously encoded with `xolox#misc#path#encode()`.
return substitute(a:encoded_path, '%\(\x\x\?\)', '\=nr2char("0x" . submatch(1))', 'g')
View
@@ -60,10 +60,11 @@ Contents ~
6. The |xolox#misc#path#relative()| function
7. The |xolox#misc#path#merge()| function
8. The |xolox#misc#path#commonprefix()| function
- 9. The |xolox#misc#path#encode()| function
- 10. The |xolox#misc#path#decode()| function
- 11. The |xolox#misc#path#is_relative()| function
- 12. The |xolox#misc#path#tempdir()| function
+ 9. The |xolox#misc#path#starts_with()| function
+ 10. The |xolox#misc#path#encode()| function
+ 11. The |xolox#misc#path#decode()| function
+ 12. The |xolox#misc#path#is_relative()| function
+ 13. The |xolox#misc#path#tempdir()| function
13. Manipulation of UNIX file permissions |misc-manipulation-of-unix-file-permissions|
1. The |xolox#misc#perm#update()| function
2. The |xolox#misc#perm#get()| function
@@ -166,8 +167,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 92 functions below was extracted from 19 Vim scripts
-on June 30, 2014 at 02:47.
+The documentation of the 93 functions below was extracted from 19 Vim scripts
+on July 6, 2014 at 18:28.
-------------------------------------------------------------------------------
*misc-asynchronous-vim-script-evaluation*
@@ -754,6 +755,14 @@ The *xolox#misc#path#commonprefix()* function
Find the common prefix of path components in a list of pathnames.
-------------------------------------------------------------------------------
+The *xolox#misc#path#starts_with()* function
+
+Check whether the first pathname starts with the second pathname (expected to
+be a directory). This does not perform a regular string comparison; first it
+normalizes both pathnames, then it splits them into their pathname segments and
+then it compares the segments.
+
+-------------------------------------------------------------------------------
The *xolox#misc#path#encode()* function
Encode a pathname so it can be used as a filename. This uses URL encoding to

0 comments on commit e3f28a7

Please sign in to comment.