MCPcopy Create free account
hub / github.com/ErrorAtLine0/infinipaint / ensure_string_unique

Function ensure_string_unique

include/Helpers/StringHelpers.cpp:98–136  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

96}
97
98std::string ensure_string_unique(const std::vector<std::string>& stringList, std::string str) {
99 for(;;) {
100 bool isUnique = true;
101 for(const std::string& strToCheckAgainst : stringList) {
102 if(strToCheckAgainst == str) {
103 size_t leftParenthesisIndex = str.find_last_of('(');
104 size_t rightParenthesisIndex = str.find_last_of(')');
105 bool failToIncrement = true;
106 if(leftParenthesisIndex != std::string::npos && rightParenthesisIndex != std::string::npos && leftParenthesisIndex < rightParenthesisIndex) {
107 std::string numStr = str.substr(leftParenthesisIndex + 1, rightParenthesisIndex - leftParenthesisIndex - 1);
108 bool isAllDigits = true;
109 for(char c : numStr) {
110 if(!isdigit(c)) {
111 isAllDigits = false;
112 break;
113 }
114 }
115 if(isAllDigits) {
116 try {
117 int s = std::stoi(numStr);
118 s++;
119 str = str.substr(0, leftParenthesisIndex);
120 str += "(" + std::to_string(s) + ")";
121 failToIncrement = false;
122 }
123 catch(...) {}
124 }
125 }
126 if(failToIncrement)
127 str += " (2)";
128 isUnique = false;
129 break;
130 }
131 }
132 if(isUnique)
133 break;
134 }
135 return str;
136}
137
138std::string sdl_time_to_nice_access_time(const SDL_DateTime& t, SDL_DateFormat dF, SDL_TimeFormat tF) {
139 SDL_DateTime currentDt;

Callers 5

autosave_to_directoryMethod · 0.85
move_selected_filesMethod · 0.85
sdl_safe_copy_fileFunction · 0.85

Calls 1

to_stringFunction · 0.50

Tested by

no test coverage detected