summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--string.c77
-rw-r--r--string.rb1
2 files changed, 51 insertions, 27 deletions
@@ -4940,43 +4940,66 @@ str_ensure_byte_pos(VALUE str, long pos)
/*
* call-seq:
- * byteindex(substring, offset = 0) -> integer or nil
- * byteindex(regexp, offset = 0) -> integer or nil
*
- * Returns the Integer byte-based index of the first occurrence of the given +substring+,
- * or +nil+ if none found:
*
- * 'foo'.byteindex('f') # => 0
- * 'foo'.byteindex('o') # => 1
- * 'foo'.byteindex('oo') # => 1
- * 'foo'.byteindex('ooo') # => nil
*
- * Returns the Integer byte-based index of the first match for the given Regexp +regexp+,
- * or +nil+ if none found:
*
- * 'foo'.byteindex(/f/) # => 0
- * 'foo'.byteindex(/o/) # => 1
- * 'foo'.byteindex(/oo/) # => 1
- * 'foo'.byteindex(/ooo/) # => nil
*
- * Integer argument +offset+, if given, specifies the byte-based position in the
- * string to begin the search:
*
- * 'foo'.byteindex('o', 1) # => 1
- * 'foo'.byteindex('o', 2) # => 2
- * 'foo'.byteindex('o', 3) # => nil
*
- * If +offset+ is negative, counts backward from the end of +self+:
*
- * 'foo'.byteindex('o', -1) # => 2
- * 'foo'.byteindex('o', -2) # => 1
- * 'foo'.byteindex('o', -3) # => 1
- * 'foo'.byteindex('o', -4) # => nil
*
- * If +offset+ does not land on character (codepoint) boundary, +IndexError+ is
- * raised.
*
- * Related: String#index, String#byterindex.
*/
static VALUE
@@ -342,6 +342,7 @@
#
# - #=~: Returns the index of the first substring that matches a given
# Regexp or other object; returns +nil+ if no match is found.
# - #index: Returns the index of the _first_ occurrence of a given substring;
# returns +nil+ if none found.
# - #rindex: Returns the index of the _last_ occurrence of a given substring;