ruby_sscanf 0.1.3 → 0.2.0

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: 2bc480e9779f68f86b3e1fc6c3037c82f9faf0b8
4
- data.tar.gz: fb6dd5f80869cdcbadaeb9ab8c277f3983b60cef
3
+ metadata.gz: ebdb3c9a6ba312ee15d515c456ec29608c615a04
4
+ data.tar.gz: 2d20f9a4f4f278deb583a7d764629c346e31f629
5
5
  SHA512:
6
- metadata.gz: 8ddc5dc86fbfb694334448efc479a5084294094204be68cc8bbf7dc7c08f363606213d53668f9ab1b9ab62ade320d7f8e4ac10ef28df6d6cc18764b3c566ecea
7
- data.tar.gz: 5d6af7a4a181a41e6ba9251b500553beed42e251e9686b9117475ee6fd597338998e648f242bd98cc6ef48e19f63538b7d01e23deb31d10a7da64eaa5557f9f0
6
+ metadata.gz: c17787e331f21a747c6cf5a3542d141399bf236d555dee02c50afaf809db8c0ae04b8101879517b2142bd9f71d93d73e37e8f4917b5d823e0fe4188ff73fdf14
7
+ data.tar.gz: 9088a19271832f38f28a5ad6c31b98b1316f9d640f3dec292d9288ce376b339dd609c350a3e59cbfeeb05cc722cac35c1521696c79ad04a586361f564e1d588b
data/README.md CHANGED
@@ -49,15 +49,19 @@ Literal string components match themselves in the input string. If the literal
49
49
  has a trailing space, then this matches zero or more spaces.
50
50
  The special sequence '%%' matches one '%' in the input string.
51
51
 
52
- The layout of a format specifier is:
52
+ The layouts of a format specifier are:
53
53
 
54
54
  %[skip_flag][width]format
55
+ %[skip_flag][[min_width,]max_width]set
55
56
 
56
57
  * The % sign is the lead-in character.
57
58
  * The optional skip flag, the *, causes any data extracted to be ignored.
58
59
  * The width field is an integer that determines the amount of text to be
59
- parsed.
60
+ parsed. Note that a .precision field may be specified, but it is ignored.
60
61
  * The format field determines the type of data being parsed.
62
+ * The min_width is the minimum allowed run of characters in the set.
63
+ * The max_width is the maximum allowed run of characters in the set.
64
+ * The set field is a regular expression style [...] set.
61
65
 
62
66
  The supported format field values are:
63
67
  <br>
@@ -152,22 +156,22 @@ pleased to see that in fact ruby_sscanf was faster. Here are the results:
152
156
 
153
157
  Warming up --------------------------------------
154
158
  Scan strings with ruby_sscanf
155
- 1.594k i/100ms
159
+ 1.768k i/100ms
156
160
  Scan strings with scanf
157
- 305.000 i/100ms
161
+ 310.000 i/100ms
158
162
  Calculating -------------------------------------
159
163
  Scan strings with ruby_sscanf
160
- 16.419k4.9%) i/s - 82.888k
164
+ 18.355k5.8%) i/s - 91.936k
161
165
  Scan strings with scanf
162
- 3.077k6.2%) i/s - 15.555k
166
+ 3.145k7.2%) i/s - 15.810k
163
167
 
164
168
  Comparison:
165
- Scan strings with ruby_sscanf: 16418.6 i/s
166
- Scan strings with scanf: 3077.1 i/s - 5.34x slower
169
+ Scan strings with ruby_sscanf: 18354.7 i/s
170
+ Scan strings with scanf: 3145.0 i/s - 5.84x slower
167
171
 
168
172
  This benchmark test was run under:
169
173
  * ruby 2.1.6p336 (2015-04-13 revision 50298) [i386-mingw32]
170
- * format_engine version = 0.5.2
174
+ * format_engine version = 0.6.0
171
175
 
172
176
  ## Contributing
173
177
 
data/lib/ruby_sscanf.rb CHANGED
@@ -43,9 +43,15 @@ class String
43
43
  #A regular expression for quoted strings.
44
44
  RSF_QUOTED = /("([^\\"]|\\.)*")|('([^\\']|\\.)*')/
45
45
 
46
+ #The standard handlers for formats with embedded regular expressions.
47
+ RSF_RGX = lambda {parse(fmt.regex) ? dst << found : :break}
48
+ RSF_RGX_SKIP = lambda {parse(fmt.regex) || :break}
49
+
50
+
46
51
  #Get the parsing engine. This is cached on a per-thread basis. That is to
47
52
  #say, each thread gets its own \FormatEngine::Engine instance.
48
- def self.get_engine
53
+ def self.get_parser_engine
54
+
49
55
  Thread.current[:ruby_sscanf_engine] ||= FormatEngine::Engine.new(
50
56
  "%a" => RSF_FLOAT_PARSE,
51
57
  "%*a" => RSF_FLOAT_SKIP,
@@ -114,13 +120,16 @@ class String
114
120
  "%X" => RSF_HEX_PARSE,
115
121
  "%*X" => RSF_HEX_SKIP,
116
122
 
117
- "%[" => lambda {parse(fmt.regex) ? dst << found : :break},
118
- "%*[" => lambda {parse(fmt.regex) || :break})
123
+ "%[" => RSF_RGX,
124
+ "%*[" => RSF_RGX_SKIP,
125
+
126
+ "%/" => RSF_RGX,
127
+ "%*/" => RSF_RGX_SKIP)
119
128
  end
120
129
 
121
130
  #Scan the formatted input.
122
131
  def sscanf(format)
123
- String.get_engine.do_parse(self, [], format)
132
+ String.get_parser_engine.do_parse(self, [], format)
124
133
  end
125
134
 
126
135
  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.1.3"
4
+ VERSION = "0.2.0"
5
5
  end
data/ruby_sscanf.gemspec CHANGED
@@ -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.5"
25
+ spec.add_runtime_dependency "format_engine", ">= 0.7"
26
26
 
27
27
  spec.add_development_dependency "bundler", "~> 1.11"
28
28
  spec.add_development_dependency "rake", "~> 10.0"
data/tests/scan_tests.rb CHANGED
@@ -85,6 +85,9 @@ class ScanTester < Minitest::Test
85
85
 
86
86
  result = "a b c".sscanf "%[a] %[b] %[c]"
87
87
  assert_equal(["a", "b", "c"] , result)
88
+
89
+ result = "a abbccc acbcad".sscanf "%/A/i %/a+b+c+/ %/([ab][cd])+/"
90
+ assert_equal(["a", "abbccc", "acbcad"] , result)
88
91
  end
89
92
 
90
93
  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.1.3
4
+ version: 0.2.0
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-18 00:00:00.000000000 Z
11
+ date: 2016-02-22 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.5'
19
+ version: '0.7'
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.5'
26
+ version: '0.7'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: bundler
29
29
  requirement: !ruby/object:Gem::Requirement