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 
18 struct StringPiece;
19 
20 /// Utility functions for normalizing include paths on Windows.
21 /// TODO: this likely duplicates functionality of CanonicalizePath; refactor.
22 struct IncludesNormalize {
23   /// Normalize path relative to |relative_to|.
24   IncludesNormalize(const std::string& relative_to);
25 
26   // Internal utilities made available for testing, maybe useful otherwise.
27   static std::string AbsPath(StringPiece s, std::string* err);
28   static std::string Relativize(StringPiece path,
29                                 const std::vector<StringPiece>& start_list,
30                                 std::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 std::string& input, std::string* result,
35                  std::string* err) const;
36 
37  private:
38   std::string relative_to_;
39   std::vector<StringPiece> split_relative_to_;
40 };
41