From ab1816b214c66292d29ad4a9775edb323bc73a3b Mon Sep 17 00:00:00 2001 From: NAITOH Jun Date: Sat, 2 Mar 2024 21:13:56 +0900 Subject: [PATCH] Remove `Source#string=` method ## Why? https://github.com/ruby/rexml/pull/114#discussion_r1501773803 > I want to just change scan pointer (StringScanner#pos=) instead of changing @scanner.string. --- lib/rexml/parsers/baseparser.rb | 23 +++++++++++++---------- lib/rexml/source.rb | 8 ++++++-- test/parse/test_notation_declaration.rb | 2 +- 3 files changed, 20 insertions(+), 13 deletions(-) diff --git a/lib/rexml/parsers/baseparser.rb b/lib/rexml/parsers/baseparser.rb index bc59bcdc..c79de0eb 100644 --- a/lib/rexml/parsers/baseparser.rb +++ b/lib/rexml/parsers/baseparser.rb @@ -211,8 +211,9 @@ def pull_event #STDERR.puts @source.encoding #STDERR.puts "BUFFER = #{@source.buffer.inspect}" if @document_status == nil + start_position = @source.position if @source.match("/um, true)[1] ] @@ -224,7 +225,7 @@ def pull_event else message = "#{base_error_message}: invalid name" end - @source.string = "/um, true) @@ -325,7 +327,7 @@ def pull_event else message = "#{base_error_message}: invalid name" end - @source.string = " " scanner << match_data[1] - scanner.pos = pos + scanner.pos = start_position closed = !match_data[2].nil? next end diff --git a/lib/rexml/source.rb b/lib/rexml/source.rb index 4111d1d3..2db13e1c 100644 --- a/lib/rexml/source.rb +++ b/lib/rexml/source.rb @@ -76,8 +76,12 @@ def match(pattern, cons=false) end end - def string=(string) - @scanner.string = string + def position + @scanner.pos + end + + def position=(pos) + @scanner.pos = pos end # @return true if the Source is exhausted diff --git a/test/parse/test_notation_declaration.rb b/test/parse/test_notation_declaration.rb index 19a0536d..9e81b6a4 100644 --- a/test/parse/test_notation_declaration.rb +++ b/test/parse/test_notation_declaration.rb @@ -35,7 +35,7 @@ def test_no_name Line: 5 Position: 72 Last 80 unconsumed characters: - ]> + ]> DETAIL end