ruby_sscanf 0.2.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ebdb3c9a6ba312ee15d515c456ec29608c615a04
4
- data.tar.gz: 2d20f9a4f4f278deb583a7d764629c346e31f629
3
+ metadata.gz: 0bc62e85d57a5d9c3b5c8dcd4b5710be669d33e4
4
+ data.tar.gz: e263651715d3557d7ff6933e933e406dc0deb8d2
5
5
  SHA512:
6
- metadata.gz: c17787e331f21a747c6cf5a3542d141399bf236d555dee02c50afaf809db8c0ae04b8101879517b2142bd9f71d93d73e37e8f4917b5d823e0fe4188ff73fdf14
7
- data.tar.gz: 9088a19271832f38f28a5ad6c31b98b1316f9d640f3dec292d9288ce376b339dd609c350a3e59cbfeeb05cc722cac35c1521696c79ad04a586361f564e1d588b
6
+ metadata.gz: 1695d80b48075693c685e2f8c0f2e31c54337cd11854ea73f97656b7f8ab9f875fff2a693ac3f113eb9e6854a5bc9c58531856c7f6c90a91542a33934b4dddba
7
+ data.tar.gz: b98fecc6662d6d2a763e10616581bf9e8c0ccb83e4f20be90a580e0c638fdcc6cd5cc5a423552a278c4a3da755bab63f01fde3289ab2c41783a188b80b3df07b
data/README.md CHANGED
@@ -53,6 +53,8 @@ The layouts of a format specifier are:
53
53
 
54
54
  %[skip_flag][width]format
55
55
  %[skip_flag][[min_width,]max_width]set
56
+ %[skip_flag]regex[options]
57
+
56
58
 
57
59
  * The % sign is the lead-in character.
58
60
  * The optional skip flag, the *, causes any data extracted to be ignored.
@@ -91,6 +93,8 @@ or "...".
91
93
  leading '0x' or '0X'.
92
94
  * [chars] - Scan for a contiguous string of characters in the set [chars].
93
95
  * [^chars] - Scan for a contiguous string of characters not in the set [^chars]
96
+ * /regex/ - Scan for a string matching the regular expression. This may be
97
+ followed by one or more optional flags. Supported flags are i, m, and x.
94
98
 
95
99
  ## Examples
96
100
  Here are a few exmaples of the sscanf method in action.
@@ -146,6 +150,17 @@ returns ["quote", "un quote", "a '"]
146
150
 
147
151
  "a b c".sscanf "%[a] %[b] %[c]"
148
152
  returns ["a", "b", "c"]
153
+
154
+ "a abbccc acbcad".sscanf "%/A/i %/a+b+c+/ %/([ab][cd])+/"
155
+ returns ["a", "abbccc", "acbcad"]
156
+ ```
157
+
158
+ ## Getting unparsed text
159
+ When a string is parsed, there may be some text at the end of the string that
160
+ is not parsed. It is possible to retrieve this text using the following:
161
+
162
+ ```ruby
163
+ String.sscanf_unparsed
149
164
  ```
150
165
 
151
166
  ## Benchmarks
@@ -11,9 +11,9 @@ class String
11
11
  RSF_UNSIGNED = /[+]?\d+/
12
12
 
13
13
  #A regular expression for hexadecimal integers.
14
- RSF_HEX = /[+-]?(0[xX])?\h+/
15
- RSF_HEX_PARSE = lambda {parse(RSF_HEX) ? dst << found.to_i(16) : :break}
16
- RSF_HEX_SKIP = lambda {parse(RSF_HEX) || :break}
14
+ rsf_hex = /[+-]?(0[xX])?\h+/
15
+ RSF_HEX_PARSE = lambda {parse(rsf_hex) ? dst << found.to_i(16) : :break}
16
+ RSF_HEX_SKIP = lambda {parse(rsf_hex) || :break}
17
17
 
18
18
  #A regular expression for octal integers.
19
19
  RSF_OCTAL = /[+-]?(0[oO])?[0-7]+/
@@ -25,9 +25,9 @@ class String
25
25
  RSF_INTEGER = /[+-]?((0[xX]\h+)|(0[bB][01]+)|(0[oO]?[0-7]*)|([1-9]\d*))/
26
26
 
27
27
  #A regular expression for floating point and scientific notation numbers.
28
- RSF_FLOAT = /[+-]?\d+(\.\d+)?([eE][+-]?\d+)?/
29
- RSF_FLOAT_PARSE = lambda {parse(RSF_FLOAT) ? dst << found.to_f : :break}
30
- RSF_FLOAT_SKIP = lambda {parse(RSF_FLOAT) || :break}
28
+ rsf_float = /[+-]?\d+(\.\d+)?([eE][+-]?\d+)?/
29
+ RSF_FLOAT_PARSE = lambda {parse(rsf_float) ? dst << found.to_f : :break}
30
+ RSF_FLOAT_SKIP = lambda {parse(rsf_float) || :break}
31
31
 
32
32
  #A regular expression for rational numbers.
33
33
  RSF_RATIONAL = /[+-]?\d+\/\d+(r)?/
@@ -132,4 +132,9 @@ class String
132
132
  String.get_parser_engine.do_parse(self, [], format)
133
133
  end
134
134
 
135
+ #Get any unparsed text.
136
+ def self.sscanf_unparsed
137
+ String.get_parser_engine.unparsed
138
+ end
139
+
135
140
  end
@@ -1,5 +1,5 @@
1
1
  #The ruby_sscanf doesn't really live here.
2
2
  module RubySscanf
3
3
  #The gem's version.
4
- VERSION = "0.2.0"
4
+ VERSION = "0.2.1"
5
5
  end
@@ -22,7 +22,7 @@ Gem::Specification.new do |spec|
22
22
 
23
23
  spec.required_ruby_version = '>= 1.9.3'
24
24
 
25
- spec.add_runtime_dependency "format_engine", ">= 0.7"
25
+ spec.add_runtime_dependency "format_engine", ">= 0.7.1"
26
26
 
27
27
  spec.add_development_dependency "bundler", "~> 1.11"
28
28
  spec.add_development_dependency "rake", "~> 10.0"
@@ -90,4 +90,14 @@ class ScanTester < Minitest::Test
90
90
  assert_equal(["a", "abbccc", "acbcad"] , result)
91
91
  end
92
92
 
93
+ def test_unparsed_text
94
+ result = "12 34 and much more".sscanf "%u %u"
95
+ assert_equal([12, 34] , result)
96
+ assert_equal(" and much more" , String.sscanf_unparsed)
97
+
98
+ result = "12 34 and much more".sscanf "%u %u "
99
+ assert_equal([12, 34] , result)
100
+ assert_equal("and much more" , String.sscanf_unparsed)
101
+ end
102
+
93
103
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby_sscanf
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Peter Camilleri
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-02-22 00:00:00.000000000 Z
11
+ date: 2016-02-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: format_engine
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: '0.7'
19
+ version: 0.7.1
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: '0.7'
26
+ version: 0.7.1
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: bundler
29
29
  requirement: !ruby/object:Gem::Requirement