Skip to content

Commit f69d51c

Browse files
committed
chore: Refactor to add toAppleFrameworkRelative helper function
1 parent 56d2c7c commit f69d51c

File tree

1 file changed

+15
-11
lines changed

1 file changed

+15
-11
lines changed

simplecpp.cpp

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2436,6 +2436,20 @@ static bool isAbsolutePath(const std::string &path)
24362436
}
24372437
#endif
24382438

2439+
namespace {
2440+
// "<Pkg/Hdr.h>" -> "<Pkg.framework/Headers/Hdr.h>"
2441+
inline std::string
2442+
toAppleFrameworkRelative(const std::string& header)
2443+
{
2444+
const std::size_t slash = header.find('/');
2445+
if (slash == std::string::npos)
2446+
return header; // no transformation applicable
2447+
const std::string pkg = header.substr(0, slash);
2448+
const std::string tail = header.substr(slash); // includes '/'
2449+
return pkg + ".framework/Headers" + tail;
2450+
}
2451+
}
2452+
24392453
namespace simplecpp {
24402454
/**
24412455
* perform path simplifications for . and ..
@@ -3013,20 +3027,10 @@ static std::string openHeader(std::ifstream &f, const simplecpp::DUI &dui, const
30133027
return path;
30143028
}
30153029

3016-
// a named lambda function to insert the ".framework/Headers" part for apple frameworks
3017-
auto get_apple_framework_relative_path= [](const std::string& appleFrameworkHeader) -> std::string {
3018-
// try the Framework path on apple OS, if there is a path in front
3019-
const size_t slashPos = appleFrameworkHeader.find('/');
3020-
if (slashPos == std::string::npos) {
3021-
return appleFrameworkHeader;
3022-
}
3023-
constexpr auto frameworkSuffix{ ".framework/Headers" };
3024-
return appleFrameworkHeader.substr(0, slashPos) + frameworkSuffix + appleFrameworkHeader.substr(slashPos);
3025-
};
30263030
// on Apple, try to find the header in the framework path
30273031
// Convert <includePath>/PKGNAME/myHeader -> <includePath>/PKGNAME.framework/Headers/myHeader
30283032
// Works on any platform, but only relevant when compiling against Apple SDKs.
3029-
const std::string appleFrameworkHeader = get_apple_framework_relative_path(header);
3033+
const std::string appleFrameworkHeader = toAppleFrameworkRelative(header);
30303034
if (appleFrameworkHeader != header) {
30313035
for (const auto & includePath: dui.includePaths) {
30323036
const std::string frameworkCandidatePath = includePath + '/' + appleFrameworkHeader;

0 commit comments

Comments
 (0)