@@ -118,53 +118,55 @@ bool needsNormalization(const llvm::StringRef &path) {
118
118
return true ;
119
119
for (auto i = path.find_first_of (" \\ /" ); i != llvm::StringRef::npos;
120
120
i = path.find_first_of (" \\ /" , i + 1 )) {
121
- const auto next = safeCharAtIndex (path, i+ 1 );
121
+ const auto next = safeCharAtIndex (path, i + 1 );
122
122
switch (next) {
123
+ case 0 :
124
+ // path separator char at the end of the string which should be
125
+ // stripped unless it is the one and only character
126
+ return i > 0 ;
127
+ case ' /' :
128
+ case ' \\ ' :
129
+ // two path separator chars in the middle of a path needs to be
130
+ // normalized
131
+ if (i > 0 )
132
+ return true ;
133
+ ++i;
134
+ break ;
135
+
136
+ case ' .' : {
137
+ const auto next_next = safeCharAtIndex (path, i + 2 );
138
+ switch (next_next) {
139
+ default :
140
+ break ;
123
141
case 0 :
124
- // path separator char at the end of the string which should be
125
- // stripped unless it is the one and only character
126
- return i > 0 ;
142
+ return true ; // ends with "/."
127
143
case ' /' :
128
144
case ' \\ ' :
129
- // two path separator chars in the middle of a path needs to be
130
- // normalized
131
- if (i > 0 )
132
- return true ;
133
- ++i;
134
- break ;
135
-
145
+ return true ; // contains "/./"
136
146
case ' .' : {
137
- const auto next_next = safeCharAtIndex (path, i+2 );
138
- switch (next_next) {
139
- default : break ;
140
- case 0 : return true ; // ends with "/."
141
- case ' /' :
142
- case ' \\ ' :
143
- return true ; // contains "/./"
144
- case ' .' : {
145
- const auto next_next_next = safeCharAtIndex (path, i+3 );
146
- switch (next_next_next) {
147
- default : break ;
148
- case 0 : return true ; // ends with "/.."
149
- case ' /' :
150
- case ' \\ ' :
151
- return true ; // contains "/../"
152
- }
153
- break ;
154
- }
155
- }
147
+ const auto next_next_next = safeCharAtIndex (path, i + 3 );
148
+ switch (next_next_next) {
149
+ default :
150
+ break ;
151
+ case 0 :
152
+ return true ; // ends with "/.."
153
+ case ' /' :
154
+ case ' \\ ' :
155
+ return true ; // contains "/../"
156
156
}
157
157
break ;
158
+ }
159
+ }
160
+ } break ;
158
161
159
- default :
160
- break ;
162
+ default :
163
+ break ;
161
164
}
162
165
}
163
166
return false ;
164
167
}
165
168
166
-
167
- }
169
+ } // namespace
168
170
169
171
void FileSpec::SetFile (llvm::StringRef pathname) { SetFile (pathname, m_style); }
170
172
@@ -199,11 +201,11 @@ void FileSpec::SetFile(llvm::StringRef pathname, Style style) {
199
201
// Split path into filename and directory. We rely on the underlying char
200
202
// pointer to be nullptr when the components are empty.
201
203
llvm::StringRef filename = llvm::sys::path::filename (resolved, m_style);
202
- if (!filename.empty ())
204
+ if (!filename.empty ())
203
205
m_filename.SetString (filename);
204
206
205
207
llvm::StringRef directory = llvm::sys::path::parent_path (resolved, m_style);
206
- if (!directory.empty ())
208
+ if (!directory.empty ())
207
209
m_directory.SetString (directory);
208
210
}
209
211
@@ -330,6 +332,13 @@ void FileSpec::Dump(llvm::raw_ostream &s) const {
330
332
s << path_separator;
331
333
}
332
334
335
+ llvm::json::Value FileSpec::ToJSON () const {
336
+ std::string file_spec{};
337
+ llvm::raw_string_ostream stream (file_spec);
338
+ this ->Dump (stream);
339
+ return llvm::json::Value (std::move (file_spec));
340
+ }
341
+
333
342
FileSpec::Style FileSpec::GetPathStyle () const { return m_style; }
334
343
335
344
void FileSpec::SetDirectory (ConstString directory) {
@@ -504,9 +513,7 @@ bool FileSpec::IsSourceImplementationFile() const {
504
513
return g_source_file_regex.Execute (extension);
505
514
}
506
515
507
- bool FileSpec::IsRelative () const {
508
- return !IsAbsolute ();
509
- }
516
+ bool FileSpec::IsRelative () const { return !IsAbsolute (); }
510
517
511
518
bool FileSpec::IsAbsolute () const {
512
519
// Check if we have cached if this path is absolute to avoid recalculating.
0 commit comments