[Mlir-commits] [mlir] [mlir][Pass] Handle escaped pipline option values (PR #97667)

Matthias Springer llvmlistbot at llvm.org
Thu Jul 4 12:26:34 PDT 2024


================
@@ -60,6 +60,20 @@ template <typename ParserT>
 static void printOptionValue(raw_ostream &os, const bool &value) {
   os << (value ? StringRef("true") : StringRef("false"));
 }
+template <typename ParserT>
+static void printOptionValue(raw_ostream &os, const std::string &str) {
+  // Check if the string needs to be escaped before writing it to the ostream.
+  const size_t spaceIndex = str.find_first_of(' ');
+  const size_t escapeIndex =
+      std::min({str.find_first_of('{'), str.find_first_of('\''),
+                str.find_first_of('"')});
+  const bool requiresEscape = spaceIndex < escapeIndex;
----------------
matthias-springer wrote:

What happens if the string has no space but contains `"`?

https://github.com/llvm/llvm-project/pull/97667


More information about the Mlir-commits mailing list