Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion compile.c
Original file line number Diff line number Diff line change
Expand Up @@ -12926,6 +12926,9 @@ ibf_load_code(const struct ibf_load *load, rb_iseq_t *iseq, ibf_offset_t bytecod
struct rb_call_data *cd_entries = load_body->call_data;
int ic_index = 0;

load_body->iseq_encoded = code;
load_body->iseq_size = 0;

iseq_bits_t * mark_offset_bits;

iseq_bits_t tmp[1] = {0};
Expand Down Expand Up @@ -13057,7 +13060,6 @@ ibf_load_code(const struct ibf_load *load, rb_iseq_t *iseq, ibf_offset_t bytecod
}
}

load_body->iseq_encoded = code;
load_body->iseq_size = code_index;

if (ISEQ_MBITS_BUFLEN(load_body->iseq_size) == 1) {
Expand Down
140 changes: 0 additions & 140 deletions doc/string.rb
Original file line number Diff line number Diff line change
Expand Up @@ -159,146 +159,6 @@
# - #rstrip, #rstrip!: Strip trailing whitespace.
# - #strip, #strip!: Strip leading and trailing whitespace.
#
# == +String+ Slices
#
# A _slice_ of a string is a substring selected by certain criteria.
#
# These instance methods utilize slicing:
#
# - String#[] (aliased as String#slice): Returns a slice copied from +self+.
# - String#[]=: Mutates +self+ with the slice replaced.
# - String#slice!: Mutates +self+ with the slice removed and returns the removed slice.
#
# Each of the above methods takes arguments that determine the slice
# to be copied or replaced.
#
# The arguments have several forms.
# For a string +string+, the forms are:
#
# - <tt>string[index]</tt>
# - <tt>string[start, length]</tt>
# - <tt>string[range]</tt>
# - <tt>string[regexp, capture = 0]</tt>
# - <tt>string[substring]</tt>
#
# <b><tt>string[index]</tt></b>
#
# When a non-negative integer argument +index+ is given,
# the slice is the 1-character substring found in +self+ at character offset +index+:
#
# 'bar'[0] # => "b"
# 'bar'[2] # => "r"
# 'bar'[20] # => nil
# 'тест'[2] # => "с"
# 'こんにちは'[4] # => "は"
#
# When a negative integer +index+ is given,
# the slice begins at the offset given by counting backward from the end of +self+:
#
# 'bar'[-3] # => "b"
# 'bar'[-1] # => "r"
# 'bar'[-20] # => nil
#
# <b><tt>string[start, length]</tt></b>
#
# When non-negative integer arguments +start+ and +length+ are given,
# the slice begins at character offset +start+, if it exists,
# and continues for +length+ characters, if available:
#
# 'foo'[0, 2] # => "fo"
# 'тест'[1, 2] # => "ес"
# 'こんにちは'[2, 2] # => "にち"
# # Zero length.
# 'foo'[2, 0] # => ""
# # Length not entirely available.
# 'foo'[1, 200] # => "oo"
# # Start out of range.
# 'foo'[4, 2] # => nil
#
# Special case: if +start+ equals the length of +self+,
# the slice is a new empty string:
#
# 'foo'[3, 2] # => ""
# 'foo'[3, 200] # => ""
#
# When a negative +start+ and non-negative +length+ are given,
# the slice begins by counting backward from the end of +self+,
# and continues for +length+ characters, if available:
#
# 'foo'[-2, 2] # => "oo"
# 'foo'[-2, 200] # => "oo"
# # Start out of range.
# 'foo'[-4, 2] # => nil
#
# When a negative +length+ is given, there is no slice:
#
# 'foo'[1, -1] # => nil
# 'foo'[-2, -1] # => nil
#
# <b><tt>string[range]</tt></b>
#
# When a Range argument +range+ is given,
# it creates a substring of +string+ using the indices in +range+.
# The slice is then determined as above:
#
# 'foo'[0..1] # => "fo"
# 'foo'[0, 2] # => "fo"
#
# 'foo'[2...2] # => ""
# 'foo'[2, 0] # => ""
#
# 'foo'[1..200] # => "oo"
# 'foo'[1, 200] # => "oo"
#
# 'foo'[4..5] # => nil
# 'foo'[4, 2] # => nil
#
# 'foo'[-4..-3] # => nil
# 'foo'[-4, 2] # => nil
#
# 'foo'[3..4] # => ""
# 'foo'[3, 2] # => ""
#
# 'foo'[-2..-1] # => "oo"
# 'foo'[-2, 2] # => "oo"
#
# 'foo'[-2..197] # => "oo"
# 'foo'[-2, 200] # => "oo"
#
# <b><tt>string[regexp, capture = 0]</tt></b>
#
# When the Regexp argument +regexp+ is given,
# and the +capture+ argument is <tt>0</tt>,
# the slice is the first matching substring found in +self+:
#
# 'foo'[/o/] # => "o"
# 'foo'[/x/] # => nil
# s = 'hello there'
# s[/[aeiou](.)\1/] # => "ell"
# s[/[aeiou](.)\1/, 0] # => "ell"
#
# If the argument +capture+ is provided and not <tt>0</tt>,
# it should be either a capture group index (integer)
# or a capture group name (String or Symbol);
# the slice is the specified capture
# (see {Groups and Captures}[rdoc-ref:Regexp@Groups+and+Captures]):
#
# s = 'hello there'
# s[/[aeiou](.)\1/, 1] # => "l"
# s[/(?<vowel>[aeiou])(?<non_vowel>[^aeiou])/, "non_vowel"] # => "l"
# s[/(?<vowel>[aeiou])(?<non_vowel>[^aeiou])/, :vowel] # => "e"
#
# If an invalid capture group index is given, there is no slice.
# If an invalid capture group name is given, +IndexError+ is raised.
#
# <b><tt>string[substring]</tt></b>
#
# When the single +String+ argument +substring+ is given,
# it returns the substring from +self+ if found, otherwise +nil+:
#
# 'foo'['oo'] # => "oo"
# 'foo'['xx'] # => nil
#
# == What's Here
#
# First, what's elsewhere. Class +String+:
Expand Down
98 changes: 98 additions & 0 deletions doc/string/aref.rdoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
Returns the substring of +self+ specified by the arguments.

<b>Form <tt>self[index]</tt></b>

With non-negative integer argument +index+ given,
returns the 1-character substring found in self at character offset index:

'hello'[0] # => "h"
'hello'[4] # => "o"
'hello'[5] # => nil
'тест'[2] # => "с"
'こんにちは'[4] # => "は"

With negative integer argument +index+ given,
counts backward from the end of +self+:

'hello'[-1] # => "o"
'hello'[-5] # => "h"
'hello'[-6] # => nil

<b>Form <tt>self[start, length]</tt></b>

With integer arguments +start+ and +length+ given,
returns a substring of size +length+ characters (as available)
beginning at character offset specified by +start+.

If argument +start+ is non-negative,
the offset is +start+:

'hello'[0, 1] # => "h"
'hello'[0, 5] # => "hello"
'hello'[0, 6] # => "hello"
'hello'[2, 3] # => "llo"
'hello'[2, 0] # => ""
'hello'[2, -1] # => nil

If argument +start+ is negative,
counts backward from the end of +self+:

'hello'[-1, 1] # => "o"
'hello'[-5, 5] # => "hello"
'hello'[-1, 0] # => ""
'hello'[-6, 5] # => nil

Special case: if +start+ equals the length of +self+,
returns a new empty string:

'hello'[5, 3] # => ""

<b>Form <tt>self[range]</tt></b>

With Range argument +range+ given,
forms substring <tt>self[range.start, range.size]</tt>:

'hello'[0..2] # => "hel"
'hello'[0, 3] # => "hel"

'hello'[0...2] # => "he"
'hello'[0, 2] # => "he"

'hello'[0, 0] # => ""
'hello'[0...0] # => ""

<b>Form <tt>self[regexp, capture = 0]</tt></b>

With Regexp argument +regexp+ given and +capture+ as zero,
searches for a matching substring in +self+;
updates {Regexp-related global variables}[rdoc-ref:Regexp@Global+Variables]:

'hello'[/ell/] # => "ell"
'hello'[/l+/] # => "ll"
'hello'[//] # => ""
'hello'[/nosuch/] # => nil

With +capture+ as a positive integer +n+,
returns the +n+th matched group:

'hello'[/(h)(e)(l+)(o)/] # => "hello"
'hello'[/(h)(e)(l+)(o)/, 1] # => "h"
$1 # => "h"
'hello'[/(h)(e)(l+)(o)/, 2] # => "e"
$2 # => "e"
'hello'[/(h)(e)(l+)(o)/, 3] # => "ll"
'hello'[/(h)(e)(l+)(o)/, 4] # => "o"
'hello'[/(h)(e)(l+)(o)/, 5] # => nil

<b>Form <tt>self[substring]</tt></b>

With string argument +substring+ given,
returns the matching substring of +self+, if found:

'hello'['ell'] # => "ell"
'hello'[''] # => ""
'hello'['nosuch'] # => nil
'тест'['ес'] # => "ес"
'こんにちは'['んにち'] # => "んにち"

Related: see {Converting to New String}[rdoc-ref:String@Converting+to+New+String].
Loading