summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTakuto Ikuta <tikuta@chromium.org>2017-05-09 04:34:31 (GMT)
committerTakuto Ikuta <tikuta@chromium.org>2017-05-09 05:20:03 (GMT)
commit75b338506197921f14e3ce0eb9a04d2787ae1750 (patch)
tree812229300ad3518d471e16c3a05f8398eaa67aeb
parent3b320023276f98b978054c14c65d3888b989ff4a (diff)
downloadNinja-75b338506197921f14e3ce0eb9a04d2787ae1750.zip
Ninja-75b338506197921f14e3ce0eb9a04d2787ae1750.tar.gz
Ninja-75b338506197921f14e3ce0eb9a04d2787ae1750.tar.bz2
Fix for review
-rw-r--r--src/clparser.cc5
-rw-r--r--src/includes_normalize-win32.cc27
-rw-r--r--src/includes_normalize.h4
-rw-r--r--src/util.cc2
-rw-r--r--src/util.h2
5 files changed, 20 insertions, 20 deletions
diff --git a/src/clparser.cc b/src/clparser.cc
index c993e36..7994c06 100644
--- a/src/clparser.cc
+++ b/src/clparser.cc
@@ -19,6 +19,7 @@
#include <string.h>
#include "metrics.h"
+#include "string_piece_util.h"
#ifdef _WIN32
#include "includes_normalize.h"
@@ -56,7 +57,7 @@ string CLParser::FilterShowIncludes(const string& line,
// static
bool CLParser::IsSystemInclude(string path) {
- transform(path.begin(), path.end(), path.begin(), ::tolower);
+ transform(path.begin(), path.end(), path.begin(), ToLowerASCII);
// TODO: this is a heuristic, perhaps there's a better way?
return (path.find("program files") != string::npos ||
path.find("microsoft visual studio") != string::npos);
@@ -64,7 +65,7 @@ bool CLParser::IsSystemInclude(string path) {
// static
bool CLParser::FilterInputFilename(string line) {
- transform(line.begin(), line.end(), line.begin(), ::tolower);
+ transform(line.begin(), line.end(), line.begin(), ToLowerASCII);
// TODO: other extensions, like .asm?
return EndsWith(line, ".c") ||
EndsWith(line, ".cc") ||
diff --git a/src/includes_normalize-win32.cc b/src/includes_normalize-win32.cc
index b60ad70..c72783f 100644
--- a/src/includes_normalize-win32.cc
+++ b/src/includes_normalize-win32.cc
@@ -38,11 +38,11 @@ bool SameDriveFast(StringPiece a, StringPiece b) {
return false;
}
- if (!isalpha(a[0]) || !isalpha(b[0])) {
+ if (!islatinalpha(a[0]) || !islatinalpha(b[0])) {
return false;
}
- if (tolower(a[0]) != tolower(b[0])) {
+ if (ToLowerASCII(a[0]) != ToLowerASCII(b[0])) {
return false;
}
@@ -50,17 +50,11 @@ bool SameDriveFast(StringPiece a, StringPiece b) {
return false;
}
- if (!IsPathSeparator(a[2]) ||
- !IsPathSeparator(b[2])) {
- return false;
- }
-
- return true;
+ return IsPathSeparator(a[2]) && IsPathSeparator(b[2]);
}
// Return true if paths a and b are on the same Windows drive.
bool SameDrive(StringPiece a, StringPiece b) {
- // Fast check.
if (SameDriveFast(a, b)) {
return true;
}
@@ -76,9 +70,11 @@ bool SameDrive(StringPiece a, StringPiece b) {
return _stricmp(a_drive, b_drive) == 0;
}
-bool IsAbsPath(StringPiece s) {
+// Check path |s| is FullPath style returned by GetFullPathName.
+// This ignores difference of path separator.
+bool IsFullPathName(StringPiece s) {
if (s.size() < 3 ||
- !isalpha(s[0]) ||
+ !islatinalpha(s[0]) ||
s[1] != ':' ||
!IsPathSeparator(s[2])) {
return false;
@@ -110,11 +106,11 @@ bool IsAbsPath(StringPiece s) {
IncludesNormalize::IncludesNormalize(const string& relative_to) {
relative_to_ = AbsPath(relative_to);
- splitted_relative_to_ = SplitStringPiece(relative_to_, '/');
+ split_relative_to_ = SplitStringPiece(relative_to_, '/');
}
string IncludesNormalize::AbsPath(StringPiece s) {
- if (IsAbsPath(s)) {
+ if (IsFullPathName(s)) {
string result = s.AsString();
for (size_t i = 0; i < result.size(); ++i) {
if (result[i] == '\\') {
@@ -132,7 +128,8 @@ string IncludesNormalize::AbsPath(StringPiece s) {
return result;
}
-string IncludesNormalize::Relativize(StringPiece path, const vector<StringPiece>& start_list) {
+string IncludesNormalize::Relativize(
+ StringPiece path, const vector<StringPiece>& start_list) {
string abs_path = AbsPath(path);
vector<StringPiece> path_list = SplitStringPiece(abs_path, '/');
int i;
@@ -172,6 +169,6 @@ bool IncludesNormalize::Normalize(const string& input,
*result = partially_fixed.AsString();
return true;
}
- *result = Relativize(partially_fixed, splitted_relative_to_);
+ *result = Relativize(partially_fixed, split_relative_to_);
return true;
}
diff --git a/src/includes_normalize.h b/src/includes_normalize.h
index 2ec08ed..3811e53 100644
--- a/src/includes_normalize.h
+++ b/src/includes_normalize.h
@@ -30,10 +30,10 @@ struct IncludesNormalize {
const vector<StringPiece>& start_list);
/// Normalize by fixing slashes style, fixing redundant .. and . and makes the
- /// path relative to |relative_to_|.
+ /// path |input| relative to |this->relative_to_| and store to |result|.
bool Normalize(const string& input, string* result, string* err) const;
private:
string relative_to_;
- vector<StringPiece> splitted_relative_to_;
+ vector<StringPiece> split_relative_to_;
};
diff --git a/src/util.cc b/src/util.cc
index ce4b192..84de879 100644
--- a/src/util.cc
+++ b/src/util.cc
@@ -471,7 +471,7 @@ void Win32Fatal(const char* function) {
}
#endif
-static bool islatinalpha(int c) {
+bool islatinalpha(int c) {
// isalpha() is locale-dependent.
return (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z');
}
diff --git a/src/util.h b/src/util.h
index 846cd93..4ee41a5 100644
--- a/src/util.h
+++ b/src/util.h
@@ -70,6 +70,8 @@ const char* SpellcheckStringV(const string& text,
/// Like SpellcheckStringV, but takes a NULL-terminated list.
const char* SpellcheckString(const char* text, ...);
+bool islatinalpha(int c);
+
/// Removes all Ansi escape codes (http://www.termsys.demon.co.uk/vtansi.htm).
string StripAnsiEscapeCodes(const string& in);