Permalink
Browse files

Fix that scanChar wouldn't scan newlines

  • Loading branch information...
1 parent 3962e97 commit cab20ed189283048aca938c2bb5d2442417c19fb @sstephenson committed Aug 27, 2010
Showing with 7 additions and 6 deletions.
  1. +4 −4 src/strscan.coffee
  2. +3 −2 test/test_strscan.coffee
View
@@ -1,13 +1,13 @@
# **StringScanner** is a simple string tokenizer that provides for lexical
-# scanning operations on a string. It's a JavaScript port of the [Ruby
+# scanning operations on a string. It's a JavaScript port of the [Ruby
# library with the same name](http://ruby-doc.org/core/classes/StringScanner.html).
#
# Scanning a string means keeping track of and advancing a position (a
# zero-based index into the source string) and matching regular expressions
# against the portion of the source string after the position.
#
# StringScanner is written in [CoffeeScript](http://coffeescript.org/) and
-# distributed via [npm](http://npm.mape.me/) as a [CommonJS
+# distributed via [npm](http://npm.mape.me/) as a [CommonJS
# module](http://www.commonjs.org/).
#
# [Clone, fork, or file bugs at GitHub](http://github.com/sstephenson/strscan-js).
@@ -44,7 +44,7 @@
#### Scanning for matches
# The `scan`, `scanUntil`, `scanChar`, `skip`, and `skipUntil` methods look
-# for matching strings and advance the scanner's position. The _scan_
+# for matching strings and advance the scanner's position. The _scan_
# methods return the matched string; the _skip_ methods return the number
# of characters by which the scan position advanced.
# -------------------------------------------------------------------------
@@ -75,7 +75,7 @@
# Scans one character, returns it, and advances the scanner's position.
scanChar: ->
- @scan /./
+ @scan /[\s\S]/
# Skips over the given `regexp` at the current position. Returns the
# length of the matched string and advances the scanner's position, or
View
@@ -42,8 +42,10 @@ ok s.scanChar() is "a"
ok s.scanChar() is "b"
ok not s.scanChar()
-s = new StringScanner ""
+s = new StringScanner "\n1"
ok s.scanChar() is ""
+ok s.scanChar() is "\n"
+ok s.scanChar() is "1"
ok not s.scanChar()
s = new StringScanner "test string"
@@ -109,4 +111,3 @@ s = new StringScanner "Fri Dec 12 1975 14:39"
ok s.checkUntil(/12/) is "Fri Dec 12"
ok s.getPosition() is 0
ok s.getMatch() is "12"
-

0 comments on commit cab20ed

Please sign in to comment.