1695b41eeSopenharmony_ci// Copyright 2012 Google Inc. All Rights Reserved.
2695b41eeSopenharmony_ci//
3695b41eeSopenharmony_ci// Licensed under the Apache License, Version 2.0 (the "License");
4695b41eeSopenharmony_ci// you may not use this file except in compliance with the License.
5695b41eeSopenharmony_ci// You may obtain a copy of the License at
6695b41eeSopenharmony_ci//
7695b41eeSopenharmony_ci//     http://www.apache.org/licenses/LICENSE-2.0
8695b41eeSopenharmony_ci//
9695b41eeSopenharmony_ci// Unless required by applicable law or agreed to in writing, software
10695b41eeSopenharmony_ci// distributed under the License is distributed on an "AS IS" BASIS,
11695b41eeSopenharmony_ci// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12695b41eeSopenharmony_ci// See the License for the specific language governing permissions and
13695b41eeSopenharmony_ci// limitations under the License.
14695b41eeSopenharmony_ci
15695b41eeSopenharmony_ci#ifndef INCLUDES_NORMALIZE_H_
16695b41eeSopenharmony_ci#define INCLUDES_NORMALIZE_H_
17695b41eeSopenharmony_ci
18695b41eeSopenharmony_ci#include <string>
19695b41eeSopenharmony_ci#include <vector>
20695b41eeSopenharmony_ci
21695b41eeSopenharmony_cistruct StringPiece;
22695b41eeSopenharmony_ci
23695b41eeSopenharmony_ci/// Utility functions for normalizing include paths on Windows.
24695b41eeSopenharmony_ci/// TODO: this likely duplicates functionality of CanonicalizePath; refactor.
25695b41eeSopenharmony_cistruct IncludesNormalize {
26695b41eeSopenharmony_ci  /// Normalize path relative to |relative_to|.
27695b41eeSopenharmony_ci  IncludesNormalize(const std::string& relative_to);
28695b41eeSopenharmony_ci
29695b41eeSopenharmony_ci  // Internal utilities made available for testing, maybe useful otherwise.
30695b41eeSopenharmony_ci  static std::string AbsPath(StringPiece s, std::string* err);
31695b41eeSopenharmony_ci  static std::string Relativize(StringPiece path,
32695b41eeSopenharmony_ci                                const std::vector<StringPiece>& start_list,
33695b41eeSopenharmony_ci                                std::string* err);
34695b41eeSopenharmony_ci
35695b41eeSopenharmony_ci  /// Normalize by fixing slashes style, fixing redundant .. and . and makes the
36695b41eeSopenharmony_ci  /// path |input| relative to |this->relative_to_| and store to |result|.
37695b41eeSopenharmony_ci  bool Normalize(const std::string& input, std::string* result,
38695b41eeSopenharmony_ci                 std::string* err) const;
39695b41eeSopenharmony_ci
40695b41eeSopenharmony_ci private:
41695b41eeSopenharmony_ci  std::string relative_to_;
42695b41eeSopenharmony_ci  std::vector<StringPiece> split_relative_to_;
43695b41eeSopenharmony_ci};
44695b41eeSopenharmony_ci
45695b41eeSopenharmony_ci#endif  // INCLUDES_NORMALIZE_H_
46