diff options
-rw-r--r-- | doc/string/delete_prefix.rdoc | 8 | ||||
-rw-r--r-- | doc/string/delete_suffix.rdoc | 8 | ||||
-rw-r--r-- | doc/string/end_with_p.rdoc | 11 | ||||
-rw-r--r-- | doc/string/start_with_p.rdoc | 18 | ||||
-rw-r--r-- | string.c | 48 |
5 files changed, 59 insertions, 34 deletions
diff --git a/doc/string/delete_prefix.rdoc b/doc/string/delete_prefix.rdoc new file mode 100644 index 0000000000..fa9d8abd38 --- /dev/null +++ b/doc/string/delete_prefix.rdoc @@ -0,0 +1,8 @@ +Returns a copy of +self+ with leading substring <tt>prefix</tt> removed: + + 'hello'.delete_prefix('hel') # => "lo" + 'hello'.delete_prefix('llo') # => "hello" + 'тест'.delete_prefix('те') # => "ст" + 'こんにちは'.delete_prefix('こん') # => "にちは" + +Related: String#delete_prefix!, String#delete_suffix. diff --git a/doc/string/delete_suffix.rdoc b/doc/string/delete_suffix.rdoc new file mode 100644 index 0000000000..4862b725cf --- /dev/null +++ b/doc/string/delete_suffix.rdoc @@ -0,0 +1,8 @@ +Returns a copy of +self+ with trailing substring <tt>suffix</tt> removed: + + 'hello'.delete_suffix('llo') # => "he" + 'hello'.delete_suffix('hel') # => "hello" + 'тест'.delete_suffix('ст') # => "те" + 'こんにちは'.delete_suffix('ちは') # => "こんに" + +Related: String#delete_suffix!, String#delete_prefix. diff --git a/doc/string/end_with_p.rdoc b/doc/string/end_with_p.rdoc new file mode 100644 index 0000000000..f959cf7aaa --- /dev/null +++ b/doc/string/end_with_p.rdoc @@ -0,0 +1,11 @@ +Returns whether +self+ ends with any of the given +strings+. + +Returns +true+ if any given string matches the end, +false+ otherwise: + + 'hello'.end_with?('ello') #=> true + 'hello'.end_with?('heaven', 'ello') #=> true + 'hello'.end_with?('heaven', 'paradise') #=> false + 'тест'.end_with?('т') # => true + 'こんにちは'.end_with?('は') # => true + +Related: String#start_with?. diff --git a/doc/string/start_with_p.rdoc b/doc/string/start_with_p.rdoc new file mode 100644 index 0000000000..1cfed76296 --- /dev/null +++ b/doc/string/start_with_p.rdoc @@ -0,0 +1,18 @@ +Returns whether +self+ starts with any of the given +string_or_regexp+. + +Matches patterns against the beginning of+self+. +For each given +string_or_regexp+, the pattern is: + +- +string_or_regexp+ itself, if it is a Regexp. +- <tt>Regexp.quote(string_or_regexp)</tt>, if +string_or_regexp+ is a string. + +Returns +true+ if any pattern matches the beginning, +false+ otherwise: + + 'hello'.start_with?('hell') # => true + 'hello'.start_with?(/H/i) # => true + 'hello'.start_with?('heaven', 'hell') # => true + 'hello'.start_with?('heaven', 'paradise') # => false + 'тест'.start_with?('т') # => true + 'こんにちは'.start_with?('こ') # => true + +Related: String#end_with?. @@ -10510,17 +10510,10 @@ rb_str_rpartition(VALUE str, VALUE sep) /* * call-seq: - * str.start_with?([prefixes]+) -> true or false + * start_with?(*string_or_regexp) -> true or false * - * Returns true if +str+ starts with one of the +prefixes+ given. - * Each of the +prefixes+ should be a String or a Regexp. - * - * "hello".start_with?("hell") #=> true - * "hello".start_with?(/H/i) #=> true + * :include: doc/string/start_with_p.rdoc * - * # returns true if one of the prefixes matches. - * "hello".start_with?("heaven", "hell") #=> true - * "hello".start_with?("heaven", "paradise") #=> false */ static VALUE @@ -10547,15 +10540,10 @@ rb_str_start_with(int argc, VALUE *argv, VALUE str) /* * call-seq: - * str.end_with?([suffixes]+) -> true or false + * end_with?(*strings) -> true or false * - * Returns true if +str+ ends with one of the +suffixes+ given. + * :include: doc/string/end_with_p.rdoc * - * "hello".end_with?("ello") #=> true - * - * # returns true if one of the +suffixes+ matches. - * "hello".end_with?("heaven", "ello") #=> true - * "hello".end_with?("heaven", "paradise") #=> false */ static VALUE @@ -10616,13 +10604,11 @@ deleted_prefix_length(VALUE str, VALUE prefix) /* * call-seq: - * str.delete_prefix!(prefix) -> self or nil + * delete_prefix!(prefix) -> self or nil * - * Deletes leading <code>prefix</code> from <i>str</i>, returning - * <code>nil</code> if no change was made. + * Like String#delete_prefix, except that +self+ is modified in place. + * Returns +self+ if the prefix is removed, +nil+ otherwise. * - * "hello".delete_prefix!("hel") #=> "lo" - * "hello".delete_prefix!("llo") #=> nil */ static VALUE @@ -10639,12 +10625,10 @@ rb_str_delete_prefix_bang(VALUE str, VALUE prefix) /* * call-seq: - * str.delete_prefix(prefix) -> new_str + * delete_prefix(prefix) -> new_string * - * Returns a copy of <i>str</i> with leading <code>prefix</code> deleted. + * :include: doc/string/delete_prefix.rdoc * - * "hello".delete_prefix("hel") #=> "lo" - * "hello".delete_prefix("llo") #=> "hello" */ static VALUE @@ -10694,13 +10678,11 @@ deleted_suffix_length(VALUE str, VALUE suffix) /* * call-seq: - * str.delete_suffix!(suffix) -> self or nil + * delete_suffix!(suffix) -> self or nil * - * Deletes trailing <code>suffix</code> from <i>str</i>, returning - * <code>nil</code> if no change was made. + * Like String#delete_suffix, except that +self+ is modified in place. + * Returns +self+ if the suffix is removed, +nil+ otherwise. * - * "hello".delete_suffix!("llo") #=> "he" - * "hello".delete_suffix!("hel") #=> nil */ static VALUE @@ -10725,12 +10707,10 @@ rb_str_delete_suffix_bang(VALUE str, VALUE suffix) /* * call-seq: - * str.delete_suffix(suffix) -> new_str + * str.delete_suffix(suffix) -> new_string * - * Returns a copy of <i>str</i> with trailing <code>suffix</code> deleted. + * :include: doc/string/delete_suffix.rdoc * - * "hello".delete_suffix("llo") #=> "he" - * "hello".delete_suffix("hel") #=> "hello" */ static VALUE |