Added quoted() string helper.
This commit is contained in:
parent
0e988a4d9e
commit
4d19752964
@ -1020,6 +1020,29 @@ bool convertStringType(const TFrom* strFrom, std::basic_string<TTo, TToTraits, T
|
||||
{
|
||||
return convertStringType(std::basic_string_view<TFrom>(strFrom), outString);
|
||||
}
|
||||
|
||||
template<typename TChar, typename TTraits, typename TAlloc = MIJIN_DEFAULT_ALLOCATOR<TChar>>
|
||||
std::basic_string<TChar, TTraits, TAlloc> quoted(std::basic_string_view<TChar, TTraits> input)
|
||||
{
|
||||
std::basic_string<TChar, TTraits> result;
|
||||
result.reserve(input.size() + 2);
|
||||
result.push_back(TChar('"'));
|
||||
for (const TChar chr : input)
|
||||
{
|
||||
if (chr == TChar('"') || chr == TChar('\\')) {
|
||||
result.push_back(TChar('\\'));
|
||||
}
|
||||
result.push_back(chr);
|
||||
}
|
||||
result.push_back(TChar('"'));
|
||||
return result;
|
||||
}
|
||||
|
||||
template<typename TChar, typename TTraits, typename TAlloc>
|
||||
std::basic_string<TChar, TTraits, TAlloc> quoted(const std::basic_string<TChar, TTraits, TAlloc>& input)
|
||||
{
|
||||
return quoted<TChar, TTraits, TAlloc>(std::basic_string_view(input));
|
||||
}
|
||||
} // namespace mijin
|
||||
|
||||
#endif // !defined(MIJIN_UTIL_STRING_HPP_INCLUDED)
|
||||
|
Loading…
x
Reference in New Issue
Block a user