aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/path.c
diff options
context:
space:
mode:
authorScott Prager <splinterofchaos@gmail.com>2014-09-19 19:34:47 -0400
committerThiago de Arruda <tpadilha84@gmail.com>2015-03-31 11:20:23 -0300
commit3f74067565d4661d231679303e9906d3afe2fc3f (patch)
tree1de658da5c4a170f851eae29bdad1f66e1146ab8 /src/nvim/path.c
parent99869989c8be45033f82b567f988a67af6ffda7b (diff)
downloadrneovim-3f74067565d4661d231679303e9906d3afe2fc3f.tar.gz
rneovim-3f74067565d4661d231679303e9906d3afe2fc3f.tar.bz2
rneovim-3f74067565d4661d231679303e9906d3afe2fc3f.zip
Un-mch mch_has_(exp_)wildcard().
Merge mch_has_wildcard() and mch_has_exp_wildcar() with their upstream equivalents for Windows and replace the "mch_" suffix with "path_".
Diffstat (limited to 'src/nvim/path.c')
-rw-r--r--src/nvim/path.c56
1 files changed, 54 insertions, 2 deletions
diff --git a/src/nvim/path.c b/src/nvim/path.c
index 346be9108d..3c0adcfae8 100644
--- a/src/nvim/path.c
+++ b/src/nvim/path.c
@@ -400,6 +400,32 @@ char_u *save_absolute_path(const char_u *name)
return vim_strsave((char_u *) name);
}
+/// Checks if a path has a wildcard character including '~', unless at the end.
+/// @param p The path to expand.
+/// @returns Unix: True if it contains one of "?[{`'$".
+/// @returns Windows: True if it contains one of "*?$[".
+bool path_has_wildcard(const char_u *p)
+ FUNC_ATTR_NONNULL_ALL
+{
+ for (; *p; mb_ptr_adv(p)) {
+#if defined(UNIX)
+ if (p[0] == '\\' && p[1] != NUL) {
+ p++;
+ continue;
+ }
+
+ const char *wildcards = "*?[{`'$";
+#else
+ // Windows:
+ const char *wildcards = "?*$[`";
+#endif
+ if (vim_strchr((char_u *)wildcards, *p) != NULL
+ || (p[0] == '~' && p[1] != NUL)) {
+ return true;
+ }
+ }
+ return false;
+}
#if defined(UNIX)
/*
@@ -410,6 +436,32 @@ static int pstrcmp(const void *a, const void *b)
{
return pathcmp(*(char **)a, *(char **)b, -1);
}
+#endif
+
+/// Checks if a path has a character expandpath can expand.
+/// @param p The path to expand.
+/// @returns Unix: True if it contains one of *?[{.
+/// @returns Windows: True if it contains one of *?[.
+bool path_has_exp_wildcard(const char_u *p)
+ FUNC_ATTR_NONNULL_ALL
+{
+ for (; *p != NUL; mb_ptr_adv(p)) {
+#if defined(UNIX)
+ if (p[0] == '\\' && p[1] != NUL) {
+ p++;
+ continue;
+ }
+
+ const char *wildcards = "*?[{";
+#else
+ const char *wildcards = "*?["; // Windows.
+#endif
+ if (vim_strchr((char_u *) wildcards, *p) != NULL) {
+ return true;
+ }
+ }
+ return false;
+}
/*
* Recursively expand one path component into all matching files and/or
@@ -566,7 +618,7 @@ unix_expandpath (
}
STRCPY(buf + len, path_end);
- if (mch_has_exp_wildcard(path_end)) { /* handle more wildcards */
+ if (path_has_exp_wildcard(path_end)) { // handle more wildcards
/* need to expand another component of the path */
/* remove backslashes for the remaining components only */
(void)unix_expandpath(gap, buf, len + 1, flags, FALSE);
@@ -1078,7 +1130,7 @@ gen_expand_wildcards (
* If there are no wildcards: Add the file name if it exists or
* when EW_NOTFOUND is given.
*/
- if (mch_has_exp_wildcard(p)) {
+ if (path_has_exp_wildcard(p)) {
if ((flags & EW_PATH)
&& !path_is_absolute_path(p)
&& !(p[0] == '.'