mirror of
https://github.com/ruby/ruby.git
synced 2026-01-27 20:44:20 +00:00
(https://github.com/ruby/strscan/pull/126) Split off from https://github.com/ruby/ruby/pull/12322 https://github.com/ruby/strscan/commit/9bee37e0f5
564 B
564 B
call-seq: pos = n -> n pointer = n -> n
Sets the [byte position][2] and the [character position][11];
returns n.
Does not affect [match values][9].
For non-negative n, sets the position to n:
scanner = StringScanner.new(HIRAGANA_TEXT)
scanner.string # => "こんにちは"
scanner.pos = 3 # => 3
scanner.rest # => "んにちは"
scanner.charpos # => 1
For negative n, counts from the end of the [stored string][1]:
scanner.pos = -9 # => -9
scanner.pos # => 6
scanner.rest # => "にちは"
scanner.charpos # => 2