Skip to content

Commit

Permalink
Use C++ string manipulation for stripLibPrefix
Browse files Browse the repository at this point in the history
Signed-off-by: Anna Rift <[email protected]>
  • Loading branch information
riftEmber committed Dec 4, 2024
1 parent 818a045 commit 3f2f707
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions compiler/codegen/library.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -153,16 +153,15 @@ static void printMakefileIncludes(fileinfo makefile);
static void printMakefileLibraries(fileinfo makefile, std::string name);

// Return string, without any "lib" prefix if present
// TODO: do this in a more C++ idiomatic way
static std::string stripLibPrefix(const std::string& name) {
std::string ret;

static const int libLength = strlen("lib");
bool startsWithLib = strncmp(name.c_str(), "lib", libLength) == 0;
if (startsWithLib) {
ret = name.substr(libLength);
static const std::string libStr = "lib";

if (name.find(libStr) != std::string::npos) {
ret = name.substr(libStr.length());
} else {
ret = name.c_str();
ret = name;
}

return ret;
Expand Down

0 comments on commit 3f2f707

Please sign in to comment.