glob matching cleanup

master
Daniel Kolesa 2015-12-15 21:22:29 +00:00
parent 7fe6ecdf7e
commit 22eff191ce
1 changed files with 9 additions and 12 deletions

View File

@ -19,7 +19,7 @@ static void ob_get_path_parts(Vector<ConstCharRange> &parts,
parts.push(ep); parts.push(ep);
parts.push("*"); parts.push("*");
elem = star; elem = star;
elem.pop_front(); ++elem;
star = ostd::find(elem, '*'); star = ostd::find(elem, '*');
} }
if (!elem.empty()) if (!elem.empty())
@ -32,10 +32,10 @@ static bool ob_path_matches(ConstCharRange fn,
while (!it.empty()) { while (!it.empty()) {
ConstCharRange elem = it.front(); ConstCharRange elem = it.front();
if (elem == "*") { if (elem == "*") {
it.pop_front(); ++it;
/* skip multiple stars if present */ /* skip multiple stars if present */
while (!it.empty() && ((elem = it.front()) == "*")) while (!it.empty() && ((elem = it.front()) == "*"))
it.pop_front(); ++it;
/* trailing stars, we match */ /* trailing stars, we match */
if (it.empty()) if (it.empty())
return true; return true;
@ -43,7 +43,7 @@ static bool ob_path_matches(ConstCharRange fn,
while (fn.size() > elem.size()) { while (fn.size() > elem.size()) {
if (fn.slice(0, elem.size()) == elem) if (fn.slice(0, elem.size()) == elem)
break; break;
fn.pop_front(); ++fn;
} }
} }
/* non-star here */ /* non-star here */
@ -51,9 +51,9 @@ static bool ob_path_matches(ConstCharRange fn,
return false; return false;
if (fn.slice(0, elem.size()) != elem) if (fn.slice(0, elem.size()) != elem)
return false; return false;
fn.pop_front_n(elem.size()); fn += elem.size();
/* try next element */ /* try next element */
it.pop_front(); ++it;
} }
/* if there are no chars in the fname remaining, we fully matched */ /* if there are no chars in the fname remaining, we fully matched */
return fn.empty(); return fn.empty();
@ -78,8 +78,7 @@ static bool ob_expand_dir(String &ret, ConstCharRange dir,
/* if we reach this, we match; try recursively matching */ /* if we reach this, we match; try recursively matching */
if (!slash.empty()) { if (!slash.empty()) {
afn.append(slash); afn.append(slash);
ConstCharRange psl = slash; ConstCharRange psl = slash + 1;
psl.pop_front();
if (!ostd::find(psl, '*').empty()) { if (!ostd::find(psl, '*').empty()) {
if (!appended) if (!appended)
appended = ob_expand_glob(ret, afn.iter()); appended = ob_expand_glob(ret, afn.iter());
@ -123,12 +122,10 @@ static bool ob_expand_glob(String &ret, ConstCharRange src, bool ne) {
if (!slash.empty()) { if (!slash.empty()) {
/* there was slash, adjust directory + prefix accordingly */ /* there was slash, adjust directory + prefix accordingly */
dir = slice_until(src, slash); dir = slice_until(src, slash);
fnpre = slash; fnpre = slash + 1;
fnpre.pop_front();
} }
/* part after star */ /* part after star */
ConstCharRange fnpost = star; ConstCharRange fnpost = star + 1;
fnpost.pop_front();
/* if a slash follows, adjust */ /* if a slash follows, adjust */
ConstCharRange nslash = ostd::find(fnpost, '/'); ConstCharRange nslash = ostd::find(fnpost, '/');
if (!nslash.empty()) if (!nslash.empty())