File tree Expand file tree Collapse file tree 1 file changed +13
-2
lines changed Expand file tree Collapse file tree 1 file changed +13
-2
lines changed Original file line number Diff line number Diff line change @@ -34,6 +34,16 @@ class Source
34
34
attr_reader :line
35
35
attr_reader :encoding
36
36
37
+ module Private
38
+ PRE_DEFINED_TERM_PATTERNS = { }
39
+ pre_defined_terms = [ "'" , '"' ]
40
+ pre_defined_terms . each do |term |
41
+ PRE_DEFINED_TERM_PATTERNS [ term ] = /#{ Regexp . escape ( term ) } /
42
+ end
43
+ end
44
+ private_constant :Private
45
+ include Private
46
+
37
47
# Constructor
38
48
# @param arg must be a String, and should be a valid XML document
39
49
# @param encoding if non-null, sets the encoding of the source to this
@@ -69,7 +79,8 @@ def read(term = nil)
69
79
end
70
80
71
81
def read_until ( term )
72
- data = @scanner . scan_until ( /#{ Regexp . escape ( term ) } / )
82
+ pattern = Private ::PRE_DEFINED_TERM_PATTERNS [ term ] || /#{ Regexp . escape ( term ) } /
83
+ data = @scanner . scan_until ( pattern )
73
84
unless data
74
85
data = @scanner . rest
75
86
@scanner . pos = @scanner . string . bytesize
@@ -179,7 +190,7 @@ def read(term = nil)
179
190
end
180
191
181
192
def read_until ( term )
182
- pattern = /#{ Regexp . escape ( term ) } /
193
+ pattern = Private :: PRE_DEFINED_TERM_PATTERNS [ term ] || /#{ Regexp . escape ( term ) } /
183
194
term = encode ( term )
184
195
begin
185
196
until str = @scanner . scan_until ( pattern )
You can’t perform that action at this time.
0 commit comments