Ignore:
Timestamp:
12/06/23 03:32:58 (5 months ago)
Author:
Maciej Komosinski
Message:

Added helper functions

File:
1 edited

Legend:

Unmodified
Added
Removed
  • cpp/common/util-string.cpp

    r1276 r1288  
    113113}
    114114
     115bool strip_prefix(string& modify_me, const char* prefix)
     116{
     117        if (starts_with(modify_me, prefix))
     118        {
     119                modify_me = modify_me.substr(strlen(prefix));
     120                return true;
     121        }
     122        return false;
     123}
    115124
    116125char* strmove(char *a, char *b) //strcpy that works well for overlapping strings ("Source and destination overlap")
     
    162171        size_t slash = filename.rfind(PATH_SEPARATOR_CHAR);
    163172        if (slash == string::npos) return string("");
    164         return filename.substr(0, slash);
     173        return (slash == 0) ? string(PATH_SEPARATOR_STRING) : filename.substr(0, slash);
     174}
     175
     176string concatPath(const string& path, const string& other_path)
     177{
     178        string result = path;
     179        if (!result.empty() && result.back() != PATH_SEPARATOR_CHAR && !other_path.empty())
     180                result += PATH_SEPARATOR_CHAR;
     181        result += other_path;
     182        return result;
    165183}
    166184
Note: See TracChangeset for help on using the changeset viewer.