From 4d19752964aacd0c3de24c1e3c9283d2de8255d8 Mon Sep 17 00:00:00 2001
From: Patrick Wuttke
Date: Sat, 30 Aug 2025 00:31:27 +0200
Subject: [PATCH] Added quoted() string helper.
---
source/mijin/util/string.hpp | 23 +++++++++++++++++++++++
1 file changed, 23 insertions(+)
diff --git a/source/mijin/util/string.hpp b/source/mijin/util/string.hpp
index 42f1365..f8fd9c1 100644
--- a/source/mijin/util/string.hpp
+++ b/source/mijin/util/string.hpp
@@ -1020,6 +1020,29 @@ bool convertStringType(const TFrom* strFrom, std::basic_string(strFrom), outString);
}
+
+template>
+std::basic_string quoted(std::basic_string_view input)
+{
+ std::basic_string 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
+std::basic_string quoted(const std::basic_string& input)
+{
+ return quoted(std::basic_string_view(input));
+}
} // namespace mijin
#endif // !defined(MIJIN_UTIL_STRING_HPP_INCLUDED)