r201227 - clang/lib/Driver/Multilib.cpp: Rewrite normalizePathSegment() to be tolerant dosish pathsep.
NAKAMURA Takumi
geek4civic at gmail.com
Wed Feb 12 03:42:02 PST 2014
Author: chapuni
Date: Wed Feb 12 05:42:02 2014
New Revision: 201227
URL: http://llvm.org/viewvc/llvm-project?rev=201227&view=rev
Log:
clang/lib/Driver/Multilib.cpp: Rewrite normalizePathSegment() to be tolerant dosish pathsep.
FIXME: It could be more simple...
Modified:
cfe/trunk/lib/Driver/Multilib.cpp
Modified: cfe/trunk/lib/Driver/Multilib.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/Multilib.cpp?rev=201227&r1=201226&r2=201227&view=diff
==============================================================================
--- cfe/trunk/lib/Driver/Multilib.cpp (original)
+++ cfe/trunk/lib/Driver/Multilib.cpp Wed Feb 12 05:42:02 2014
@@ -29,15 +29,30 @@
using namespace clang::driver;
using namespace clang;
using namespace llvm::opt;
+using namespace llvm::sys;
+/// normalize Segment to "/foo/bar" or "".
static void normalizePathSegment(std::string &Segment) {
- if (Segment.empty() || Segment == "/." || Segment == "/" || Segment == ".") {
+ StringRef seg = Segment;
+
+ // Prune trailing "/" or "./"
+ while (1) {
+ StringRef last = *--path::end(seg);
+ if (last != ".")
+ break;
+ seg = path::parent_path(seg);
+ }
+
+ if (seg.empty() || seg == "/") {
Segment = "";
+ return;
+ }
+
+ // Add leading '/'
+ if (seg.front() != '/') {
+ Segment = "/" + seg.str();
} else {
- if (StringRef(Segment).back() == '/')
- Segment.erase(Segment.begin() + Segment.size() - 1);
- if (StringRef(Segment).front() != '/')
- Segment = "/" + Segment;
+ Segment = seg;
}
}
More information about the cfe-commits
mailing list