1 // Copyright 2012 Google Inc. All Rights Reserved. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 #include <string> 16 #include <vector> 17 using namespace std; 18 19 struct StringPiece; 20 21 /// Utility functions for normalizing include paths on Windows. 22 /// TODO: this likely duplicates functionality of CanonicalizePath; refactor. 23 struct IncludesNormalize { 24 /// Normalize path relative to |relative_to|. 25 IncludesNormalize(const string& relative_to); 26 27 // Internal utilities made available for testing, maybe useful otherwise. 28 static string AbsPath(StringPiece s, string* err); 29 static string Relativize(StringPiece path, 30 const vector<StringPiece>& start_list, string* err); 31 32 /// Normalize by fixing slashes style, fixing redundant .. and . and makes the 33 /// path |input| relative to |this->relative_to_| and store to |result|. 34 bool Normalize(const string& input, string* result, string* err) const; 35 36 private: 37 string relative_to_; 38 vector<StringPiece> split_relative_to_; 39 }; 40