Navigation Menu

Skip to content

Commit

Permalink
New xolox#misc#path#starts_with() function
Browse files Browse the repository at this point in the history
  • Loading branch information
xolox committed Jul 6, 2014
1 parent 92172c6 commit e3f28a7
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 13 deletions.
11 changes: 9 additions & 2 deletions README.md
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions autoload/xolox/misc.vim
@@ -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'
14 changes: 11 additions & 3 deletions autoload/xolox/misc/path.vim
@@ -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()
Expand Down Expand Up @@ -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('')
Expand Down Expand Up @@ -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.
Expand All @@ -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')
Expand Down
21 changes: 15 additions & 6 deletions doc/misc.txt
Expand Up @@ -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
Expand Down Expand Up @@ -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*
Expand Down Expand Up @@ -753,6 +754,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

Expand Down

0 comments on commit e3f28a7

Please sign in to comment.