Skip to content

Commit e3f28a7

Browse files
committed
New xolox#misc#path#starts_with() function
1 parent 92172c6 commit e3f28a7

File tree

4 files changed

+37
-13
lines changed

4 files changed

+37
-13
lines changed

README.md

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ from the source code of the miscellaneous scripts using the Python module
3737

3838
<!-- Start of generated documentation -->
3939

40-
The documentation of the 92 functions below was extracted from
41-
19 Vim scripts on June 30, 2014 at 02:47.
40+
The documentation of the 93 functions below was extracted from
41+
19 Vim scripts on July 6, 2014 at 18:28.
4242

4343
### Asynchronous Vim script evaluation
4444

@@ -616,6 +616,13 @@ Join a directory pathname and filename into a single pathname.
616616

617617
Find the common prefix of path components in a list of pathnames.
618618

619+
#### The `xolox#misc#path#starts_with()` function
620+
621+
Check whether the first pathname starts with the second pathname (expected
622+
to be a directory). This does not perform a regular string comparison;
623+
first it normalizes both pathnames, then it splits them into their
624+
pathname segments and then it compares the segments.
625+
619626
#### The `xolox#misc#path#encode()` function
620627

621628
Encode a pathname so it can be used as a filename. This uses URL encoding

autoload/xolox/misc.vim

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
" The version of my miscellaneous scripts.
22
"
33
" Author: Peter Odding <[email protected]>
4-
" Last Change: June 30, 2014
4+
" Last Change: July 6, 2014
55
" URL: http://peterodding.com/code/vim/misc/
66

7-
let g:xolox#misc#version = '1.13.1'
7+
let g:xolox#misc#version = '1.14'

autoload/xolox/misc/path.vim

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
" Pathname manipulation functions.
22
"
33
" Author: Peter Odding <[email protected]>
4-
" Last Change: June 25, 2013
4+
" Last Change: July 6, 2014
55
" URL: http://peterodding.com/code/vim/misc/
66

77
let s:windows_compatible = xolox#misc#os#is_win()
@@ -154,7 +154,6 @@ function! xolox#misc#path#relative(path, base) " {{{1
154154
return xolox#misc#path#join(distance + path)
155155
endfunction
156156

157-
158157
function! xolox#misc#path#merge(parent, child, ...) " {{{1
159158
" Join a directory pathname and filename into a single pathname.
160159
if type(a:parent) == type('') && type(a:child) == type('')
@@ -190,6 +189,16 @@ function! xolox#misc#path#commonprefix(paths) " {{{1
190189
return xolox#misc#path#join(common)
191190
endfunction
192191

192+
function! xolox#misc#path#starts_with(a, b) " {{{1
193+
" Check whether the first pathname starts with the second pathname (expected
194+
" to be a directory). This does not perform a regular string comparison;
195+
" first it normalizes both pathnames, then it splits them into their
196+
" pathname segments and then it compares the segments.
197+
let a = xolox#misc#path#split(xolox#misc#path#absolute(a:a))
198+
let b = xolox#misc#path#split(xolox#misc#path#absolute(a:b))
199+
return a[0 : len(b) - 1] == b
200+
endfunction
201+
193202
function! xolox#misc#path#encode(path) " {{{1
194203
" Encode a pathname so it can be used as a filename. This uses URL encoding
195204
" to encode special characters.
@@ -203,7 +212,6 @@ function! xolox#misc#path#encode(path) " {{{1
203212
return substitute(a:path, mask, '\=printf("%%%x", char2nr(submatch(0)))', 'g')
204213
endfunction
205214

206-
207215
function! xolox#misc#path#decode(encoded_path) " {{{1
208216
" Decode a pathname previously encoded with `xolox#misc#path#encode()`.
209217
return substitute(a:encoded_path, '%\(\x\x\?\)', '\=nr2char("0x" . submatch(1))', 'g')

doc/misc.txt

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,11 @@ Contents ~
6060
6. The |xolox#misc#path#relative()| function
6161
7. The |xolox#misc#path#merge()| function
6262
8. The |xolox#misc#path#commonprefix()| function
63-
9. The |xolox#misc#path#encode()| function
64-
10. The |xolox#misc#path#decode()| function
65-
11. The |xolox#misc#path#is_relative()| function
66-
12. The |xolox#misc#path#tempdir()| function
63+
9. The |xolox#misc#path#starts_with()| function
64+
10. The |xolox#misc#path#encode()| function
65+
11. The |xolox#misc#path#decode()| function
66+
12. The |xolox#misc#path#is_relative()| function
67+
13. The |xolox#misc#path#tempdir()| function
6768
13. Manipulation of UNIX file permissions |misc-manipulation-of-unix-file-permissions|
6869
1. The |xolox#misc#perm#update()| function
6970
2. The |xolox#misc#perm#get()| function
@@ -166,8 +167,8 @@ For those who are curious: The function descriptions given below were extracted
166167
from the source code of the miscellaneous scripts using the Python module
167168
'vimdoctool.py' included in vim-tools [5].
168169

169-
The documentation of the 92 functions below was extracted from 19 Vim scripts
170-
on June 30, 2014 at 02:47.
170+
The documentation of the 93 functions below was extracted from 19 Vim scripts
171+
on July 6, 2014 at 18:28.
171172

172173
-------------------------------------------------------------------------------
173174
*misc-asynchronous-vim-script-evaluation*
@@ -753,6 +754,14 @@ The *xolox#misc#path#commonprefix()* function
753754

754755
Find the common prefix of path components in a list of pathnames.
755756

757+
-------------------------------------------------------------------------------
758+
The *xolox#misc#path#starts_with()* function
759+
760+
Check whether the first pathname starts with the second pathname (expected to
761+
be a directory). This does not perform a regular string comparison; first it
762+
normalizes both pathnames, then it splits them into their pathname segments and
763+
then it compares the segments.
764+
756765
-------------------------------------------------------------------------------
757766
The *xolox#misc#path#encode()* function
758767

0 commit comments

Comments
 (0)