Class: REXML::Source
- Inherits:
-
Object
show all
- Includes:
- Encoding
- Defined in:
- lib/compat/opal/rexml/source.rb
Constant Summary
Constants included
from Encoding
Encoding::ASCII_8BIT, Encoding::UTF_8
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(arg, encoding = nil) ⇒ Source
Returns a new instance of Source.
81
82
83
84
85
86
87
88
89
90
91
|
# File 'lib/compat/opal/rexml/source.rb', line 81
def initialize(arg, encoding=nil)
@orig = arg
@scanner = StringScanner.new(@orig)
if encoding
self.encoding = encoding
else
detect_encoding
end
@line = 0
@encoded_terms = {}
end
|
Instance Attribute Details
#encoding ⇒ Object
Returns the value of attribute encoding.
67
68
69
|
# File 'lib/compat/opal/rexml/source.rb', line 67
def encoding
@encoding
end
|
#line ⇒ Object
Returns the value of attribute line.
66
67
68
|
# File 'lib/compat/opal/rexml/source.rb', line 66
def line
@line
end
|
Instance Method Details
#buffer ⇒ Object
93
94
95
|
# File 'lib/compat/opal/rexml/source.rb', line 93
def buffer
@scanner.rest
end
|
#buffer_encoding=(encoding) ⇒ Object
103
104
105
|
# File 'lib/compat/opal/rexml/source.rb', line 103
def buffer_encoding=(encoding)
end
|
#current_line ⇒ Object
171
172
173
174
175
176
|
# File 'lib/compat/opal/rexml/source.rb', line 171
def current_line
lines = @orig.split
res = lines.grep @scanner.rest[0..30]
res = res[-1] if res.kind_of? Array
lines.index( res ) if res
end
|
#drop_parsed_content ⇒ Object
97
98
99
100
101
|
# File 'lib/compat/opal/rexml/source.rb', line 97
def drop_parsed_content
if @scanner.pos > Private::SCANNER_RESET_SIZE
@scanner = StringScanner.new(@scanner.rest)
end
end
|
#empty? ⇒ Boolean
167
168
169
|
# File 'lib/compat/opal/rexml/source.rb', line 167
def empty?
@scanner.eos?
end
|
#ensure_buffer ⇒ Object
125
126
|
# File 'lib/compat/opal/rexml/source.rb', line 125
def ensure_buffer
end
|
#match(pattern, cons = false) ⇒ Object
128
129
130
131
132
133
134
135
|
# File 'lib/compat/opal/rexml/source.rb', line 128
def match(pattern, cons=false)
pattern = Regexp.new(Regexp.escape(pattern)) if pattern.is_a?(String)
if cons
@scanner.scan(pattern).nil? ? nil : @scanner
else
@scanner.check(pattern).nil? ? nil : @scanner
end
end
|
#match?(pattern, cons = false) ⇒ Boolean
137
138
139
140
141
142
143
144
145
|
# File 'lib/compat/opal/rexml/source.rb', line 137
def match?(pattern, cons=false)
pattern = Regexp.new(Regexp.escape(pattern)) if pattern.is_a?(String)
window = @scanner.peek(4096)
return false if window.empty?
m = pattern.match(window)
return false unless m && m.begin(0) == 0
@scanner.pos += m[0].length if cons
true
end
|
#peek_byte ⇒ Object
159
160
161
|
# File 'lib/compat/opal/rexml/source.rb', line 159
def peek_byte
@scanner.peek_byte
end
|
#position ⇒ Object
151
152
153
|
# File 'lib/compat/opal/rexml/source.rb', line 151
def position
@scanner.pos
end
|
#position=(pos) ⇒ Object
155
156
157
|
# File 'lib/compat/opal/rexml/source.rb', line 155
def position=(pos)
@scanner.pos = pos
end
|
#read(term = nil) ⇒ Object
112
113
|
# File 'lib/compat/opal/rexml/source.rb', line 112
def read(term = nil)
end
|
#read_until(term) ⇒ Object
115
116
117
118
119
120
121
122
123
|
# File 'lib/compat/opal/rexml/source.rb', line 115
def read_until(term)
pattern = Private::PRE_DEFINED_TERM_PATTERNS[term] || /#{Regexp.escape(term)}/
data = @scanner.scan_until(pattern)
unless data
data = @scanner.rest
@scanner.pos = @scanner.string.bytesize
end
data
end
|
#scan_byte ⇒ Object
163
164
165
|
# File 'lib/compat/opal/rexml/source.rb', line 163
def scan_byte
@scanner.scan_byte
end
|
#skip_spaces ⇒ Object
147
148
149
|
# File 'lib/compat/opal/rexml/source.rb', line 147
def skip_spaces
@scanner.skip(Private::SPACES_PATTERN) ? true : false
end
|