aboutsummaryrefslogtreecommitdiffstats
path: root/parse.y
diff options
context:
space:
mode:
authorNobuyoshi Nakada <nobu@ruby-lang.org>2023-12-01 22:16:10 +0900
committerNobuyoshi Nakada <nobu@ruby-lang.org>2023-12-02 02:41:39 +0900
commitadd0ab07e8b5e8f271e7bffa21c650c38a46c7db (patch)
tree72cbdd41a487a7b3cca4bb66f4e4d16261342aa7 /parse.y
parent6e2b10d45653ed96529aafe981eae7e920110461 (diff)
downloadruby-add0ab07e8b5e8f271e7bffa21c650c38a46c7db.tar.gz
Extract `end_with_newline_p`
Diffstat (limited to 'parse.y')
-rw-r--r--parse.y8
1 files changed, 7 insertions, 1 deletions
diff --git a/parse.y b/parse.y
index 668e6091ac..063e28b918 100644
--- a/parse.y
+++ b/parse.y
@@ -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)
{
@@ -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;
}