motion-strscan 0.5.0 → 0.5.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: 6ce76e9365737a21abf4825e2750832c950a6e8f
4
- data.tar.gz: 9e8c604e70652a9886190f92548debf544a66778
3
+ metadata.gz: 2a771a294c218fbfdf4fc1613d9d2c19559cef72
4
+ data.tar.gz: 88224c0207bad83b1f6ce3cfef941f0c26d79d83
5
5
  SHA512:
6
- metadata.gz: e427425d5b1525c59ccbdc14a540c36f11f741991f5fe867cc5f9dc84a2004b17b2d8917f5fc1122278555d17e1a407017e30ce25f7dc2782a4b1d7fd7e69422
7
- data.tar.gz: 867b7c8b34e89a51c54ed66a0696174f6f3e23f187e6549d0cccef4e797d98f486782435ed07b9f9436b8cd608a2f43bf76993a0e62a94c4934514086dad9b58
6
+ metadata.gz: 209f1e440b64700af5df1b60904c4a16aea7cb672526f27bf3c872c5abc904e01e82e87d36871606534dfca3a43fa48a2f604f5d2982888d00f689cfc2350524
7
+ data.tar.gz: aec494fbf5b5958a340dd0b3b1aa4735af633ed14b5e489ac78d767ef91e0cd4da274ec466ad66065152149cea8002c79e327647e11c0b1902aad2a220d1441f
data/README.md CHANGED
@@ -15,6 +15,10 @@ And then execute:
15
15
  Or install it yourself as:
16
16
 
17
17
  $ gem install motion-strscan
18
+
19
+ Edit the Rakefile of your RubyMotion project and add the following require line
20
+
21
+ require 'motion-strscan'
18
22
 
19
23
  ## Implementation details
20
24
 
@@ -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
- private
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 = Regexp.new("\\A(?:#{pattern.source})", pattern.options)
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
@@ -1,3 +1,3 @@
1
1
  module MotionStrscan
2
- VERSION = '0.5.0'
2
+ VERSION = '0.5.1'
3
3
  end
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.0
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-22 00:00:00.000000000 Z
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