1 //===- HeaderFile.cpp ------------------------------------------*- C++ -*-===// 2 // 3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 // See https://llvm.org/LICENSE.txt for license information. 5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 // 7 //===----------------------------------------------------------------------===// 8 9 #include "clang/InstallAPI/HeaderFile.h" 10 11 using namespace llvm; 12 namespace clang::installapi { 13 14 llvm::Regex HeaderFile::getFrameworkIncludeRule() { 15 return llvm::Regex("/(.+)\\.framework/(.+)?Headers/(.+)"); 16 } 17 18 std::optional<std::string> createIncludeHeaderName(const StringRef FullPath) { 19 // Headers in usr(/local)*/include. 20 std::string Pattern = "/include/"; 21 auto PathPrefix = FullPath.find(Pattern); 22 if (PathPrefix != StringRef::npos) { 23 PathPrefix += Pattern.size(); 24 return FullPath.drop_front(PathPrefix).str(); 25 } 26 27 // Framework Headers. 28 SmallVector<StringRef, 4> Matches; 29 HeaderFile::getFrameworkIncludeRule().match(FullPath, &Matches); 30 // Returned matches are always in stable order. 31 if (Matches.size() != 4) 32 return std::nullopt; 33 34 return Matches[1].drop_front(Matches[1].rfind('/') + 1).str() + "/" + 35 Matches[3].str(); 36 } 37 } // namespace clang::installapi 38