Skip to content

Commit 1deea83

Browse files
committed
exposed isAbsolutePath() and merged implementations
1 parent 04f4dfa commit 1deea83

2 files changed

Lines changed: 12 additions & 12 deletions

File tree

simplecpp.cpp

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2413,21 +2413,18 @@ namespace simplecpp {
24132413
return windowsPath;
24142414
}
24152415
#endif
2416-
}
24172416

2417+
bool isAbsolutePath(const std::string &path)
2418+
{
24182419
#ifdef SIMPLECPP_WINDOWS
2419-
static bool isAbsolutePath(const std::string &path)
2420-
{
2421-
if (path.length() >= 3 && path[0] > 0 && std::isalpha(path[0]) && path[1] == ':' && (path[2] == '\\' || path[2] == '/'))
2422-
return true;
2423-
return path.length() > 1U && (path[0] == '/' || path[0] == '\\');
2424-
}
2420+
if (path.length() >= 3 && path[0] > 0 && std::isalpha(path[0]) && path[1] == ':' && (path[2] == '\\' || path[2] == '/'))
2421+
return true;
2422+
return path.length() > 1U && (path[0] == '/' || path[0] == '\\');
24252423
#else
2426-
static bool isAbsolutePath(const std::string &path)
2427-
{
2428-
return path.length() > 1U && path[0] == '/';
2429-
}
2424+
return path.length() > 1U && path[0] == '/';
24302425
#endif
2426+
}
2427+
}
24312428

24322429
namespace simplecpp {
24332430
/**
@@ -2988,7 +2985,7 @@ static std::string openHeaderDirect(std::ifstream &f, const std::string &path)
29882985

29892986
static std::string openHeader(std::ifstream &f, const simplecpp::DUI &dui, const std::string &sourcefile, const std::string &header, bool systemheader)
29902987
{
2991-
if (isAbsolutePath(header))
2988+
if (simplecpp::isAbsolutePath(header))
29922989
return openHeaderDirect(f, simplecpp::simplifyPath(header));
29932990

29942991
// prefer first to search the header relatively to source file if found, when not a system header

simplecpp.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -559,6 +559,9 @@ namespace simplecpp {
559559
/** Returns the __cplusplus value for a given standard */
560560
SIMPLECPP_LIB std::string getCppStdString(const std::string &std);
561561
SIMPLECPP_LIB std::string getCppStdString(cppstd_t std);
562+
563+
/** Checks if given path is absolute */
564+
SIMPLECPP_LIB bool isAbsolutePath(const std::string &path);
562565
}
563566

564567
#undef SIMPLECPP_TOKENLIST_ALLOW_PTR

0 commit comments

Comments
 (0)