lib/maruku/input/parse_span.rb
# Reads a simple string (no formatting) until one of exit_on_chars,
# while escaping the escaped.
# If the string is empty, it returns nil.
# By default, raises on error if the string terminates unexpectedly. This can be
# by setting the last argument to false.
Reads a simple string (no formatting) until one of exit_on_chars,
while escaping the escaped.
If the string is empty, it returns nil.
By default, raises on error if the string terminates unexpectedly. This can be
by setting the last argument to false.
Reads a simple string ( no formatting ) until one of exit_on_chars while escaping the escaped . If the string is empty it returns nil . By default raises on error if the string terminates unexpectedly . This can be by setting the last argument to false .
def read_simple(src, escaped, exit_on_chars=nil, exit_on_strings=nil, warn=true)
    text = ""
    escaped = Array(escaped)
    exit_on_chars = Array(exit_on_chars)
    exit_on_strings = Array(exit_on_strings)
    while true
      c = src.cur_char
      break if exit_on_chars.include?(c)
      break if exit_on_strings.any? {|x| src.cur_chars_are x }
      case c
      when nil
        if warn
          maruku_error "String finished while reading (break on " +
            "#{(exit_on_chars + exit_on_strings).inspect})" +
            " already read: #{text.inspect}", src
        end
        break
      when "\\"
        d = src.next_char
        if escaped.include? d
          src.ignore_chars(2)
          text << d
        else
          text << src.shift_char
        end
      else
        text << src.shift_char
      end
    end
    text.empty? ? nil : text
  end
def read_simple ( src , escaped , exit_on_chars = nil , exit_on_strings = nil , warn = true ) text = "" escaped = Array ( escaped ) exit_on_chars = Array ( exit_on_chars ) exit_on_strings = Array ( exit_on_strings ) while true c = src . cur_char break if exit_on_chars . include? ( c ) break if exit_on_strings . any? { | x | src . cur_chars_are x } case c when nil if warn maruku_error "String finished while reading (break on " + "#{(exit_on_chars + exit_on_strings).inspect})" + " already read: #{text.inspect}" , src end break when "\\" d = src . next_char if escaped . include? d src . ignore_chars ( 2 ) text << d else text << src . shift_char end else text << src . shift_char end end text . empty? ? nil : text end
Reads a simple string (no formatting) until one of exit_on_chars,
while escaping the escaped.
Reads a simple string ( no formatting ) until one of exit_on_chars while escaping the escaped .
src
<not_specific>
escaped
<not_specific>
exit_on_chars
<not_specific>
exit_on_strings
<not_specific>
warn
<not_specific>