Method: RbYAML::Emitter#write_double_quoted

Defined in:
lib/rbyaml/emitter.rb

#write_double_quoted(text, split = true) ⇒ Object



895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
# File 'lib/rbyaml/emitter.rb', line 895

def write_double_quoted(text, split=true)
  write_indicator('"', true)
  start = ending = 0
  while ending <= text.length
    ch = nil
    ch = text[ending] if ending < text.length
    if ch.nil? || "\"\\\x85".include?(ch) || !(?\x20 <= ch && ch <= ?\x7E)
      if start < ending
        data = text[start...ending]
        @column += data.length
        @stream.write(data)
        start = ending
      end
      if !ch.nil?
        if ESCAPE_REPLACEMENTS.include?(ch)
          data = "\\"+ESCAPE_REPLACEMENTS[ch]
        elsif ch <= ?\xFF
          data = "\\x%02X" % ch
        end
        @column += data.length
        @stream.write(data)
        start = ending+1
      end
    end
    if (0 < ending && ending < text.length-1) && (ch == 32 || start >= ending) && @column+(ending-start) > @best_width && split
      data = text[start...ending]+"\\"
      start = ending if start < ending
      @column += data.length
      @stream.write(data)
      write_indent
      @whitespace = false
      @indention = false
      if text[start] == 32
        data = "\\"
        @column += data.length
        @stream.write(data)
      end
    end
    ending += 1
  end
  write_indicator('"', false)
end