class String
Public Instance Methods
classify_for_zaml()
click to toggle source
# File lib/icss/serialization/zaml.rb, line 312 def classify_for_zaml unless RUBY_VERSION >= "1.9" return :escaped if (self =~ ZAML::HI_BIT_CHARS_RE) end case when self == '' :bare when (self =~ ZAML::EXTENDED_CHARS_RE) :escaped when ( (self =~ ZAML::SIMPLE_STRING_RE) or (self =~ /\A\n* /) or (self =~ /[ \r]\s*\z/) or (self =~ /^[>|][-+\d]*\s/i) ) :escaped when self =~ /\n/ :complex when ( (self[-1..-1] =~ /\s/) or (self =~ /[\s:]$/) or (self =~ /[,\[\]\{\}\r\t]|:\s|\s#/) or (self =~ /\A([-:?!#&*'"]|<<|%.+:.)/) ) :escaped else :simple end end
escaped_for_zaml()
click to toggle source
# File lib/icss/serialization/zaml.rb, line 298 def escaped_for_zaml gsub( /\x5C/, "\\\\\\" ). # Demi-kludge for Maglev/rubinius; the regexp should be /\\/ but parsetree chokes on that. gsub( /"/, "\\\"" ). gsub( /([\x00-\x1F])/ ){|x| ZAML::ZAML_ESCAPES[ x.unpack("C")[0] ] } end
to_zaml(z=ZAML.new)
click to toggle source
# File lib/icss/serialization/zaml.rb, line 342 def to_zaml(z=ZAML.new) z.first_time_only(self) { case cl = classify_for_zaml when :bare then z.emit('""') when :escaped then z.emit("\"#{escaped_for_zaml}\"") when :simple then z.emit(self) when :complex lines = split("\n",-1) self =~ /(\s+)\z/ if $1.nil? then z.emit('|-') ; lastline = "" elsif $1 == "\n" then z.emit('|') ; lastline = "\n" ; lines.pop else z.emit('|+') ; lastline = "" ; lines.pop ; end z.nested{ lines.each{|line| z.nl; z.emit(line) } } z.emit(lastline) z.nl else raise("Misclassified string: #{cl}!") end } end