Class: REXML::Source

Inherits:
Object
  • Object
show all
Includes:
Encoding
Defined in:
lib/compat/opal/rexml/source.rb

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

#encodingObject

Returns the value of attribute encoding.



66
67
68
# File 'lib/compat/opal/rexml/source.rb', line 66

def encoding
  @encoding
end

#lineObject (readonly)

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

#bufferObject



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)
  # no-op under Opal (no Encoding support)
end

#current_lineObject



172
173
174
175
176
177
# File 'lib/compat/opal/rexml/source.rb', line 172

def current_line
  lines = @orig.split
  res = lines.grep @scanner.rest[0..30]
  res = res[-1] if res.is_a? Array
  lines.index(res) if res
end

#drop_parsed_contentObject



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

Returns:

  • (Boolean)


168
169
170
# File 'lib/compat/opal/rexml/source.rb', line 168

def empty?
  @scanner.eos?
end

#ensure_bufferObject



125
# File 'lib/compat/opal/rexml/source.rb', line 125

def ensure_buffer; end

#match(pattern, cons = false) ⇒ Object



127
128
129
130
131
132
133
134
# File 'lib/compat/opal/rexml/source.rb', line 127

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

Returns:

  • (Boolean)


136
137
138
139
140
141
142
143
144
145
146
# File 'lib/compat/opal/rexml/source.rb', line 136

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_byteObject



160
161
162
# File 'lib/compat/opal/rexml/source.rb', line 160

def peek_byte
  @scanner.peek_byte
end

#positionObject



152
153
154
# File 'lib/compat/opal/rexml/source.rb', line 152

def position
  @scanner.pos
end

#position=(pos) ⇒ Object



156
157
158
# File 'lib/compat/opal/rexml/source.rb', line 156

def position=(pos)
  @scanner.pos = pos
end

#read(term = nil) ⇒ Object



113
# File 'lib/compat/opal/rexml/source.rb', line 113

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_byteObject



164
165
166
# File 'lib/compat/opal/rexml/source.rb', line 164

def scan_byte
  @scanner.scan_byte
end

#skip_spacesObject



148
149
150
# File 'lib/compat/opal/rexml/source.rb', line 148

def skip_spaces
  @scanner.skip(Private::SPACES_PATTERN) ? true : false
end