Skip to content
This repository was archived by the owner on Jun 15, 2023. It is now read-only.

Commit 75b3385

Browse files
author
Takuto Ikuta
committedMay 9, 2017
Fix for review
1 parent 3b32002 commit 75b3385

File tree

5 files changed

+20
-20
lines changed

5 files changed

+20
-20
lines changed
 

‎src/clparser.cc

+3-2
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include <string.h>
2020

2121
#include "metrics.h"
22+
#include "string_piece_util.h"
2223

2324
#ifdef _WIN32
2425
#include "includes_normalize.h"
@@ -56,15 +57,15 @@ string CLParser::FilterShowIncludes(const string& line,
5657

5758
// static
5859
bool CLParser::IsSystemInclude(string path) {
59-
transform(path.begin(), path.end(), path.begin(), ::tolower);
60+
transform(path.begin(), path.end(), path.begin(), ToLowerASCII);
6061
// TODO: this is a heuristic, perhaps there's a better way?
6162
return (path.find("program files") != string::npos ||
6263
path.find("microsoft visual studio") != string::npos);
6364
}
6465

6566
// static
6667
bool CLParser::FilterInputFilename(string line) {
67-
transform(line.begin(), line.end(), line.begin(), ::tolower);
68+
transform(line.begin(), line.end(), line.begin(), ToLowerASCII);
6869
// TODO: other extensions, like .asm?
6970
return EndsWith(line, ".c") ||
7071
EndsWith(line, ".cc") ||

‎src/includes_normalize-win32.cc

+12-15
Original file line numberDiff line numberDiff line change
@@ -38,29 +38,23 @@ bool SameDriveFast(StringPiece a, StringPiece b) {
3838
return false;
3939
}
4040

41-
if (!isalpha(a[0]) || !isalpha(b[0])) {
41+
if (!islatinalpha(a[0]) || !islatinalpha(b[0])) {
4242
return false;
4343
}
4444

45-
if (tolower(a[0]) != tolower(b[0])) {
45+
if (ToLowerASCII(a[0]) != ToLowerASCII(b[0])) {
4646
return false;
4747
}
4848

4949
if (a[1] != ':' || b[1] != ':') {
5050
return false;
5151
}
5252

53-
if (!IsPathSeparator(a[2]) ||
54-
!IsPathSeparator(b[2])) {
55-
return false;
56-
}
57-
58-
return true;
53+
return IsPathSeparator(a[2]) && IsPathSeparator(b[2]);
5954
}
6055

6156
// Return true if paths a and b are on the same Windows drive.
6257
bool SameDrive(StringPiece a, StringPiece b) {
63-
// Fast check.
6458
if (SameDriveFast(a, b)) {
6559
return true;
6660
}
@@ -76,9 +70,11 @@ bool SameDrive(StringPiece a, StringPiece b) {
7670
return _stricmp(a_drive, b_drive) == 0;
7771
}
7872

79-
bool IsAbsPath(StringPiece s) {
73+
// Check path |s| is FullPath style returned by GetFullPathName.
74+
// This ignores difference of path separator.
75+
bool IsFullPathName(StringPiece s) {
8076
if (s.size() < 3 ||
81-
!isalpha(s[0]) ||
77+
!islatinalpha(s[0]) ||
8278
s[1] != ':' ||
8379
!IsPathSeparator(s[2])) {
8480
return false;
@@ -110,11 +106,11 @@ bool IsAbsPath(StringPiece s) {
110106

111107
IncludesNormalize::IncludesNormalize(const string& relative_to) {
112108
relative_to_ = AbsPath(relative_to);
113-
splitted_relative_to_ = SplitStringPiece(relative_to_, '/');
109+
split_relative_to_ = SplitStringPiece(relative_to_, '/');
114110
}
115111

116112
string IncludesNormalize::AbsPath(StringPiece s) {
117-
if (IsAbsPath(s)) {
113+
if (IsFullPathName(s)) {
118114
string result = s.AsString();
119115
for (size_t i = 0; i < result.size(); ++i) {
120116
if (result[i] == '\\') {
@@ -132,7 +128,8 @@ string IncludesNormalize::AbsPath(StringPiece s) {
132128
return result;
133129
}
134130

135-
string IncludesNormalize::Relativize(StringPiece path, const vector<StringPiece>& start_list) {
131+
string IncludesNormalize::Relativize(
132+
StringPiece path, const vector<StringPiece>& start_list) {
136133
string abs_path = AbsPath(path);
137134
vector<StringPiece> path_list = SplitStringPiece(abs_path, '/');
138135
int i;
@@ -172,6 +169,6 @@ bool IncludesNormalize::Normalize(const string& input,
172169
*result = partially_fixed.AsString();
173170
return true;
174171
}
175-
*result = Relativize(partially_fixed, splitted_relative_to_);
172+
*result = Relativize(partially_fixed, split_relative_to_);
176173
return true;
177174
}

‎src/includes_normalize.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,10 @@ struct IncludesNormalize {
3030
const vector<StringPiece>& start_list);
3131

3232
/// Normalize by fixing slashes style, fixing redundant .. and . and makes the
33-
/// path relative to |relative_to_|.
33+
/// path |input| relative to |this->relative_to_| and store to |result|.
3434
bool Normalize(const string& input, string* result, string* err) const;
3535

3636
private:
3737
string relative_to_;
38-
vector<StringPiece> splitted_relative_to_;
38+
vector<StringPiece> split_relative_to_;
3939
};

‎src/util.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -471,7 +471,7 @@ void Win32Fatal(const char* function) {
471471
}
472472
#endif
473473

474-
static bool islatinalpha(int c) {
474+
bool islatinalpha(int c) {
475475
// isalpha() is locale-dependent.
476476
return (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z');
477477
}

‎src/util.h

+2
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,8 @@ const char* SpellcheckStringV(const string& text,
7070
/// Like SpellcheckStringV, but takes a NULL-terminated list.
7171
const char* SpellcheckString(const char* text, ...);
7272

73+
bool islatinalpha(int c);
74+
7375
/// Removes all Ansi escape codes (http://www.termsys.demon.co.uk/vtansi.htm).
7476
string StripAnsiEscapeCodes(const string& in);
7577

0 commit comments

Comments
 (0)
This repository has been archived.