From 6b9d65923a73eb7bafd15ebda76b0f88d0a6aa0f Mon Sep 17 00:00:00 2001 From: Yorick Peterse Date: Wed, 21 May 2014 00:27:23 +0200 Subject: [PATCH] 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. --- ext/c/lexer.rl | 6 +++--- ext/java/org/liboga/xml/Lexer.rl | 2 +- lib/oga/xml/lexer.rb | 9 +++++++++ 3 files changed, 13 insertions(+), 4 deletions(-) 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. #