Use a method for getting input in the XML lexer.

Instead of directly accessing the `data` instance variable the C/Java code now
uses the method `read_data`. This is part of one of the various steps required
to allow Oga to read data from IO like instances. It also means I can freely
change the name of the instance variable without also having to change the
C/Java code.
This commit is contained in:
Yorick Peterse 2014-05-21 00:27:23 +02:00
parent 418b4ef498
commit 6b9d65923a
3 changed files with 13 additions and 4 deletions

View File

@ -70,12 +70,12 @@ void liboga_xml_lexer_callback_simple(VALUE self, const char *name)
VALUE oga_xml_lexer_advance(VALUE self) VALUE oga_xml_lexer_advance(VALUE self)
{ {
/* Pull the data in from Ruby land. */ /* Pull the data in from Ruby land. */
VALUE data_ivar = rb_ivar_get(self, rb_intern("@data")); VALUE data_block = rb_funcall(self, rb_intern("read_data"), 0);
/* Make sure that all data passed back to Ruby has the proper encoding. */ /* Make sure that all data passed back to Ruby has the proper encoding. */
rb_encoding *encoding = rb_enc_get(data_ivar); rb_encoding *encoding = rb_enc_get(data_block);
char *data_str_val = StringValuePtr(data_ivar); char *data_str_val = StringValuePtr(data_block);
const char *p = data_str_val; const char *p = data_str_val;
const char *pe = data_str_val + strlen(data_str_val); const char *pe = data_str_val + strlen(data_str_val);

View File

@ -82,7 +82,7 @@ public class Lexer extends RubyObject
public IRubyObject advance_native(ThreadContext context) public IRubyObject advance_native(ThreadContext context)
{ {
// Pull the data in from Ruby land. // Pull the data in from Ruby land.
RubyString rb_str = (RubyString) this.getInstanceVariable("@data"); RubyString rb_str = (RubyString) this.callMethod(context, "read_data");
Encoding encoding = rb_str.getEncoding(); Encoding encoding = rb_str.getEncoding();
byte[] data = rb_str.getBytes(); byte[] data = rb_str.getBytes();

View File

@ -64,6 +64,15 @@ module Oga
@elements = [] @elements = []
end end
##
# Returns the next block of data to lex.
#
# @return [String]
#
def read_data
return @data
end
## ##
# Gathers all the tokens for the input and returns them as an Array. # Gathers all the tokens for the input and returns them as an Array.
# #