Skip to content

Commit

Permalink
Merge pull request #391 from vim-jp/System.Filepath/some-improves
Browse files Browse the repository at this point in the history
System.Filepath: some improves
  • Loading branch information
thinca committed Feb 11, 2016
2 parents e83e607 + 140a012 commit 7ca07c3
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 107 deletions.
19 changes: 11 additions & 8 deletions autoload/vital/__latest__/System/Filepath.vim
Expand Up @@ -33,7 +33,7 @@ function! s:path_extensions() abort
let pathext = $PATHEXT
else
" get default PATHEXT
let pathext = matchstr(system('set pathext'), '^pathext=\zs.*\ze\n', 'i')
let pathext = matchstr(system('set pathext'), '\C^pathext=\zs.*\ze\n', 'i')
endif
let s:path_extensions = map(split(pathext, s:path_separator), 'tolower(v:val)')
elseif s:is_cygwin
Expand Down Expand Up @@ -161,7 +161,7 @@ endfunction
" Remove the separator at the end of a:path.
function! s:remove_last_separator(path) abort
let sep = s:separator()
let pat = (sep ==# '\' ? '\\' : '/') . '\+$'
let pat = escape(sep, '\') . '\+$'
return substitute(a:path, pat, '', '')
endfunction

Expand Down Expand Up @@ -213,12 +213,15 @@ else
endfunction
endif

function! s:is_root_directory(path) abort
if a:path ==# '/'
return 1
endif
return (has('win32') || has('win64')) && a:path =~# '^[a-zA-Z]:[/\\]$'
endfunction
if s:is_windows
function! s:is_root_directory(path) abort
return a:path =~# '^[a-zA-Z]:[/\\]$'
endfunction
else
function! s:is_root_directory(path) abort
return a:path ==# '/'
endfunction
endif

function! s:contains(path, base) abort
if a:path ==# '' || a:base ==# ''
Expand Down
26 changes: 15 additions & 11 deletions doc/vital-system-filepath.txt
Expand Up @@ -40,43 +40,47 @@ which({command} [, {path}]) *Vital.System.Filepath.which()*
split({path}) *Vital.System.Filepath.split()*
Return |List| of elements in {path} string.

join({args}...) *Vital.System.Filepath.join()*
join({args}...) *Vital.System.Filepath.join()*
Join the path in {args}.

is_absolute({path}) *Vital.System.Filepath.is_absolute()*
is_absolute({path}) *Vital.System.Filepath.is_absolute()*
When {path} is absolute path, return 1.
Otherwise, return 0.
cf. |Vital.System.Filepath.is_relative()|
cf. |Vital.System.Filepath.is_relative()|

is_relative({path}) *Vital.System.Filepath.is_relative()*
is_relative({path}) *Vital.System.Filepath.is_relative()*
When {path} is relative path, return 1.
Otherwise, return 0.
cf. |Vital.System.Filepath.is_absolute()|
cf. |Vital.System.Filepath.is_absolute()|

dirname({path}) *Vital.System.Filepath.dirname()*
dirname({path}) *Vital.System.Filepath.dirname()*
Return directory name from {path}.

basename({path}) *Vital.System.Filepath.basename()*
basename({path}) *Vital.System.Filepath.basename()*
Return basename from {path}.

remove_last_separator({path}) *Vital.System.Filepath.remove_last_separator()*
remove_last_separator({path}) *Vital.System.Filepath.remove_last_separator()*
Remove last directory separator if exists.

is_case_tolerant() *Vital.System.Filepath.is_case_tolerant()*
Return non-zero if filesystem ignores alphabetic case of a filename,
zero otherwise.

abspath({path}) *Vital.System.Filepath.abspath()*
Return an absolute path of {path}.
If the {path} is already an absolute path, it return the {path}.
cf. |Vital.System.Filepath.relpath()|
cf. |Vital.System.Filepath.relpath()|

relpath({path}) *Vital.System.Filepath.relpath()*
Return an relative path of {path}.
If the {path} is already a relative path, it return the {path}.
cf. |Vital.System.Filepath.abspath()|
cf. |Vital.System.Filepath.abspath()|

unixpath({path}) *Vital.System.Filepath.unixpath()*
Return an unix path of {path}.
All backslashes (\) in {path} will be substituted to slashes (/).

winpath({path}) *Vital.System.Filepath.winpath()*
winpath({path}) *Vital.System.Filepath.winpath()*
Return a windows path of {path}.
All slashes (/) in {path} will be substituted to backslashes (\).

Expand Down

0 comments on commit 7ca07c3

Please sign in to comment.