Compare commits

...

3 Commits

3 changed files with 31 additions and 6 deletions

View File

@ -1021,7 +1021,12 @@ 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>>
struct StringQuoteOptions
{
bool replaceNewlines = false;
};
template<StringQuoteOptions options = {}, 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;
@ -1029,8 +1034,28 @@ std::basic_string<TChar, TTraits, TAlloc> quoted(std::basic_string_view<TChar, T
result.push_back(TChar('"'));
for (const TChar chr : input)
{
if (chr == TChar('"') || chr == TChar('\\')) {
switch (chr)
{
case TChar('"'):
case TChar('\\'):
result.push_back(TChar('\\'));
break;
case TChar('\n'):
if constexpr (options.replaceNewlines)
{
result.push_back(TChar('\\'));
result.push_back(TChar('n'));
continue;
}
break;
case TChar('\r'):
if constexpr (options.replaceNewlines)
{
result.push_back(TChar('\\'));
result.push_back(TChar('r'));
continue;
}
break;
}
result.push_back(chr);
}
@ -1038,10 +1063,10 @@ std::basic_string<TChar, TTraits, TAlloc> quoted(std::basic_string_view<TChar, T
return result;
}
template<typename TChar, typename TTraits, typename TAlloc>
template<StringQuoteOptions options = {}, 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));
return quoted<options, TChar, TTraits, TAlloc>(std::basic_string_view(input));
}
} // namespace mijin

View File

@ -80,7 +80,7 @@ class FileSystemAdapter
public:
virtual ~FileSystemAdapter() = default;
[[deprecated("Will be removed ASAP")]]
[[deprecated("Will be removed ASAP, use getKnownFolder(KnownFolder::USER_HOME) from platform/folders.hpp instead.")]]
[[nodiscard]] virtual fs::path getHomeFolder() { return {}; } // TODO: get rid of this ...
[[nodiscard]] virtual std::vector<FileInfo> listFiles(const fs::path& folder) = 0;
[[nodiscard]] virtual FileInfo getFileInfo(const fs::path& file) = 0;

View File

@ -97,7 +97,7 @@ fs::path RelativeFileSystemAdapter<TWrapped>::appendPath(const fs::path& other)
else {
combinedPath /= other;
}
return combinedPath;
return combinedPath.lexically_normal();
}
namespace vfs_pipe