Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

README.md: tabs to spaces

  • Loading branch information...
commit 735b38f0114775d7b6de8b89aa69bfe266a362ae 1 parent f46f699
Michael Ficarra authored
Showing with 141 additions and 141 deletions.
  1. +141 −141 README.md
282 README.md
View
@@ -10,9 +10,9 @@ How To Use
Instantiate a new `StringScanner` by passing its constructor the string to scan.
- var StringScanner = require("StringScanner");
- var ss = new StringScanner("abc123 def456");
- // #<StringScanner 0/13 @ "abc12...">
+ var StringScanner = require("StringScanner");
+ var ss = new StringScanner("abc123 def456");
+ // #<StringScanner 0/13 @ "abc12...">
For the following examples, `ss` represents the `StringScanner` instance
defined above.
@@ -21,24 +21,24 @@ defined above.
Returns `true` if the scan pointer is at the beginning of a line (right after
`\n`) or the beginning of the string, `false` otherwise.
- ss.reset() // #<StringScanner 0/13 @ "abc12...">
- ss.pointer() // 0
- ss.bol() // true
- ss.scan(/./) // "a"
- ss.pointer() // 1
- ss.bol() // false
+ ss.reset() // #<StringScanner 0/13 @ "abc12...">
+ ss.pointer() // 0
+ ss.bol() // true
+ ss.scan(/./) // "a"
+ ss.pointer() // 1
+ ss.bol() // false
### captures
Returns an Array containing the contents of the capturing groups in the last
evaluated pattern match.
- ss.reset() // #<StringScanner 0/13 @ "abc12...">
- ss.check(/.*(..) (..)/ // "abc123 de"
- ss.captures() // ["23","de"]
- ss.check(/\w+/) // "abc123"
- ss.captures() // []
- ss.check(/\s+/) // null
- ss.captures() // []
+ ss.reset() // #<StringScanner 0/13 @ "abc12...">
+ ss.check(/.*(..) (..)/ // "abc123 de"
+ ss.captures() // ["23","de"]
+ ss.check(/\w+/) // "abc123"
+ ss.captures() // []
+ ss.check(/\s+/) // null
+ ss.captures() // []
### check(pattern)
@@ -48,12 +48,12 @@ Checks if a `scan` of the given pattern would succeed without advancing the
scan pointer. Returns the portion of the string matched on successful match,
`null` otherwise.
- ss.reset() // #<StringScanner 0/13 @ "abc12...">
- ss.check(/[a-z]+/i) // "abc"
- ss.check(/[a-z]+/i) // "abc"
- ss.scan(/[a-z]+/i) // "abc"
- ss.check(/[a-z]+/i) // null
- ss.check(/[\d\s]+/) // "123 "
+ ss.reset() // #<StringScanner 0/13 @ "abc12...">
+ ss.check(/[a-z]+/i) // "abc"
+ ss.check(/[a-z]+/i) // "abc"
+ ss.scan(/[a-z]+/i) // "abc"
+ ss.check(/[a-z]+/i) // null
+ ss.check(/[\d\s]+/) // "123 "
### checkUntil(pattern)
*Note: this method alters last match results*
@@ -62,12 +62,12 @@ Checks if a `scanUntil` would succeed without advancing the scan pointer.
Returns the portion of the string being scanned from the scan pointer to the
end of the matched string on successful match, `null` otherwise.
- ss.reset() // #<StringScanner 0/13 @ "abc12...">
- ss.checkUntil(/\s/) // "abc123 "
- ss.checkUntil(/\s/) // "abc123 "
- ss.checkUntil(/r/) // null
- ss.scanUntil(/e/) // "abc123 de"
- ss.checkUntil(/\s/) // null
+ ss.reset() // #<StringScanner 0/13 @ "abc12...">
+ ss.checkUntil(/\s/) // "abc123 "
+ ss.checkUntil(/\s/) // "abc123 "
+ ss.checkUntil(/r/) // null
+ ss.scanUntil(/e/) // "abc123 de"
+ ss.checkUntil(/\s/) // null
### clone / dup
Creates a duplicate of this instance of `StringScanner`.
@@ -75,21 +75,21 @@ Creates a duplicate of this instance of `StringScanner`.
### concat(str)
Appends the given string to the string being scanned.
- ss.reset() // #<StringScanner 0/13 @ "abc12...">
- ss.checkUntil(/h/) // null
- ss.concat(" ghi789") // #<StringScanner 0/20 @ "abc12..."
- ss.checkUntil(/h/) // "abc123 def456 gh"
+ ss.reset() // #<StringScanner 0/13 @ "abc12...">
+ ss.checkUntil(/h/) // null
+ ss.concat(" ghi789") // #<StringScanner 0/20 @ "abc12..."
+ ss.checkUntil(/h/) // "abc123 def456 gh"
### eos / endOfString
Returns `true` if the scan pointer is at the end of the string being scanned,
`false` otherwise.
- ss.reset() // #<StringScanner 0/13 @ "abc12...">
- ss.pointer() // 0
- ss.eos() // false
- ss.scan(/.*/) // "abc123 def456"
- ss.pointer() // 13
- ss.eos() // true
+ ss.reset() // #<StringScanner 0/13 @ "abc12...">
+ ss.pointer() // 0
+ ss.eos() // false
+ ss.scan(/.*/) // "abc123 def456"
+ ss.pointer() // 13
+ ss.eos() // true
### exists(pattern) / exist(pattern)
*Note: this method alters last match results*
@@ -102,23 +102,23 @@ This will determine if a `scanUntil` operation will succeed. Returns the
number of characters between the scan pointer and the position in which the
match was found on success, `null` otherwise.
- ss.reset()
- // ----
- ss.exists(/c/) // 2
- ss.match() // "c"
- ss.matched() // true
- // ----
- ss.exists(/a/) // 0
- ss.match() // "a"
- ss.matched() // true
- // ----
- ss.exists(/b*/) // 0
- ss.match() // ""
- ss.matched() // true
- // ----
- ss.exists(/m/) // null
- ss.match() // null
- ss.matched() // false
+ ss.reset()
+ // ----
+ ss.exists(/c/) // 2
+ ss.match() // "c"
+ ss.matched() // true
+ // ----
+ ss.exists(/a/) // 0
+ ss.match() // "a"
+ ss.matched() // true
+ // ----
+ ss.exists(/b*/) // 0
+ ss.match() // ""
+ ss.matched() // true
+ // ----
+ ss.exists(/m/) // null
+ ss.match() // null
+ ss.matched() // false
### getch / getChar
*Note: this method alters last match results*
@@ -127,21 +127,21 @@ match was found on success, `null` otherwise.
`scan`s one character and returns it; exactly equivalent to `scan(/./)`.
- ss.reset() // #<StringScanner 0/13 @ "abc12...">
- ss.getch() // "a"
- ss.reset() // #<StringScanner 0/13 @ "abc12...">
- ss.scan(/./) // "a"
+ ss.reset() // #<StringScanner 0/13 @ "abc12...">
+ ss.getch() // "a"
+ ss.reset() // #<StringScanner 0/13 @ "abc12...">
+ ss.scan(/./) // "a"
### match
*Note: Ruby equivalent: `matched`*
Returns the last string matched or `null` if the last attempted match failed.
- ss.reset() // #<StringScanner 0/13 @ "abc12...">
- ss.scan(/[a-z]+/i) // "abc"
- ss.match() // "abc"
- ss.check(/[a-z]+/i) // null
- ss.match() // null
+ ss.reset() // #<StringScanner 0/13 @ "abc12...">
+ ss.scan(/[a-z]+/i) // "abc"
+ ss.match() // "abc"
+ ss.check(/[a-z]+/i) // null
+ ss.match() // null
### matches(pattern)
*Note: Ruby equivalent: `match?`*
@@ -150,23 +150,23 @@ Checks if a scan of the given pattern would succeed without advancing the scan
pointer. Returns the length of the string matched on successful match, `null`
otherwise.
- ss.reset() // #<StringScanner 0/13 @ "abc12...">
- ss.matches(/[a-z]+/i) // 3
- ss.matches(/[a-z]+/i) // 3
- ss.scan(/[a-z]+/i) // "abc"
- ss.matches(/[a-z]+/i) // null
- ss.matches(/[\d\s]+/) // 4
+ ss.reset() // #<StringScanner 0/13 @ "abc12...">
+ ss.matches(/[a-z]+/i) // 3
+ ss.matches(/[a-z]+/i) // 3
+ ss.scan(/[a-z]+/i) // "abc"
+ ss.matches(/[a-z]+/i) // null
+ ss.matches(/[\d\s]+/) // 4
### matched
*Note: Ruby equivalent: `matched?`*
Returns `true` if the last attempted match was successful, `false` otherwise.
- ss.reset() // #<StringScanner 0/13 @ "abc12...">
- ss.scan(/\w+/) // "abc123"
- ss.matched() // true
- ss.scan(/\w+/) // null
- ss.matched() // false
+ ss.reset() // #<StringScanner 0/13 @ "abc12...">
+ ss.scan(/\w+/) // "abc123"
+ ss.matched() // true
+ ss.scan(/\w+/) // null
+ ss.matched() // false
### matchSize
*Warning: this method may return `0` on a successful operation. Use `===`
@@ -175,34 +175,34 @@ comparision to `null` for failure check, for example: `ss.matchSize()===null`*
Returns the length of the most recently matched string if the most recent match
attempt succeeded, `null` otherwise.
- ss.reset() // #<StringScanner 0/13 @ "abc12...">
- ss.scan(/\w+/) // "abc123"
- ss.matchSize() // 6
- ss.check(/\w*/) // ""
- ss.matchSize() // 0
- ss.check(/\w+/) // null
- ss.matchSize() // null
+ ss.reset() // #<StringScanner 0/13 @ "abc12...">
+ ss.scan(/\w+/) // "abc123"
+ ss.matchSize() // 6
+ ss.check(/\w*/) // ""
+ ss.matchSize() // 0
+ ss.check(/\w+/) // null
+ ss.matchSize() // null
### peek(len)
Returns *len* characters after the scan pointer, or the rest of the string,
whichever is shorter.
- ss.reset() // #<StringScanner 0/13 @ "abc12...">
- ss.scan(/.*d/) // "abc123 d"
- ss.peek(3) // "ef4"
- ss.peek(9001) // "ef456"
- ss.peek(0) // ""
- ss.peek(-3) // ""
+ ss.reset() // #<StringScanner 0/13 @ "abc12...">
+ ss.scan(/.*d/) // "abc123 d"
+ ss.peek(3) // "ef4"
+ ss.peek(9001) // "ef456"
+ ss.peek(0) // ""
+ ss.peek(-3) // ""
### pointer / position
Returns the scan pointer position as an integer.
- ss.reset() // #<StringScanner 0/13 @ "abc12...">
- ss.pointer() // 0
- ss.scan(/\w+\d+\s+/) // "abc123 "
- ss.pointer() // 7
- ss.scan([a-z]+) // "def"
- ss.pointer() // 10
+ ss.reset() // #<StringScanner 0/13 @ "abc12...">
+ ss.pointer() // 0
+ ss.scan(/\w+\d+\s+/) // "abc123 "
+ ss.pointer() // 7
+ ss.scan([a-z]+) // "def"
+ ss.pointer() // 10
### setPointer(pos)
Manually move the scan pointer to *pos* characters from the beginning of the
@@ -210,33 +210,33 @@ string. The scan pointer is bounded between zero and the scanning string's
length. Returns the position to which the scan pointer was moved. `setPointer`
neither resets nor modifies the last match results.
- ss.reset() // #<StringScanner 0/13 @ "abc12...">
- ss.setPointer(4) // 4
- ss.scan(/\d+/) // "23"
- ss.pointer() // 6
- ss.setPointer(-4) // 0
- ss.setPointer(99) // 13
+ ss.reset() // #<StringScanner 0/13 @ "abc12...">
+ ss.setPointer(4) // 4
+ ss.scan(/\d+/) // "23"
+ ss.pointer() // 6
+ ss.setPointer(-4) // 0
+ ss.setPointer(99) // 13
### reset
Moves the scan pointer back to the beginning of the string being scanned and
clears the last match results.
- ss.reset() // #<StringScanner 0/13 @ "abc12...">
- ss.scanUntil(/(\s)/) // "abc123 "
- ss.pointer() // 7
- ss.match() // "abc123 "
- ss.captures() // [" "]
- ss.reset() // #<StringScanner 0/13 @ "abc12...">
- ss.pointer() // 0
- ss.match() // null
- ss.captures() // []
+ ss.reset() // #<StringScanner 0/13 @ "abc12...">
+ ss.scanUntil(/(\s)/) // "abc123 "
+ ss.pointer() // 7
+ ss.match() // "abc123 "
+ ss.captures() // [" "]
+ ss.reset() // #<StringScanner 0/13 @ "abc12...">
+ ss.pointer() // 0
+ ss.match() // null
+ ss.captures() // []
### rest
Returns the portion of the string being scanned after the scan pointer.
- ss.reset() // #<StringScanner 0/13 @ "abc12...">
- ss.scanUntil(/\s/) // "abc123 "
- ss.rest() // "def456"
+ ss.reset() // #<StringScanner 0/13 @ "abc12...">
+ ss.scanUntil(/\s/) // "abc123 "
+ ss.rest() // "def456"
### scan(pattern)
*Note: this method alters last match results*
@@ -245,13 +245,13 @@ Attempts to match the given pattern at the position of the scan pointer.
Returns the matched string and advances the string pointer upon successful
match. A failed match will result in a `null` value being returned.
- ss.reset() // #<StringScanner 0/13 @ "abc12...">
- ss.scan(/[a-z]+/) // "abc"
- ss // #<StringScanner 3/13 @ "abc12...">
- ss.scan(/[a-z]+/) // null
- ss // #<StringScanner 3/13 @ "abc12...">
- ss.scan(/[0-9]+/) // "123"
- ss // #<StringScanner 6/13 @ "abc12...">
+ ss.reset() // #<StringScanner 0/13 @ "abc12...">
+ ss.scan(/[a-z]+/) // "abc"
+ ss // #<StringScanner 3/13 @ "abc12...">
+ ss.scan(/[a-z]+/) // null
+ ss // #<StringScanner 3/13 @ "abc12...">
+ ss.scan(/[0-9]+/) // "123"
+ ss // #<StringScanner 6/13 @ "abc12...">
### scanUntil(pattern)
*Note: this method alters last match results*
@@ -261,10 +261,10 @@ match, the scan pointer is advanced to the end of the matched portion of the
string and the portion of the string being scanned up to and including the
matched string is returned. On a failed match, `null` is returned.
- ss.reset() // #<StringScanner 0/13 @ "abc12...">
- ss.scanUntil(/ /) // "abc123 "
- ss.scanUntil(/f/) // "def"
- ss.scanUntil(/f/) // null
+ ss.reset() // #<StringScanner 0/13 @ "abc12...">
+ ss.scanUntil(/ /) // "abc123 "
+ ss.scanUntil(/f/) // "def"
+ ss.scanUntil(/f/) // null
### skip(pattern)
*Note: this method alters last match results*
@@ -272,10 +272,10 @@ matched string is returned. On a failed match, `null` is returned.
Performs a `scan`, returning the length of the matched string on successful
match, `null` otherwise.
- ss.reset() // #<StringScanner 0/13 @ "abc12...">
- ss.skip(/[a-z]+/) // 3
- ss.skip(/[a-z]+/) // null
- ss.skip(/[0-9]+/) // 3
+ ss.reset() // #<StringScanner 0/13 @ "abc12...">
+ ss.skip(/[a-z]+/) // 3
+ ss.skip(/[a-z]+/) // null
+ ss.skip(/[0-9]+/) // 3
### skipUntil(pattern)
*Note: this method alters last match results*
@@ -283,29 +283,29 @@ match, `null` otherwise.
Performs a `scanUntil`, returning the length of the matched string on
successful match, `null` otherwise.
- ss.reset() // #<StringScanner 0/13 @ "abc12...">
- ss.skipUntil(/ /) // 7
- ss.skipUntil(/f/) // 3
- ss.skipUntil(/f/) // null
+ ss.reset() // #<StringScanner 0/13 @ "abc12...">
+ ss.skipUntil(/ /) // 7
+ ss.skipUntil(/f/) // 3
+ ss.skipUntil(/f/) // null
### string
Returns the entire string being scanned.
- ss.string() // "abc123 def456"
- ss.getch() // "a"
- ss.string() // "abc123 def456"
+ ss.string() // "abc123 def456"
+ ss.getch() // "a"
+ ss.string() // "abc123 def456"
### terminate / clear
Advances the scan pointer to the end of the string being scanned and resets the
last match results.
- ss.reset() // #<StringScanner 0/13 @ "abc12...">
- ss.getch() // "a"
- ss.pointer() // 1
- ss.terminate() // #<StringScanner fin>
- ss.pointer() // 13
- ss.eos() // true
- ss.match() // null
+ ss.reset() // #<StringScanner 0/13 @ "abc12...">
+ ss.getch() // "a"
+ ss.pointer() // 1
+ ss.terminate() // #<StringScanner fin>
+ ss.pointer() // 13
+ ss.eos() // true
+ ss.match() // null
Known Issues
------------
Please sign in to comment.
Something went wrong with that request. Please try again.