On 2025-12-28 15:13, Tom Tromey wrote:
> All callers of generic_emit_char print the quotes around the
> character, then pass the quote character to the function. It seemed
> better to just have generic_emit_char print the quotes itself.
I don't know if this is affected by the rest of the series, but
generic_emit_char always receives a single quote as the quoter, so that
parameter could be removed. The function could still use a variable to
keep the "quoter" name, like:
constexpr int quoter = '\'';
Still, this patch LGTM.
Approved-By: Simon Marchi <simon.marchi@efficios.com>
Simon
@@ -160,9 +160,7 @@ language_defn::printchar (int c, struct type *type,
break;
}
- gdb_putc ('\'', stream);
generic_emit_char (c, type, stream, '\'', encoding);
- gdb_putc ('\'', stream);
}
/* Print the character string STRING, printing at most LENGTH
@@ -161,10 +161,8 @@ class f_language : public language_defn
void printchar (int ch, struct type *chtype,
struct ui_file *stream) const override
{
- gdb_puts ("'", stream);
const char *encoding = get_encoding (chtype);
generic_emit_char (ch, chtype, stream, '\'', encoding);
- gdb_puts ("'", stream);
}
/* See language.h. */
@@ -1774,11 +1774,14 @@ void
rust_language::printchar (int ch, struct type *chtype,
struct ui_file *stream) const
{
- fputs_filtered ("'", stream);
if (!rust_chartype_p (chtype))
- generic_emit_char (ch, chtype, stream, '\'',
- target_charset (chtype->arch ()));
- else if (ch == '\\')
+ {
+ generic_emit_char (ch, chtype, stream, '\'',
+ target_charset (chtype->arch ()));
+ return;
+ }
+ gdb_puts ("'", stream);
+ if (ch == '\\')
gdb_printf (stream, "\\%c", ch);
else if (ch == '\n')
gdb_puts ("\\n", stream);
@@ -2281,6 +2281,7 @@ generic_emit_char (int c, struct type *type, struct ui_file *stream,
c_buf = (gdb_byte *) alloca (type->length ());
pack_long (c_buf, type, c);
+ gdb_putc (quoter, stream);
wchar_iterator iter (c_buf, type->length (), encoding, type->length ());
/* This holds the printable form of the wchar_t data. */
@@ -2340,6 +2341,7 @@ generic_emit_char (int c, struct type *type, struct ui_file *stream,
obstack_1grow (&output, '\0');
gdb_puts ((const char *) obstack_base (&output), stream);
+ gdb_putc (quoter, stream);
}
/* Return the repeat count of the next character/byte in ITER,