mirror of
https://github.com/ruby/ruby.git
synced 2025-08-24 21:44:30 +02:00

(https://github.com/ruby/strscan/pull/126)
Split off from https://github.com/ruby/ruby/pull/12322
9bee37e0f5
19 lines
468 B
Markdown
19 lines
468 B
Markdown
call-seq:
|
|
charpos -> character_position
|
|
|
|
Returns the [character position][7] (initially zero),
|
|
which may be different from the [byte position][2]
|
|
given by method #pos:
|
|
|
|
```rb
|
|
scanner = StringScanner.new(HIRAGANA_TEXT)
|
|
scanner.string # => "こんにちは"
|
|
scanner.getch # => "こ" # 3-byte character.
|
|
scanner.getch # => "ん" # 3-byte character.
|
|
put_situation(scanner)
|
|
# Situation:
|
|
# pos: 6
|
|
# charpos: 2
|
|
# rest: "にちは"
|
|
# rest_size: 9
|
|
```
|