diff --git a/ext/c/lexer.rl b/ext/c/lexer.rl index 9e19463..f239f1b 100644 --- a/ext/c/lexer.rl +++ b/ext/c/lexer.rl @@ -70,12 +70,12 @@ void liboga_xml_lexer_callback_simple(VALUE self, const char *name) VALUE oga_xml_lexer_advance(VALUE self) { /* 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. */ - 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 *pe = data_str_val + strlen(data_str_val); diff --git a/ext/java/org/liboga/xml/Lexer.rl b/ext/java/org/liboga/xml/Lexer.rl index 0162e89..d6f10f7 100644 --- a/ext/java/org/liboga/xml/Lexer.rl +++ b/ext/java/org/liboga/xml/Lexer.rl @@ -82,7 +82,7 @@ public class Lexer extends RubyObject public IRubyObject advance_native(ThreadContext context) { // 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(); byte[] data = rb_str.getBytes(); diff --git a/lib/oga/xml/lexer.rb b/lib/oga/xml/lexer.rb index e58c452..1d73132 100644 --- a/lib/oga/xml/lexer.rb +++ b/lib/oga/xml/lexer.rb @@ -64,6 +64,15 @@ module Oga @elements = [] 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. #