summaryrefslogtreecommitdiff
path: root/doc/strscan/methods
diff options
context:
space:
mode:
Diffstat (limited to 'doc/strscan/methods')
-rw-r--r--doc/strscan/methods/get_byte.md7
-rw-r--r--doc/strscan/methods/get_charpos.md5
-rw-r--r--doc/strscan/methods/get_pos.md5
-rw-r--r--doc/strscan/methods/getch.md9
-rw-r--r--doc/strscan/methods/scan.md7
-rw-r--r--doc/strscan/methods/scan_until.md7
-rw-r--r--doc/strscan/methods/set_pos.md8
-rw-r--r--doc/strscan/methods/skip.md5
-rw-r--r--doc/strscan/methods/skip_until.md13
-rw-r--r--doc/strscan/methods/terminate.md5
10 files changed, 21 insertions, 50 deletions
diff --git a/doc/strscan/methods/get_byte.md b/doc/strscan/methods/get_byte.md
index 2f23be1899..775226638e 100644
--- a/doc/strscan/methods/get_byte.md
+++ b/doc/strscan/methods/get_byte.md
@@ -1,6 +1,3 @@
-call-seq:
- get_byte -> byte_as_character or nil
-
Returns the next byte, if available:
- If the [position][2]
@@ -10,7 +7,7 @@ Returns the next byte, if available:
- Increments the [byte position][2].
- Adjusts the [character position][7].
- ```
+ ```rb
scanner = StringScanner.new(HIRAGANA_TEXT)
# => #<StringScanner 0/15 @ "\xE3\x81\x93\xE3\x82...">
scanner.string # => "こんにちは"
@@ -24,7 +21,7 @@ Returns the next byte, if available:
- Otherwise, returns `nil`, and does not change the positions.
- ```
+ ```rb
scanner.terminate
[scanner.get_byte, scanner.pos, scanner.charpos] # => [nil, 15, 5]
```
diff --git a/doc/strscan/methods/get_charpos.md b/doc/strscan/methods/get_charpos.md
index f77563c860..4de07897dc 100644
--- a/doc/strscan/methods/get_charpos.md
+++ b/doc/strscan/methods/get_charpos.md
@@ -1,11 +1,8 @@
-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.
diff --git a/doc/strscan/methods/get_pos.md b/doc/strscan/methods/get_pos.md
index 56bcef3274..56b1636812 100644
--- a/doc/strscan/methods/get_pos.md
+++ b/doc/strscan/methods/get_pos.md
@@ -1,10 +1,7 @@
-call-seq:
- pos -> byte_position
-
Returns the integer [byte position][2],
which may be different from the [character position][7]:
-```
+```rb
scanner = StringScanner.new(HIRAGANA_TEXT)
scanner.string # => "こんにちは"
scanner.pos # => 0
diff --git a/doc/strscan/methods/getch.md b/doc/strscan/methods/getch.md
index b57732ad7c..ede1d2b071 100644
--- a/doc/strscan/methods/getch.md
+++ b/doc/strscan/methods/getch.md
@@ -1,6 +1,3 @@
-call-seq:
- getch -> character or nil
-
Returns the next (possibly multibyte) character,
if available:
@@ -12,7 +9,7 @@ if available:
- Increments the [byte position][2]
by the size (in bytes) of the character.
- ```
+ ```rb
scanner = StringScanner.new(HIRAGANA_TEXT)
scanner.string # => "こんにちは"
[scanner.getch, scanner.pos, scanner.charpos] # => ["こ", 3, 1]
@@ -27,7 +24,7 @@ if available:
(that is, not at its beginning),
behaves like #get_byte (returns a 1-byte character):
- ```
+ ```rb
scanner.pos = 1
[scanner.getch, scanner.pos, scanner.charpos] # => ["\x81", 2, 2]
[scanner.getch, scanner.pos, scanner.charpos] # => ["\x93", 3, 1]
@@ -37,7 +34,7 @@ if available:
- If the [position][2] is at the end of the [stored string][1],
returns `nil` and does not modify the positions:
- ```
+ ```rb
scanner.terminate
[scanner.getch, scanner.pos, scanner.charpos] # => [nil, 15, 5]
```
diff --git a/doc/strscan/methods/scan.md b/doc/strscan/methods/scan.md
index 714fa9910a..805c797913 100644
--- a/doc/strscan/methods/scan.md
+++ b/doc/strscan/methods/scan.md
@@ -1,6 +1,3 @@
-call-seq:
- scan(pattern) -> substring or nil
-
Attempts to [match][17] the given `pattern`
at the beginning of the [target substring][3].
@@ -11,7 +8,7 @@ If the match succeeds:
and may increment the [character position][7].
- Sets [match values][9].
-```
+```rb
scanner = StringScanner.new(HIRAGANA_TEXT)
scanner.string # => "こんにちは"
scanner.pos = 6
@@ -45,7 +42,7 @@ If the match fails:
- Does not increment byte and character positions.
- Clears match values.
-```
+```rb
scanner.scan(/nope/) # => nil
match_values_cleared?(scanner) # => true
```
diff --git a/doc/strscan/methods/scan_until.md b/doc/strscan/methods/scan_until.md
index 3b7ff2c3a9..5fb2912a1b 100644
--- a/doc/strscan/methods/scan_until.md
+++ b/doc/strscan/methods/scan_until.md
@@ -1,6 +1,3 @@
-call-seq:
- scan_until(pattern) -> substring or nil
-
Attempts to [match][17] the given `pattern`
anywhere (at any [position][2]) in the [target substring][3].
@@ -12,7 +9,7 @@ If the match attempt succeeds:
- Returns the matched substring.
-```
+```rb
scanner = StringScanner.new(HIRAGANA_TEXT)
scanner.string # => "こんにちは"
scanner.pos = 6
@@ -46,7 +43,7 @@ If the match attempt fails:
- Returns `nil`.
- Does not update positions.
-```
+```rb
scanner.scan_until(/nope/) # => nil
match_values_cleared?(scanner) # => true
```
diff --git a/doc/strscan/methods/set_pos.md b/doc/strscan/methods/set_pos.md
index 230177109c..6a43edeb41 100644
--- a/doc/strscan/methods/set_pos.md
+++ b/doc/strscan/methods/set_pos.md
@@ -1,7 +1,3 @@
-call-seq:
- pos = n -> n
- pointer = n -> n
-
Sets the [byte position][2] and the [character position][11];
returns `n`.
@@ -9,7 +5,7 @@ Does not affect [match values][9].
For non-negative `n`, sets the position to `n`:
-```
+```rb
scanner = StringScanner.new(HIRAGANA_TEXT)
scanner.string # => "こんにちは"
scanner.pos = 3 # => 3
@@ -19,7 +15,7 @@ scanner.charpos # => 1
For negative `n`, counts from the end of the [stored string][1]:
-```
+```rb
scanner.pos = -9 # => -9
scanner.pos # => 6
scanner.rest # => "にちは"
diff --git a/doc/strscan/methods/skip.md b/doc/strscan/methods/skip.md
index 656f134c5a..7e924b624b 100644
--- a/doc/strscan/methods/skip.md
+++ b/doc/strscan/methods/skip.md
@@ -1,6 +1,3 @@
-call-seq:
- skip(pattern) match_size or nil
-
Attempts to [match][17] the given `pattern`
at the beginning of the [target substring][3];
@@ -11,7 +8,7 @@ If the match succeeds:
- Sets [match values][9].
- Returns the size (bytes) of the matched substring.
-```
+```rb
scanner = StringScanner.new(HIRAGANA_TEXT)
scanner.string # => "こんにちは"
scanner.pos = 6
diff --git a/doc/strscan/methods/skip_until.md b/doc/strscan/methods/skip_until.md
index 5187a4826f..a0ffab0b84 100644
--- a/doc/strscan/methods/skip_until.md
+++ b/doc/strscan/methods/skip_until.md
@@ -1,16 +1,14 @@
-call-seq:
- skip_until(pattern) -> matched_substring_size or nil
-
Attempts to [match][17] the given `pattern`
-anywhere (at any [position][2]) in the [target substring][3];
-does not modify the positions.
+anywhere (at any [position][2]) in the [target substring][3].
If the match attempt succeeds:
- Sets [match values][9].
+- Sets the [byte position][2] to the end of the matched substring;
+ may adjust the [character position][7].
- Returns the size of the matched substring.
-```
+```rb
scanner = StringScanner.new(HIRAGANA_TEXT)
scanner.string # => "こんにちは"
scanner.pos = 6
@@ -42,8 +40,9 @@ If the match attempt fails:
- Clears match values.
- Returns `nil`.
+- Does not update positions.
-```
+```rb
scanner.skip_until(/nope/) # => nil
match_values_cleared?(scanner) # => true
```
diff --git a/doc/strscan/methods/terminate.md b/doc/strscan/methods/terminate.md
index fd55727099..27f7d41cb1 100644
--- a/doc/strscan/methods/terminate.md
+++ b/doc/strscan/methods/terminate.md
@@ -1,13 +1,10 @@
-call-seq:
- terminate -> self
-
Sets the scanner to end-of-string;
returns +self+:
- Sets both [positions][11] to end-of-stream.
- Clears [match values][9].
-```
+```rb
scanner = StringScanner.new(HIRAGANA_TEXT)
scanner.string # => "こんにちは"
scanner.scan_until(/に/)