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 | |
| parent | e3cccd28ea7954d29a15e0fd2495febdaa5bc306 (diff) | |
pathname: Move has_trailing_separator? to pathname.c
| -rw-r--r-- | pathname.c | 16 | ||||
| -rw-r--r-- | pathname_builtin.rb | 11 |
2 files changed, 16 insertions, 11 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"); } diff --git a/pathname_builtin.rb b/pathname_builtin.rb index 0885aa3085..2ba598d3ee 100644 --- a/pathname_builtin.rb +++ b/pathname_builtin.rb @@ -500,17 +500,6 @@ class Pathname end private :cleanpath_aggressive - # has_trailing_separator?(path) -> bool - def has_trailing_separator?(path) # :nodoc: - if r = chop_basename(path) - pre, basename = r - pre.length + basename.length < path.length - else - false - end - end - private :has_trailing_separator? - # add_trailing_separator(path) -> path def add_trailing_separator(path) # :nodoc: if File.basename(path + 'a') == 'a' |
