Changeset 1288 for cpp/common
- Timestamp:
- 12/06/23 03:32:58 (12 months ago)
- Location:
- cpp/common
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
cpp/common/util-stl.h
r1130 r1288 1 1 // This file is a part of Framsticks SDK. http://www.framsticks.com/ 2 // Copyright (C) 1999-202 1Maciej Komosinski and Szymon Ulatowski.2 // Copyright (C) 1999-2023 Maciej Komosinski and Szymon Ulatowski. 3 3 // See LICENSE.txt for details. 4 4 … … 13 13 for (unsigned int i = 0; i < N; i++) 14 14 v.push_back(d[i]); 15 } 16 17 template<typename T> void push_back(vector<T>& to, const vector<T>& from) 18 { 19 for (auto &e : from) 20 to.push_back(e); 15 21 } 16 22 … … 37 43 } 38 44 39 template<typename Key, typename Value> Value mapValueOrDefault(const std::map<Key,Value> &map, const Key& key, const Value& default_value)45 template<typename Key, typename Value> Value mapValueOrDefault(const std::map<Key, Value> &map, const Key& key, const Value& default_value) 40 46 { 41 47 auto found = map.find(key); -
cpp/common/util-string.cpp
r1276 r1288 113 113 } 114 114 115 bool 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 } 115 124 116 125 char* strmove(char *a, char *b) //strcpy that works well for overlapping strings ("Source and destination overlap") … … 162 171 size_t slash = filename.rfind(PATH_SEPARATOR_CHAR); 163 172 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 176 string 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; 165 183 } 166 184 -
cpp/common/util-string.h
r1276 r1288 13 13 char* strmove(char *a, char *b); //strcpy that works well for overlapping strings ("Source and destination overlap") 14 14 bool str_starts_with(const char *str, const char *prefix); 15 inline bool starts_with(const string& str, const char *prefix) { return str_starts_with(str.c_str(), prefix); } //std::string.starts_with(...) since c++2015 inline bool starts_with(const string& str, const char *prefix) { return str_starts_with(str.c_str(), prefix); } //std::string.starts_with(...) since c++20 16 16 bool ends_with(std::string_view str, std::string_view suffix); 17 bool strip_prefix(string& modify_me, const char* prefix); //@return true if the prefix is found and removed 17 18 18 19 string ssprintf(const char* format, ...); … … 23 24 string getFileDir(const string& filename); // get path component excluding filename ("" if no dir in file) 24 25 string stripFileDir(const string& filename); // strip path component from filename 26 string concatPath(const string& path, const string& other_path); // concatenate paths, adding PATH_SEPARATOR_CHAR if necessary 25 27 26 28 void ltrim_inplace(string &s);
Note: See TracChangeset
for help on using the changeset viewer.