Kaydet (Commit) 2db621da authored tarafından Stephan Bergmann's avatar Stephan Bergmann

Adapt loplugin:includeform to Windows \ path separator

This can also call loplugin::isSamePathname with two paths that both contain
backslashes, so finally make it (and hasPathnamePrefix) symmetric in which
arguments my contain backslashes.

Change-Id: I0465988d9d41e21c5660cbdbd1558543860ae1ad
üst aace8587
......@@ -52,7 +52,16 @@ private:
auto const file = StringRef(
compiler.getSourceManager().getPresumedLoc(HashLoc)
.getFilename());
auto const dir = compat::take_front(file, file.rfind('/'));
auto pos = file.rfind('/');
#if defined _WIN32
auto const pos2 = file.rfind('\\');
if (pos2 != StringRef::npos
&& (pos == StringRef::npos || pos2 > pos))
{
pos = pos2;
}
#endif
auto const dir = compat::take_front(file, pos);
shouldUseAngles = !loplugin::isSamePathname(SearchPath, dir);
}
if (shouldUseAngles == IsAngled) {
......
......@@ -442,15 +442,28 @@ template<typename Fn> bool checkPathname(
for (std::size_t n = 0;;)
{
std::size_t n1 = pathname.find('\\', n);
if (n1 >= against.size()) {
return check(pathname.substr(n), against.substr(n));
}
if (against[n1] != '/'
|| pathname.substr(n, n1 - n) != against.substr(n, n1 - n))
{
break;
std::size_t n2 = against.find('\\', n);
if (n1 <= n2) {
if (n1 >= against.size()) {
return check(pathname.substr(n), against.substr(n));
}
if ((against[n1] != '/' && against[n1] != '\\')
|| pathname.substr(n, n1 - n) != against.substr(n, n1 - n))
{
break;
}
n = n1 + 1;
} else {
if (n2 >= pathname.size()) {
return check(pathname.substr(n), against.substr(n));
}
if (pathname[n2] != '/'
|| pathname.substr(n, n2 - n) != against.substr(n, n2 - n))
{
break;
}
n = n2 + 1;
}
n = n1 + 1;
}
#endif
return false;
......
......@@ -215,12 +215,12 @@ RewritePlugin::RewriteOption operator|( RewritePlugin::RewriteOption option1, Re
return static_cast< RewritePlugin::RewriteOption >( int( option1 ) | int( option2 ));
}
// Same as pathname.startswith(prefix), except on Windows, where pathname (but
// not prefix) may also contain backslashes:
// Same as pathname.startswith(prefix), except on Windows, where pathname and
// prefix may also contain backslashes:
bool hasPathnamePrefix(StringRef pathname, StringRef prefix);
// Same as pathname == other, except on Windows, where pathname (but not other)
// may also contain backslashes:
// Same as pathname == other, except on Windows, where pathname and other may
// also contain backslashes:
bool isSamePathname(StringRef pathname, StringRef other);
} // namespace
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment