Skip to content

Commit

Permalink
Extract end_with_newline_p
Browse files Browse the repository at this point in the history
  • Loading branch information
nobu committed Dec 1, 2023
1 parent 6e2b10d commit add0ab0
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion parse.y
Expand Up @@ -562,6 +562,12 @@ static void numparam_name(struct parser_params *p, ID id);
#define TOK_INTERN() intern_cstr(tok(p), toklen(p), p->enc)
#define VALID_SYMNAME_P(s, l, enc, type) (rb_enc_symname_type(s, l, enc, (1U<<(type))) == (int)(type))

static inline bool
end_with_newline_p(struct parser_params *p, VALUE str)
{
return RSTRING_LEN(str) > 0 && RSTRING_END(str)[-1] == '\n';
}

static void
pop_pvtbl(struct parser_params *p, st_table *tbl)
{
Expand Down Expand Up @@ -15965,7 +15971,7 @@ rb_parser_printf(struct parser_params *p, const char *fmt, ...)
va_start(ap, fmt);
rb_str_vcatf(mesg, fmt, ap);
va_end(ap);
if (RSTRING_END(mesg)[-1] == '\n') {
if (end_with_newline_p(p, mesg)) {
rb_io_write(p->debug_output, mesg);
p->debug_buffer = Qnil;
}
Expand Down

0 comments on commit add0ab0

Please sign in to comment.