22 lines
466 B
C++
22 lines
466 B
C++
#pragma once
|
|
#include <string>
|
|
#include <string_view>
|
|
|
|
namespace ks
|
|
{
|
|
inline std::wstring quoteWindowsArgument(std::wstring_view value)
|
|
{
|
|
std::wstring quoted=L"\"";
|
|
size_t slashes=0;
|
|
for(const auto character:value)
|
|
{
|
|
if(character==L'\\') {++slashes;continue;}
|
|
quoted.append(character==L'"'?slashes*2+1:slashes,L'\\');
|
|
slashes=0;
|
|
quoted+=character;
|
|
}
|
|
quoted.append(slashes*2,L'\\');
|
|
return quoted+L'"';
|
|
}
|
|
}
|