rubysl-scanf 1.0.0 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +5 -6
- data/lib/rubysl/scanf/scanf.rb +39 -23
- data/lib/rubysl/scanf/version.rb +1 -1
- data/rubysl-scanf.gemspec +1 -2
- metadata +2 -16
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 69abe82c76d0d2fe7294188cfbec985533eda22c
|
4
|
+
data.tar.gz: 9faecde899f413b13324b92d776d5a8260de7afe
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ee7c4bfe9c6d50663afda1d5d069c8511fb6acf785f39904164374d1444c62821ed4cc6b5f2a4c130471bc1d07773564da8420cebc64ab7a28fba159fc8ef79d
|
7
|
+
data.tar.gz: 5b56ac91953cdf593fef407dd86b6532495b7ce9c8e01c4cbf98b176c1c67fb64642999c54193d9055a4f9f91a9dd393fff05d6f1bd02095a23d42a0f28aa706
|
data/.travis.yml
CHANGED
data/lib/rubysl/scanf/scanf.rb
CHANGED
@@ -1,9 +1,9 @@
|
|
1
1
|
# scanf for Ruby
|
2
2
|
#
|
3
|
-
# $
|
4
|
-
# $
|
5
|
-
# $
|
6
|
-
# $
|
3
|
+
# $Release Version: 1.1.2 $
|
4
|
+
# $Revision: 27139 $
|
5
|
+
# $Id: scanf.rb 27139 2010-04-01 04:32:22Z naruse $
|
6
|
+
# $Author: naruse $
|
7
7
|
#
|
8
8
|
# A product of the Austin Ruby Codefest (Austin, Texas, August 2002)
|
9
9
|
|
@@ -63,7 +63,7 @@ to the beginning of the format string, and yields a new array of
|
|
63
63
|
conversions to the block every time the format string is matched
|
64
64
|
(including partial matches, but not including complete failures). The
|
65
65
|
actual return value of scanf when called with a block is an array
|
66
|
-
containing the results of all the executions of the block.
|
66
|
+
containing the results of all the executions of the block.
|
67
67
|
|
68
68
|
str = "123 abc 456 def 789 ghi"
|
69
69
|
str.scanf("%d%s") { |num,str| [ num * 2, str.upcase ] }
|
@@ -100,7 +100,7 @@ and <tt>tests/scanftests.rb</tt> for examples.)
|
|
100
100
|
[u]
|
101
101
|
Same as d.
|
102
102
|
|
103
|
-
[i]
|
103
|
+
[i]
|
104
104
|
Matches an optionally signed integer. The integer is read in base
|
105
105
|
16 if it begins with `0x' or `0X', in base 8 if it begins with `0',
|
106
106
|
and in base 10 other- wise. Only characters that correspond to the
|
@@ -112,7 +112,7 @@ and <tt>tests/scanftests.rb</tt> for examples.)
|
|
112
112
|
[x,X]
|
113
113
|
Matches an optionally signed hexadecimal integer,
|
114
114
|
|
115
|
-
[f,g,
|
115
|
+
[a,e,f,g,A,E,F,G]
|
116
116
|
Matches an optionally signed floating-point number.
|
117
117
|
|
118
118
|
[s]
|
@@ -280,7 +280,7 @@ Project contributors:: Nolan Darilek, Jason Johnston
|
|
280
280
|
|
281
281
|
Thanks to Hal Fulton for hosting the Codefest.
|
282
282
|
|
283
|
-
Thanks to Matz for suggestions about the class design.
|
283
|
+
Thanks to Matz for suggestions about the class design.
|
284
284
|
|
285
285
|
Thanks to Gavin Sinclair for some feedback on the documentation.
|
286
286
|
|
@@ -309,7 +309,22 @@ module Scanf
|
|
309
309
|
|
310
310
|
def skip; /^\s*%\*/.match(@spec_string); end
|
311
311
|
|
312
|
-
def extract_float(s)
|
312
|
+
def extract_float(s)
|
313
|
+
return nil unless s &&! skip
|
314
|
+
if /\A(?<sign>[-+]?)0[xX](?<frac>\.\h+|\h+(?:\.\h*)?)[pP](?<exp>[-+]\d+)/ =~ s
|
315
|
+
f1, f2 = frac.split('.')
|
316
|
+
f = f1.hex
|
317
|
+
if f2
|
318
|
+
len = f2.length
|
319
|
+
if len > 0
|
320
|
+
f += f2.hex / (16.0 ** len)
|
321
|
+
end
|
322
|
+
end
|
323
|
+
(sign == ?- ? -1 : 1) * Math.ldexp(f, exp.to_i)
|
324
|
+
else
|
325
|
+
s.to_f
|
326
|
+
end
|
327
|
+
end
|
313
328
|
def extract_decimal(s); s.to_i if s &&! skip; end
|
314
329
|
def extract_hex(s); s.hex if s &&! skip; end
|
315
330
|
def extract_octal(s); s.oct if s &&! skip; end
|
@@ -325,14 +340,14 @@ module Scanf
|
|
325
340
|
end
|
326
341
|
|
327
342
|
def count_space?
|
328
|
-
/(?:\A|\S)%\*?\d*c
|
343
|
+
/(?:\A|\S)%\*?\d*c|%\d*\[/.match(@spec_string)
|
329
344
|
end
|
330
345
|
|
331
346
|
def initialize(str)
|
332
347
|
@spec_string = str
|
333
348
|
h = '[A-Fa-f0-9]'
|
334
349
|
|
335
|
-
@re_string, @handler =
|
350
|
+
@re_string, @handler =
|
336
351
|
case @spec_string
|
337
352
|
|
338
353
|
# %[[:...:]]
|
@@ -409,12 +424,13 @@ module Scanf
|
|
409
424
|
[ "([-+][0-7]{1,#{$1.to_i-1}}|[0-7]{1,#{$1}})", :extract_octal ]
|
410
425
|
|
411
426
|
# %f
|
412
|
-
when /%\*?
|
413
|
-
[ '([-+]?((\d+(
|
427
|
+
when /%\*?[aefgAEFG]/
|
428
|
+
[ '([-+]?(?:0[xX](?:\.\h+|\h+(?:\.\h*)?)[pP][-+]\d+|\d+(?![\d.])|\d*\.\d*(?:[eE][-+]?\d+)?))', :extract_float ]
|
414
429
|
|
415
430
|
# %5f
|
416
|
-
when /%\*?(\d+)
|
417
|
-
[
|
431
|
+
when /%\*?(\d+)[aefgAEFG]/
|
432
|
+
[ '(?=[-+]?(?:0[xX](?:\.\h+|\h+(?:\.\h*)?)[pP][-+]\d+|\d+(?![\d.])|\d*\.\d*(?:[eE][-+]?\d+)?))' +
|
433
|
+
"(\\S{1,#{$1}})", :extract_float ]
|
418
434
|
|
419
435
|
# %5s
|
420
436
|
when /%\*?(\d+)s/
|
@@ -466,11 +482,11 @@ module Scanf
|
|
466
482
|
end
|
467
483
|
|
468
484
|
def letter
|
469
|
-
/%\*?\d*([a-z\[])
|
485
|
+
@spec_string[/%\*?\d*([a-z\[])/, 1]
|
470
486
|
end
|
471
487
|
|
472
488
|
def width
|
473
|
-
w = /%\*?(\d+)
|
489
|
+
w = @spec_string[/%\*?(\d+)/, 1]
|
474
490
|
w && w.to_i
|
475
491
|
end
|
476
492
|
|
@@ -482,7 +498,7 @@ module Scanf
|
|
482
498
|
|
483
499
|
return width_left || cc_no_width
|
484
500
|
end
|
485
|
-
|
501
|
+
|
486
502
|
end
|
487
503
|
|
488
504
|
class FormatString
|
@@ -490,7 +506,7 @@ module Scanf
|
|
490
506
|
attr_reader :string_left, :last_spec_tried,
|
491
507
|
:last_match_tried, :matched_count, :space
|
492
508
|
|
493
|
-
SPECIFIERS = '
|
509
|
+
SPECIFIERS = 'diuXxofFeEgGscaA'
|
494
510
|
REGEX = /
|
495
511
|
# possible space, followed by...
|
496
512
|
(?:\s*
|
@@ -542,7 +558,7 @@ module Scanf
|
|
542
558
|
@matched_count = 0
|
543
559
|
|
544
560
|
@specs.each_with_index do |spec,i|
|
545
|
-
@i
|
561
|
+
@i=i
|
546
562
|
@last_spec_tried = spec
|
547
563
|
@last_match_tried = spec.match(@string_left)
|
548
564
|
break unless @last_match_tried
|
@@ -672,10 +688,10 @@ class String
|
|
672
688
|
if b
|
673
689
|
block_scanf(fstr,&b)
|
674
690
|
else
|
675
|
-
fs =
|
691
|
+
fs =
|
676
692
|
if fstr.is_a? Scanf::FormatString
|
677
|
-
fstr
|
678
|
-
else
|
693
|
+
fstr
|
694
|
+
else
|
679
695
|
Scanf::FormatString.new(fstr)
|
680
696
|
end
|
681
697
|
fs.match(self)
|
data/lib/rubysl/scanf/version.rb
CHANGED
data/rubysl-scanf.gemspec
CHANGED
@@ -19,5 +19,4 @@ Gem::Specification.new do |spec|
|
|
19
19
|
spec.add_development_dependency "bundler", "~> 1.3"
|
20
20
|
spec.add_development_dependency "rake", "~> 10.0"
|
21
21
|
spec.add_development_dependency "mspec", "~> 1.5"
|
22
|
-
|
23
|
-
end
|
22
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rubysl-scanf
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 2.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Brian Shirai
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-
|
11
|
+
date: 2013-09-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -52,20 +52,6 @@ dependencies:
|
|
52
52
|
- - ~>
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '1.5'
|
55
|
-
- !ruby/object:Gem::Dependency
|
56
|
-
name: rubysl-prettyprint
|
57
|
-
requirement: !ruby/object:Gem::Requirement
|
58
|
-
requirements:
|
59
|
-
- - ~>
|
60
|
-
- !ruby/object:Gem::Version
|
61
|
-
version: '1.0'
|
62
|
-
type: :development
|
63
|
-
prerelease: false
|
64
|
-
version_requirements: !ruby/object:Gem::Requirement
|
65
|
-
requirements:
|
66
|
-
- - ~>
|
67
|
-
- !ruby/object:Gem::Version
|
68
|
-
version: '1.0'
|
69
55
|
description: Ruby standard library scanf.
|
70
56
|
email:
|
71
57
|
- brixen@gmail.com
|