diff options
author | Nobuyoshi Nakada <nobu@ruby-lang.org> | 2023-12-01 22:16:10 +0900 |
---|---|---|
committer | Nobuyoshi Nakada <nobu@ruby-lang.org> | 2023-12-02 02:41:39 +0900 |
commit | add0ab07e8b5e8f271e7bffa21c650c38a46c7db (patch) | |
tree | 72cbdd41a487a7b3cca4bb66f4e4d16261342aa7 /parse.y | |
parent | 6e2b10d45653ed96529aafe981eae7e920110461 (diff) | |
download | ruby-add0ab07e8b5e8f271e7bffa21c650c38a46c7db.tar.gz |
Extract `end_with_newline_p`
Diffstat (limited to 'parse.y')
-rw-r--r-- | parse.y | 8 |
1 files changed, 7 insertions, 1 deletions
@@ -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; } |