diff options
| author | Nobuyoshi Nakada <nobu@ruby-lang.org> | 2026-05-03 21:01:43 +0900 |
|---|---|---|
| committer | Nobuyoshi Nakada <nobu.nakada@gmail.com> | 2026-05-13 17:37:48 +0900 |
| commit | 516adc1f787a520d6331a3be91ffcded046e0d3d (patch) | |
| tree | 73cada877ad2af96cfbb6c85d2b8745055b877cd /pathname.c | |
| parent | e3cccd28ea7954d29a15e0fd2495febdaa5bc306 (diff) | |
pathname: Move has_trailing_separator? to pathname.c
Diffstat (limited to 'pathname.c')
| -rw-r--r-- | pathname.c | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/pathname.c b/pathname.c index 2a006b4899..f68dea0372 100644 --- a/pathname.c +++ b/pathname.c @@ -233,6 +233,21 @@ chop_basename(VALUE self, VALUE path) return rb_assoc_new(dir, basename); } +/* :nodoc: */ +/* has_trailing_separator?(path) -> bool */ +static VALUE +has_trailing_separator(VALUE self, VALUE path) +{ + long baselen, alllen = RSTRING_LEN(check_strpath(path)); + if (alllen <= 0) return Qfalse; + rb_encoding *enc = rb_enc_get(path); + const char *name = RSTRING_PTR(path); + const char *base = ruby_enc_find_basename(name, &baselen, &alllen, enc); + if (baselen < 1) return Qfalse; + if (baselen == 1 && isdirsep(*base)) return Qfalse; + return RBOOL(base + alllen < RSTRING_END(path)); +} + #include "pathname_builtin.rbinc" static void init_ids(void); @@ -260,6 +275,7 @@ InitVM_pathname(void) rb_define_private_method(rb_cPathname, "has_separator?", has_separator_p, 1); rb_define_private_method(rb_cPathname, "chop_basename", chop_basename, 1); + rb_define_private_method(rb_cPathname, "has_trailing_separator?", has_trailing_separator, 1); rb_provide("pathname.so"); } |
