[Lldb-commits] [lldb] [lldb] Fix compile Python f-strings to improved `@fmt` (PR #232997)
Dave Lee via lldb-commits
lldb-commits at lists.llvm.org
Tue Oct 20 10:52:35 PDT 2026
================
@@ -97,9 +97,66 @@ std::string toString(const FormatterBytecode::DataStack &data) {
namespace FormatterBytecode {
+/// Check a version 2 format string, and remove the layout and options of each
+/// replacement. The format string may contain literal text, escaped braces
+/// ("{{"), and automatically indexed replacements:
+///
+/// "{" [ "," layout ] [ ":" options ] "}"
+///
+/// Explicit indexes are not supported. Layouts and options are accepted, so
+/// that support for them can be added without changing the ABI, but they are
+/// currently ignored. The result contains only literal text, escaped braces,
+/// and "{}", so malformed format strings never reach formatv.
+static llvm::Expected<std::string> SanitizeFormatString(llvm::StringRef fmt) {
+ std::string result;
+ size_t i = 0;
+ while (i < fmt.size()) {
+ if (fmt[i] != '{') {
+ result += fmt[i++];
+ continue;
+ }
+ if (fmt.drop_front(i).starts_with("{{")) {
+ result += "{{";
+ i += 2;
+ continue;
+ }
+ size_t start = i++;
+ // Skip the layout, which ends at the options or the closing brace.
+ if (i < fmt.size() && fmt[i] == ',') {
+ ++i;
+ while (i < fmt.size() && !llvm::StringRef("{}:").contains(fmt[i]))
----------------
kastiglione wrote:
Updated this code to no longer use an index.
https://github.com/llvm/llvm-project/pull/232997
More information about the lldb-commits
mailing list