opal-strscan 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. data/.gitignore +1 -0
  2. data/README.md +1 -0
  3. data/lib/opal/strscan.rb +53 -0
  4. metadata +47 -0
data/.gitignore ADDED
@@ -0,0 +1 @@
1
+ .DS_Store
data/README.md ADDED
@@ -0,0 +1 @@
1
+ StringScanner for Opal
@@ -0,0 +1,53 @@
1
+ class StringScanner
2
+ def initialize(string)
3
+ @string = string
4
+ @at = 0
5
+ @matched = ''
6
+ @working = string
7
+ end
8
+
9
+ def scan(regex)
10
+ %x{
11
+ var regex = new RegExp('^' + regex.toString().substring(1, regex.toString().length - 1)),
12
+ result = regex.exec(#@working);
13
+
14
+ if (result == null) {
15
+ #@matched = '';
16
+
17
+ return nil;
18
+ }
19
+ else if (typeof(result) === 'object') {
20
+ #@at += result[0].length;
21
+ #@working = #@working.substring(result[0].length);
22
+ #@matched = result[0];
23
+
24
+ return result[0];
25
+ }
26
+ else if (typeof(result) === 'string') {
27
+ #@at += result.length;
28
+ #@working = #@working.substring(result.length);
29
+
30
+ return result;
31
+ }
32
+ else {
33
+ return nil;
34
+ }
35
+ }
36
+ end
37
+
38
+ def check(regex)
39
+ `!!new RegExp('^' + regex.toString().substring(1, regex.toString().length - 1)).exec(#@working)`
40
+ end
41
+
42
+ def peek(length)
43
+ `#@working.substring(0, length)`
44
+ end
45
+
46
+ def eos?
47
+ `#@working.length === 0`
48
+ end
49
+
50
+ def matched
51
+ @matched
52
+ end
53
+ end
metadata ADDED
@@ -0,0 +1,47 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: opal-strscan
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Adam Beynon
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-01-22 00:00:00.000000000Z
13
+ dependencies: []
14
+ description: Opal version of strscan
15
+ email: adam@adambeynon.com
16
+ executables: []
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - .gitignore
21
+ - README.md
22
+ - lib/opal/strscan.rb
23
+ homepage: http://opalrb.org
24
+ licenses: []
25
+ post_install_message:
26
+ rdoc_options: []
27
+ require_paths:
28
+ - lib
29
+ required_ruby_version: !ruby/object:Gem::Requirement
30
+ none: false
31
+ requirements:
32
+ - - ! '>='
33
+ - !ruby/object:Gem::Version
34
+ version: '0'
35
+ required_rubygems_version: !ruby/object:Gem::Requirement
36
+ none: false
37
+ requirements:
38
+ - - ! '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ requirements: []
42
+ rubyforge_project:
43
+ rubygems_version: 1.8.11
44
+ signing_key:
45
+ specification_version: 3
46
+ summary: Opal version of strscan
47
+ test_files: []