motion-strscan 0.5.0 → 0.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +4 -0
- data/lib/motion-strscan/strscan.rb +34 -2
- data/lib/motion-strscan/version.rb +1 -1
- metadata +6 -19
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2a771a294c218fbfdf4fc1613d9d2c19559cef72
|
4
|
+
data.tar.gz: 88224c0207bad83b1f6ce3cfef941f0c26d79d83
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 209f1e440b64700af5df1b60904c4a16aea7cb672526f27bf3c872c5abc904e01e82e87d36871606534dfca3a43fa48a2f604f5d2982888d00f689cfc2350524
|
7
|
+
data.tar.gz: aec494fbf5b5958a340dd0b3b1aa4735af633ed14b5e489ac78d767ef91e0cd4da274ec466ad66065152149cea8002c79e327647e11c0b1902aad2a220d1441f
|
data/README.md
CHANGED
@@ -140,6 +140,10 @@ class StringScanner
|
|
140
140
|
#
|
141
141
|
attr_reader :string, :char_pos, :byte_pos
|
142
142
|
|
143
|
+
def self.regex_cache
|
144
|
+
@@regex_cache
|
145
|
+
end
|
146
|
+
|
143
147
|
# This method is defined for backward compatibility.
|
144
148
|
#
|
145
149
|
def self.must_C_version
|
@@ -152,6 +156,8 @@ class StringScanner
|
|
152
156
|
# +dup+ argument is obsolete and not used now.
|
153
157
|
#
|
154
158
|
def initialize(string, dup = false)
|
159
|
+
@@regex_cache ||= {}
|
160
|
+
|
155
161
|
begin
|
156
162
|
@string = string.to_str
|
157
163
|
rescue
|
@@ -647,8 +653,31 @@ class StringScanner
|
|
647
653
|
@match.post_match if matched?
|
648
654
|
end
|
649
655
|
|
650
|
-
|
656
|
+
# Check to see if a specific regular expression has been cached
|
657
|
+
#------------------------------------------------------------------------------
|
658
|
+
def self.regex_cached?(cache_key)
|
659
|
+
@@regex_cache[cache_key] ? true : false
|
660
|
+
end
|
661
|
+
|
662
|
+
# Get cached regular expression
|
663
|
+
#------------------------------------------------------------------------------
|
664
|
+
def self.get_regex(cache_key)
|
665
|
+
@@regex_cache[cache_key]
|
666
|
+
end
|
667
|
+
|
668
|
+
# Cache a regular expression. This is particulary useful for the headonly
|
669
|
+
# option in _scan, so thay we don't create the same regex over and over.
|
670
|
+
# Caused a serious performance problem
|
671
|
+
#
|
672
|
+
# These methods can be used by other user methods to cache their regular expressions
|
673
|
+
#------------------------------------------------------------------------------
|
674
|
+
def self.cache_regex(cache_key, regexp)
|
675
|
+
@@regex_cache[cache_key] = regexp
|
676
|
+
end
|
651
677
|
|
678
|
+
private
|
679
|
+
|
680
|
+
#------------------------------------------------------------------------------
|
652
681
|
def _scan(pattern, succptr, getstr, headonly)
|
653
682
|
raise TypeError, "wrong argument type #{pattern.class.name} (expected Regexp)" unless
|
654
683
|
Regexp === pattern
|
@@ -657,7 +686,10 @@ class StringScanner
|
|
657
686
|
rest = @byte_pos == 0 ? @string : self.rest
|
658
687
|
|
659
688
|
if headonly
|
660
|
-
headonly_pattern =
|
689
|
+
unless (headonly_pattern = StringScanner.get_regex("#{pattern.source}/#{pattern.options}"))
|
690
|
+
headonly_pattern = Regexp.new("\\A(?:#{pattern.source})", pattern.options)
|
691
|
+
StringScanner.cache_regex("#{pattern.source}/#{pattern.options}", headonly_pattern)
|
692
|
+
end
|
661
693
|
@match = headonly_pattern.match rest
|
662
694
|
else
|
663
695
|
@match = pattern.match rest
|
metadata
CHANGED
@@ -1,29 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: motion-strscan
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.
|
4
|
+
version: 0.5.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Brett Walker
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-02-
|
12
|
-
dependencies:
|
13
|
-
- !ruby/object:Gem::Dependency
|
14
|
-
name: rake
|
15
|
-
requirement: !ruby/object:Gem::Requirement
|
16
|
-
requirements:
|
17
|
-
- - ">="
|
18
|
-
- !ruby/object:Gem::Version
|
19
|
-
version: '0'
|
20
|
-
type: :development
|
21
|
-
prerelease: false
|
22
|
-
version_requirements: !ruby/object:Gem::Requirement
|
23
|
-
requirements:
|
24
|
-
- - ">="
|
25
|
-
- !ruby/object:Gem::Version
|
26
|
-
version: '0'
|
11
|
+
date: 2015-02-25 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
27
13
|
description: StringScanner implementation for RubyMotion
|
28
14
|
email:
|
29
15
|
- github@digitalmoksha.com
|
@@ -92,7 +78,8 @@ files:
|
|
92
78
|
- spec/strscan_spec/terminate_spec.rb
|
93
79
|
- spec/strscan_spec/unscan_spec.rb
|
94
80
|
homepage: https://github.com/digitalmoksha/motion-strscan
|
95
|
-
licenses:
|
81
|
+
licenses:
|
82
|
+
- MIT
|
96
83
|
metadata: {}
|
97
84
|
post_install_message:
|
98
85
|
rdoc_options: []
|
@@ -113,7 +100,7 @@ rubyforge_project:
|
|
113
100
|
rubygems_version: 2.4.5
|
114
101
|
signing_key:
|
115
102
|
specification_version: 4
|
116
|
-
summary: StringScanner implementation for RubyMotion
|
103
|
+
summary: A StringScanner implementation for RubyMotion
|
117
104
|
test_files:
|
118
105
|
- spec/helpers/it_behaves_like.rb
|
119
106
|
- spec/string_spec/_shared/slice.rb
|