Skip to content

Commit

Permalink
Showing 2 changed files with 17 additions and 3 deletions.
3 changes: 0 additions & 3 deletions spec/filters/bugs/strscan.rb
Original file line number Diff line number Diff line change
@@ -19,9 +19,6 @@
fails "StringScanner#empty? Returns false if the scan pointer is not at the end of the string"
fails "StringScanner#empty? Returns true if the scan pointer is at the end of the string"
fails "StringScanner#empty? warns in verbose mode that the method is obsolete"
fails "StringScanner#exist? returns 0 if the pattern is empty"
fails "StringScanner#exist? returns nil if the pattern isn't found in the string"
fails "StringScanner#exist? returns the index of the first occurrence of the given pattern"
fails "StringScanner#getbyte is not multi-byte character sensitive"
fails "StringScanner#getbyte returns an instance of String when passed a String subclass"
fails "StringScanner#getbyte returns nil at the end of the string"
17 changes: 17 additions & 0 deletions stdlib/strscan.rb
Original file line number Diff line number Diff line change
@@ -15,6 +15,7 @@ def initialize(string)
def beginning_of_line?
`#@pos === 0 || #@string.charAt(#@pos - 1) === "\n"`
end

alias bol? beginning_of_line?

def scan(regex)
@@ -87,6 +88,22 @@ def eos?
`#@working.length === 0`
end

def exist?(regex)
%x{
var result = regex.exec(#@working);
if (result == null) {
return nil;
}
else if (result.index == 0) {
return 0;
}
else {
return result.index + 1;
}
}
end

def skip(re)
%x{
re = new RegExp('^' + re.source)

0 comments on commit 697476d

Please sign in to comment.