Skip to content

Commit a1f4a20

Browse files
committed
[WIN] escape all string, not only the first occurrency
Fixes #5
1 parent 8217efd commit a1f4a20

File tree

5 files changed

+11
-8
lines changed

5 files changed

+11
-8
lines changed

Diff for: cygwin-prebuilt/cyggcc_s-1.dll

-110 KB
Binary file not shown.

Diff for: cygwin-prebuilt/cygncursesw-10.dll

-316 KB
Binary file not shown.

Diff for: cygwin-prebuilt/cygwin1.dll

-2.82 MB
Binary file not shown.

Diff for: cygwin-prebuilt/cygz.dll

-86.5 KB
Binary file not shown.

Diff for: utils.hpp

+11-8
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131

3232
#include <vector>
3333
#include <sstream>
34+
#include <iostream>
3435

3536
using namespace std;
3637

@@ -77,20 +78,22 @@ inline bool cStrEndsWith(const char *str, const char *suffix) {
7778
}
7879

7980
#ifdef WIN32
80-
inline bool replace(std::string& str, const std::string& from, const std::string& to) {
81-
size_t start_pos = str.find(from);
82-
if(start_pos == std::string::npos)
83-
return false;
84-
str.replace(start_pos, from.length(), to);
85-
return true;
81+
82+
std::string ReplaceAll(std::string str, const std::string& from, const std::string& to) {
83+
size_t start_pos = 0;
84+
while((start_pos = str.find(from, start_pos)) != std::string::npos) {
85+
str.replace(start_pos, from.length(), to);
86+
start_pos += to.length(); // Handles case where 'to' is a substring of 'from'
87+
}
88+
return str;
8689
}
8790

8891
inline std::string quoteCppString(std::string& str) {
89-
replace(str, "\\", "\\\\");
92+
str = ReplaceAll(str, "\\", "\\\\");
9093
return str;
9194
}
9295
#else
9396
inline std::string quoteCppString(std::string& str) {
9497
return str;
9598
}
96-
#endif
99+
#endif

0 commit comments

Comments
 (0)