Class: MaRuKu::In::Markdown::SpanLevelParser::CharSourceManual

### Home Classes Methods

### In Files

- lib/maruku/input/charsource.rb

### Parent

Object

### Methods

- ::new
- #consume_whitespace
- #cur_char
- #cur_chars
- #cur_chars_are
- #current_remaining_buffer
- #describe
- #describe_pos
- #ignore_char
- #ignore_chars
- #next_char
- #next_matches
- #read_regexp
- #shift_char

### Class/Module Index

Quicksearch

- MaRuKu
- MaRuKu::AttributeList
- MaRuKu::Errors
- MaRuKu::Exception
- MaRuKu::HTMLElement
- MaRuKu::HTMLFragment
- MaRuKu::Helpers
- MaRuKu::In
- MaRuKu::In::Markdown
- MaRuKu::In::Markdown::BlockLevelParser
- MaRuKu::In::Markdown::BlockLevelParser::BlockContext
- MaRuKu::In::Markdown::BlockLevelParser::LineSource
- MaRuKu::In::Markdown::SpanExtension
- MaRuKu::In::Markdown::SpanLevelParser
- MaRuKu::In::Markdown::SpanLevelParser::CharSourceDebug
- MaRuKu::In::Markdown::SpanLevelParser::CharSourceManual
- MaRuKu::In::Markdown::SpanLevelParser::CharSourceStrscan
- MaRuKu::In::Markdown::SpanLevelParser::HTMLHelper
- MaRuKu::In::Markdown::SpanLevelParser::SpanContext
- MaRuKu::MDDocument
- MaRuKu::MDElement
- MaRuKu::MDHTMLElement
- MaRuKu::MDLine
- MaRuKu::NokogiriHTMLFragment
- MaRuKu::Out
- MaRuKu::Out::EntityTable
- MaRuKu::Out::HTML
- MaRuKu::Out::HTML::HTMLElement
- MaRuKu::Out::Latex
- MaRuKu::Out::Latex::MDDocumentExtensions
- MaRuKu::Out::Markdown
- MaRuKu::REXMLHTMLFragment
- MaRuKu::Section
- MaRuKu::Strings
- Maruku
- Maruku::In
- Maruku::In::Markdown
- Maruku::In::Markdown::FencedCode
- Object
- String
- Textile2Signature

No matching classes.

# MaRuKu::In::Markdown::SpanLevelParser::CharSourceManual

a string scanner coded by me

CharSource = CharSourceStrscan # Faster on LONG documents. But StringScanner is buggy in Rubinius CharSource = CharSourceDebug

### Public Class Methods

new(s, parent=nil) click to toggle source

    # File lib/maruku/input/charsource.rb, line 23
    def initialize(s, parent=nil)
      raise "Passed #{s.class}" if not s.kind_of? String
      @buffer = s
      @buffer_index = 0
      @parent = parent
    end

### Public Instance Methods

consume_whitespace() click to toggle source

    # File lib/maruku/input/charsource.rb, line 84
    def consume_whitespace
      while c = cur_char
        break unless (c == ' ' || c == "\t")
        ignore_char
      end
    end

cur_char() click to toggle source

Return current char as a String (or nil).

    # File lib/maruku/input/charsource.rb, line 31
    def cur_char
      cur_chars(1)
    end

cur_chars(n) click to toggle source

Return the next n chars as a String.

    # File lib/maruku/input/charsource.rb, line 36
    def cur_chars(n)
      return nil if @buffer_index >= @buffer.size
      @buffer[@buffer_index, n]
    end

cur_chars_are(string) click to toggle source

    # File lib/maruku/input/charsource.rb, line 65
    def cur_chars_are(string)
      cur_chars(string.size) == string
    end

current_remaining_buffer() click to toggle source

    # File lib/maruku/input/charsource.rb, line 61
    def current_remaining_buffer
      @buffer[@buffer_index, @buffer.size - @buffer_index]
    end

describe() click to toggle source

    # File lib/maruku/input/charsource.rb, line 91
    def describe
      s = describe_pos(@buffer, @buffer_index)
      if @parent
        s += "\n\n" + @parent.describe
      end
      s
    end

describe_pos(buffer, buffer_index) click to toggle source

    # File lib/maruku/input/charsource.rb, line 99
    def describe_pos(buffer, buffer_index)
      len = 75
      num_before = [len/2, buffer_index].min
      num_after = [len/2, buffer.size - buffer_index].min
      num_before_max = buffer_index
      num_after_max = buffer.size - buffer_index

      num_before = [num_before_max, len - num_after].min
      num_after  = [num_after_max, len - num_before].min

      index_start = [buffer_index - num_before, 0].max
      index_end   = [buffer_index + num_after, buffer.size].min

      size = index_end - index_start

      str = buffer[index_start, size]
      str.gsub!("\n", 'N')
      str.gsub!("\t", 'T')

      if index_end == buffer.size
        str += "EOF"
      end

      pre_s = buffer_index - index_start
      pre_s = [pre_s, 0].max
      pre_s2 = [len - pre_s, 0].max
      pre = " " * pre_s

      "-" * len + "\n" +
        str + "\n" +
        "-" * pre_s + "|" + "-" * pre_s2 + "\n" +
        pre + "+--- Byte #{buffer_index}\n"+

        "Shown bytes [#{index_start} to #{size}] of #{buffer.size}:\n"+
        buffer.gsub(/^/, ">")
    end

ignore_char() click to toggle source

    # File lib/maruku/input/charsource.rb, line 53
    def ignore_char
      @buffer_index += 1
    end

ignore_chars(n) click to toggle source

    # File lib/maruku/input/charsource.rb, line 57
    def ignore_chars(n)
      @buffer_index += n
    end

next_char() click to toggle source

Return the char after current char as a String (or nil).

    # File lib/maruku/input/charsource.rb, line 42
    def next_char
      return nil if @buffer_index + 1 >= @buffer.size
      @buffer[@buffer_index + 1, 1]
    end

next_matches(r) click to toggle source

    # File lib/maruku/input/charsource.rb, line 69
    def next_matches(r)
      r2 = /^.{#{@buffer_index}}#{r}/
      r2.match @buffer
    end

read_regexp(r) click to toggle source

    # File lib/maruku/input/charsource.rb, line 74
    def read_regexp(r)
      r2 = /^#{r}/
      rest = current_remaining_buffer
      m = r2.match(rest)
      if m
        @buffer_index += m.to_s.size
      end
      m
    end

shift_char() click to toggle source

    # File lib/maruku/input/charsource.rb, line 47
    def shift_char
      c = cur_char
      @buffer_index += 1
      c
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.