Skip to content

Commit 9a91d27

Browse files
committed
chore: Refactor to add toAppleFrameworkRelative helper function
1 parent 6fc70f6 commit 9a91d27

1 file changed

Lines changed: 15 additions & 11 deletions

File tree

simplecpp.cpp

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2429,6 +2429,20 @@ static bool isAbsolutePath(const std::string &path)
24292429
}
24302430
#endif
24312431

2432+
namespace {
2433+
// "<Pkg/Hdr.h>" -> "<Pkg.framework/Headers/Hdr.h>"
2434+
inline std::string
2435+
toAppleFrameworkRelative(const std::string& header)
2436+
{
2437+
const std::size_t slash = header.find('/');
2438+
if (slash == std::string::npos)
2439+
return header; // no transformation applicable
2440+
const std::string pkg = header.substr(0, slash);
2441+
const std::string tail = header.substr(slash); // includes '/'
2442+
return pkg + ".framework/Headers" + tail;
2443+
}
2444+
}
2445+
24322446
namespace simplecpp {
24332447
/**
24342448
* perform path simplifications for . and ..
@@ -3006,20 +3020,10 @@ static std::string openHeader(std::ifstream &f, const simplecpp::DUI &dui, const
30063020
return path;
30073021
}
30083022

3009-
// a named lambda function to insert the ".framework/Headers" part for apple frameworks
3010-
auto get_apple_framework_relative_path= [](const std::string& appleFrameworkHeader) -> std::string {
3011-
// try the Framework path on apple OS, if there is a path in front
3012-
const size_t slashPos = appleFrameworkHeader.find('/');
3013-
if (slashPos == std::string::npos) {
3014-
return appleFrameworkHeader;
3015-
}
3016-
constexpr auto frameworkSuffix{ ".framework/Headers" };
3017-
return appleFrameworkHeader.substr(0, slashPos) + frameworkSuffix + appleFrameworkHeader.substr(slashPos);
3018-
};
30193023
// on Apple, try to find the header in the framework path
30203024
// Convert <includePath>/PKGNAME/myHeader -> <includePath>/PKGNAME.framework/Headers/myHeader
30213025
// Works on any platform, but only relevant when compiling against Apple SDKs.
3022-
const std::string appleFrameworkHeader = get_apple_framework_relative_path(header);
3026+
const std::string appleFrameworkHeader = toAppleFrameworkRelative(header);
30233027
if (appleFrameworkHeader != header) {
30243028
for (const auto & includePath: dui.includePaths) {
30253029
const std::string frameworkCandidatePath = includePath + '/' + appleFrameworkHeader;

0 commit comments

Comments
 (0)