diff options
Diffstat (limited to 'lib/rdoc/markdown/literals_1_9.rb')
-rw-r--r-- | lib/rdoc/markdown/literals_1_9.rb | 25 |
1 files changed, 14 insertions, 11 deletions
diff --git a/lib/rdoc/markdown/literals_1_9.rb b/lib/rdoc/markdown/literals_1_9.rb index 6782eb7910..f7bfbe27a1 100644 --- a/lib/rdoc/markdown/literals_1_9.rb +++ b/lib/rdoc/markdown/literals_1_9.rb @@ -23,8 +23,7 @@ class RDoc::Markdown::Literals # Prepares for parsing +str+. If you define a custom initialize you must # call this method before #parse def setup_parser(str, debug=false) - @string = str - @pos = 0 + set_string str, 0 @memoizations = Hash.new { |h,k| h[k] = {} } @result = nil @failed_rule = nil @@ -37,7 +36,6 @@ class RDoc::Markdown::Literals attr_reader :failing_rule_offset attr_accessor :result, :pos - def current_column(target=pos) if c = string.rindex("\n", target-1) return target - c - 1 @@ -71,6 +69,13 @@ class RDoc::Markdown::Literals @string[start..@pos-1] end + # Sets the string and current parsing position for the parser. + def set_string string, pos + @string = string + @string_size = string ? string.size : 0 + @pos = pos + end + def show_pos width = 10 if @pos < width @@ -177,19 +182,19 @@ class RDoc::Markdown::Literals return nil end - if "".respond_to? :getbyte + if "".respond_to? :ord def get_byte - if @pos >= @string.size + if @pos >= @string_size return nil end - s = @string.getbyte @pos + s = @string[@pos].ord @pos += 1 s end else def get_byte - if @pos >= @string.size + if @pos >= @string_size return nil end @@ -238,8 +243,7 @@ class RDoc::Markdown::Literals old_pos = @pos old_string = @string - @pos = other.pos - @string = other.string + set_string other.string, other.pos begin if val = __send__(rule, *args) @@ -250,8 +254,7 @@ class RDoc::Markdown::Literals end val ensure - @pos = old_pos - @string = old_string + set_string old_string, old_pos end end |