| 969 | } |
| 970 | |
| 971 | bool IGFD::Utils::ReplaceString(std::string& str, const ::std::string& oldStr, const ::std::string& newStr, const size_t& vMaxRecursion) { |
| 972 | if (!str.empty() && oldStr != newStr) { |
| 973 | bool res = false; |
| 974 | size_t pos = 0; |
| 975 | bool found = false; |
| 976 | size_t max_recursion = vMaxRecursion; |
| 977 | do { |
| 978 | pos = str.find(oldStr, pos); |
| 979 | if (pos != std::string::npos) { |
| 980 | found = res = true; |
| 981 | str.replace(pos, oldStr.length(), newStr); |
| 982 | pos += newStr.length(); |
| 983 | } else if (found && max_recursion > 0) { // recursion loop |
| 984 | found = false; |
| 985 | pos = 0; |
| 986 | --max_recursion; |
| 987 | } |
| 988 | } while (pos != std::string::npos); |
| 989 | return res; |
| 990 | } |
| 991 | return false; |
| 992 | } |
| 993 | |
| 994 | std::vector<std::string> IGFD::Utils::SplitStringToVector(const std::string& vText, const std::string& vDelimiterPattern, const bool vPushEmpty) { |
| 995 | std::vector<std::string> arr; |