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:
		
							parent
							
								
									418b4ef498
								
							
						
					
					
						commit
						6b9d65923a
					
				| 
						 | 
				
			
			@ -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);
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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();
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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.
 | 
			
		||||
      #
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue