File tree Expand file tree Collapse file tree 2 files changed +48
-4
lines changed Expand file tree Collapse file tree 2 files changed +48
-4
lines changed Original file line number Diff line number Diff line change @@ -22,6 +22,28 @@ namespace s3d
22
22
{
23
23
namespace detail
24
24
{
25
+ [[nodiscard]]
26
+ static std::string Escape (const std::string& s)
27
+ {
28
+ std::string result;
29
+ result.push_back (' \' ' );
30
+
31
+ for (char ch : s)
32
+ {
33
+ if (ch == ' \' ' )
34
+ {
35
+ result.append (" '\\ ''" );
36
+ }
37
+ else
38
+ {
39
+ result.push_back (ch);
40
+ }
41
+ }
42
+
43
+ result.push_back (' \' ' );
44
+ return result;
45
+ }
46
+
25
47
[[nodiscard]]
26
48
static bool Run (const char * program, char * argv[])
27
49
{
@@ -200,7 +222,7 @@ namespace s3d
200
222
201
223
bool LaunchFile (const FilePathView fileName)
202
224
{
203
- const std::string command = (" xdg-open ' " + fileName.narrow () + " ' " );
225
+ const std::string command = (" xdg-open " + detail::Escape ( fileName.narrow ()) );
204
226
205
227
return (std::system (command.c_str ()) == 0 );
206
228
}
@@ -227,7 +249,7 @@ namespace s3d
227
249
}
228
250
}
229
251
230
- const std::string command = (std::string (editor) + " ' " + fileName.narrow () + " ' " );
252
+ const std::string command = (std::string (editor) + " " + detail::Escape ( fileName.narrow ()) );
231
253
232
254
return (std::system (command.c_str ()) == 0 );
233
255
}
Original file line number Diff line number Diff line change 18
18
{
19
19
namespace detail
20
20
{
21
+ [[nodiscard]]
22
+ static std::string Escape (const std::string& s)
23
+ {
24
+ std::string result;
25
+ result.push_back (' \' ' );
26
+
27
+ for (char ch : s)
28
+ {
29
+ if (ch == ' \' ' )
30
+ {
31
+ result.append (" '\\ ''" );
32
+ }
33
+ else
34
+ {
35
+ result.push_back (ch);
36
+ }
37
+ }
38
+
39
+ result.push_back (' \' ' );
40
+ return result;
41
+ }
42
+
21
43
[[nodiscard]]
22
44
static bool MacOS_OpenURLInBrowser (const char * _url)
23
45
{
@@ -185,14 +207,14 @@ String DefaultLanguage()
185
207
186
208
bool LaunchFile (const FilePathView fileName)
187
209
{
188
- const std::string command = (" open ' " + FileSystem::NativePath (fileName) + " ' " );
210
+ const std::string command = (" open " + detail::Escape ( FileSystem::NativePath (fileName)) );
189
211
190
212
return (std::system (command.c_str ()) == 0 );
191
213
}
192
214
193
215
bool LaunchFileWithTextEditor (const FilePathView fileName)
194
216
{
195
- const std::string command = (" open -t ' " + FileSystem::NativePath (fileName) + " ' " );
217
+ const std::string command = (" open -t " + detail::Escape ( FileSystem::NativePath (fileName)) );
196
218
197
219
return (std::system (command.c_str ()) == 0 );
198
220
}
You can’t perform that action at this time.
0 commit comments