mirror of
https://github.com/neovim/neovim.git
synced 2025-09-12 14:28:18 +00:00
Test and refactor getnextcomp -> path_next_component.
This commit is contained in:

committed by
Thiago de Arruda

parent
7021b970b9
commit
955d6a2949
@@ -12422,7 +12422,7 @@ static void f_resolve(typval_T *argvars, typval_T *rettv)
|
|||||||
p[len - 1] = NUL; /* the trailing slash breaks readlink() */
|
p[len - 1] = NUL; /* the trailing slash breaks readlink() */
|
||||||
}
|
}
|
||||||
|
|
||||||
q = getnextcomp(p);
|
q = path_next_component(p);
|
||||||
if (*q != NUL) {
|
if (*q != NUL) {
|
||||||
/* Separate the first path component in "p", and keep the
|
/* Separate the first path component in "p", and keep the
|
||||||
* remainder (beginning with the path separator). */
|
* remainder (beginning with the path separator). */
|
||||||
@@ -12456,7 +12456,7 @@ static void f_resolve(typval_T *argvars, typval_T *rettv)
|
|||||||
|
|
||||||
/* Separate the first path component in the link value and
|
/* Separate the first path component in the link value and
|
||||||
* concatenate the remainders. */
|
* concatenate the remainders. */
|
||||||
q = getnextcomp(vim_ispathsep(*buf) ? buf + 1 : buf);
|
q = path_next_component(vim_ispathsep(*buf) ? buf + 1 : buf);
|
||||||
if (*q != NUL) {
|
if (*q != NUL) {
|
||||||
if (remain == NULL)
|
if (remain == NULL)
|
||||||
remain = vim_strsave(q - 1);
|
remain = vim_strsave(q - 1);
|
||||||
@@ -12495,7 +12495,7 @@ static void f_resolve(typval_T *argvars, typval_T *rettv)
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
/* Append the first path component of "remain" to "p". */
|
/* Append the first path component of "remain" to "p". */
|
||||||
q = getnextcomp(remain + 1);
|
q = path_next_component(remain + 1);
|
||||||
len = q - remain - (*q != NUL);
|
len = q - remain - (*q != NUL);
|
||||||
cpy = vim_strnsave(p, STRLEN(p) + len);
|
cpy = vim_strnsave(p, STRLEN(p) + len);
|
||||||
if (cpy != NULL) {
|
if (cpy != NULL) {
|
||||||
|
14
src/path.c
14
src/path.c
@@ -93,15 +93,15 @@ char_u *path_tail_with_seperator(char_u *fname)
|
|||||||
return tail;
|
return tail;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
char_u *path_next_component(char_u *fname)
|
||||||
* get the next path component (just after the next path separator).
|
|
||||||
*/
|
|
||||||
char_u *getnextcomp(char_u *fname)
|
|
||||||
{
|
{
|
||||||
while (*fname && !vim_ispathsep(*fname))
|
assert(fname != NULL);
|
||||||
|
while (*fname != NUL && !vim_ispathsep(*fname)) {
|
||||||
mb_ptr_adv(fname);
|
mb_ptr_adv(fname);
|
||||||
if (*fname)
|
}
|
||||||
|
if (*fname != NUL) {
|
||||||
++fname;
|
++fname;
|
||||||
|
}
|
||||||
return fname;
|
return fname;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1428,7 +1428,7 @@ void simplify_filename(char_u *filename)
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
++components; /* simple path component */
|
++components; /* simple path component */
|
||||||
p = getnextcomp(p);
|
p = path_next_component(p);
|
||||||
}
|
}
|
||||||
} while (*p != NUL);
|
} while (*p != NUL);
|
||||||
}
|
}
|
||||||
|
10
src/path.h
10
src/path.h
@@ -33,13 +33,20 @@ char_u *path_tail(char_u *fname);
|
|||||||
///
|
///
|
||||||
/// Takes care of "c:/" and "//". That means `path_tail_with_seperator("dir///file.txt")`
|
/// Takes care of "c:/" and "//". That means `path_tail_with_seperator("dir///file.txt")`
|
||||||
/// will return a pointer to `"///file.txt"`.
|
/// will return a pointer to `"///file.txt"`.
|
||||||
/// @param fname A file path.
|
/// @param fname A file path. (Must be != NULL.)
|
||||||
/// @return
|
/// @return
|
||||||
/// - Pointer to the last path seperator of `fname`, if there is any.
|
/// - Pointer to the last path seperator of `fname`, if there is any.
|
||||||
/// - `fname` if it contains no path seperator.
|
/// - `fname` if it contains no path seperator.
|
||||||
/// - Never NULL.
|
/// - Never NULL.
|
||||||
char_u *path_tail_with_seperator(char_u *fname);
|
char_u *path_tail_with_seperator(char_u *fname);
|
||||||
|
|
||||||
|
/// Get the next path component of a path name.
|
||||||
|
///
|
||||||
|
/// @param fname A file path. (Must be != NULL.)
|
||||||
|
/// @return Pointer to first found path seperator + 1.
|
||||||
|
/// An empty string, if `fname` doesn't contain a path seperator,
|
||||||
|
char_u *path_next_component(char_u *fname);
|
||||||
|
|
||||||
int vim_ispathsep(int c);
|
int vim_ispathsep(int c);
|
||||||
int vim_ispathsep_nocolon(int c);
|
int vim_ispathsep_nocolon(int c);
|
||||||
int vim_ispathlistsep(int c);
|
int vim_ispathlistsep(int c);
|
||||||
@@ -54,7 +61,6 @@ int gen_expand_wildcards(int num_pat, char_u **pat, int *num_file,
|
|||||||
char_u ***file,
|
char_u ***file,
|
||||||
int flags);
|
int flags);
|
||||||
void addfile(garray_T *gap, char_u *f, int flags);
|
void addfile(garray_T *gap, char_u *f, int flags);
|
||||||
char_u *getnextcomp(char_u *fname);
|
|
||||||
char_u *get_past_head(char_u *path);
|
char_u *get_past_head(char_u *path);
|
||||||
char_u *concat_str(char_u *str1, char_u *str2);
|
char_u *concat_str(char_u *str1, char_u *str2);
|
||||||
void add_pathsep(char_u *p);
|
void add_pathsep(char_u *p);
|
||||||
|
@@ -9,6 +9,7 @@ typedef enum file_comparison {
|
|||||||
FileComparison path_full_compare(char_u *s1, char_u *s2, int checkname);
|
FileComparison path_full_compare(char_u *s1, char_u *s2, int checkname);
|
||||||
char_u *path_tail(char_u *fname);
|
char_u *path_tail(char_u *fname);
|
||||||
char_u *path_tail_with_seperator(char_u *fname);
|
char_u *path_tail_with_seperator(char_u *fname);
|
||||||
|
char_u *path_next_component(char_u *fname);
|
||||||
]]
|
]]
|
||||||
|
|
||||||
-- import constants parsed by ffi
|
-- import constants parsed by ffi
|
||||||
@@ -85,3 +86,15 @@ describe 'path function', ->
|
|||||||
|
|
||||||
it 'returns the whole file name if there is no seperator', ->
|
it 'returns the whole file name if there is no seperator', ->
|
||||||
eq 'file.txt', path_tail_with_seperator 'file.txt'
|
eq 'file.txt', path_tail_with_seperator 'file.txt'
|
||||||
|
|
||||||
|
describe 'path_next_component', ->
|
||||||
|
path_next_component = (file) ->
|
||||||
|
res = path.path_next_component (to_cstr file)
|
||||||
|
neq NULL, res
|
||||||
|
ffi.string res
|
||||||
|
|
||||||
|
it 'returns', ->
|
||||||
|
eq 'directory/file.txt', path_next_component 'some/directory/file.txt'
|
||||||
|
|
||||||
|
it 'returns empty string if given file contains no seperator', ->
|
||||||
|
eq '', path_next_component 'file.txt'
|
||||||
|
Reference in New Issue
Block a user