/* Python brace format strings.
- Copyright (C) 2004-2024 Free Software Foundation, Inc.
+ Copyright (C) 2004-2025 Free Software Foundation, Inc.
Written by Daiki Ueno <ueno@gnu.org>, 2013.
This program is free software: you can redistribute it and/or modify
if (!parse_named_field (spec, &format, translated, fdi, invalid_reason)
&& !parse_numeric_field (spec, &format, translated, fdi, invalid_reason))
{
- *invalid_reason =
- xasprintf (_("In the directive number %u, '%c' cannot start a field name."),
- spec->directives, *format);
- FDI_SET (format, FMTDIR_ERROR);
+ if (*format == '\0')
+ {
+ *invalid_reason = INVALID_UNTERMINATED_DIRECTIVE ();
+ FDI_SET (format - 1, FMTDIR_ERROR);
+ }
+ else
+ {
+ *invalid_reason =
+ (c_isprint (*format)
+ ? xasprintf (_("In the directive number %u, '%c' cannot start a field name."),
+ spec->directives, *format)
+ : xasprintf (_("In the directive number %u, a field name starts with a character that is not alphanumerical or underscore."),
+ spec->directives));
+ FDI_SET (format, FMTDIR_ERROR);
+ }
return false;
}
if (!parse_named_field (spec, &format, translated, fdi,
invalid_reason))
{
- *invalid_reason =
- xasprintf (_("In the directive number %u, '%c' cannot start a getattr argument."),
- spec->directives, *format);
- FDI_SET (format, FMTDIR_ERROR);
+ if (*format == '\0')
+ {
+ *invalid_reason = INVALID_UNTERMINATED_DIRECTIVE ();
+ FDI_SET (format - 1, FMTDIR_ERROR);
+ }
+ else
+ {
+ *invalid_reason =
+ (c_isprint (*format)
+ ? xasprintf (_("In the directive number %u, '%c' cannot start a getattr argument."),
+ spec->directives, *format)
+ : xasprintf (_("In the directive number %u, a getattr argument starts with a character that is not alphabetical or underscore."),
+ spec->directives));
+ FDI_SET (format, FMTDIR_ERROR);
+ }
return false;
}
}
&& !parse_numeric_field (spec, &format, translated, fdi,
invalid_reason))
{
- *invalid_reason =
- xasprintf (_("In the directive number %u, '%c' cannot start a getitem argument."),
- spec->directives, *format);
- FDI_SET (format, FMTDIR_ERROR);
+ if (*format == '\0')
+ {
+ *invalid_reason = INVALID_UNTERMINATED_DIRECTIVE ();
+ FDI_SET (format - 1, FMTDIR_ERROR);
+ }
+ else
+ {
+ *invalid_reason =
+ (c_isprint (*format)
+ ? xasprintf (_("In the directive number %u, '%c' cannot start a getitem argument."),
+ spec->directives, *format)
+ : xasprintf (_("In the directive number %u, a getitem argument starts with a character that is not alphanumerical or underscore."),
+ spec->directives));
+ FDI_SET (format, FMTDIR_ERROR);
+ }
return false;
}
*invalid_reason =
xasprintf (_("In the directive number %u, there is an unterminated getitem argument."),
spec->directives);
- FDI_SET (format, FMTDIR_ERROR);
+ FDI_SET (format - 1, FMTDIR_ERROR);
return false;
}
format++;
if (c1 == '\0')
{
*invalid_reason =
- xasprintf (_("In the directive number %u, there is an unterminated format directive."),
+ xasprintf (_("The directive number %u is unterminated."),
spec->directives);
- FDI_SET (format, FMTDIR_ERROR);
+ FDI_SET (format - 1, FMTDIR_ERROR);
return false;
}
if (*format != '}')
{
*invalid_reason =
- xasprintf (_("In the directive number %u, there is an unterminated format directive."),
+ xasprintf (_("The directive number %u is unterminated."),
spec->directives);
- FDI_SET (format, FMTDIR_ERROR);
+ FDI_SET (format - 1, FMTDIR_ERROR);
return false;
}
/* Format strings.
- Copyright (C) 2001-2024 Free Software Foundation, Inc.
+ Copyright (C) 2001-2025 Free Software Foundation, Inc.
Written by Bruno Haible <haible@clisp.cons.org>, 2001.
This program is free software: you can redistribute it and/or modify
/* Macro for use inside a parser:
Sets an indicator at the position corresponding to PTR.
- Assumes local variables 'fdi' and 'format_start' are defined. */
+ Assumes local variables 'fdi' and 'format_start' are defined.
+ *PTR must not be the terminating NUL character; if it might be NUL, you need
+ to pass PTR - 1 instead of PTR. */
#define FDI_SET(ptr, flag) \
if (fdi != NULL) \
fdi[(ptr) - format_start] |= (flag)/*;*/