Class: RubyXL::Text

Inherits:
OOXMLObject show all
Defined in:
lib/rubyXL/objects/text.rb

Overview

Constant Summary collapse

INVALID_XML10_CHARS =

www.w3.org/TR/REC-xml/#NT-Char: Char ::= #x9 | #xA | #xD | [#x20-#xD7FF] | [#xE000-#xFFFD] | [#x10000-#x10FFFF]

/([^\x09\x0A\x0D\x20-\uD7FF\uE000-\uFFFD\u{10000}-\u{10FFFF}])/
ESCAPED_UNICODE =
/_x([0-9A-F]{4})_/

Instance Attribute Summary

Attributes included from OOXMLObjectInstanceMethods

#local_namespaces

Instance Method Summary collapse

Methods included from OOXMLObjectInstanceMethods

#==, included, #index_in_collection, #initialize, #write_xml

Instance Method Details

#before_write_xmlObject



20
21
22
23
24
# File 'lib/rubyXL/objects/text.rb', line 20

def before_write_xml
  preserve_whitespace
  self.value.gsub!(INVALID_XML10_CHARS) { |c| "_x%04x_" % c.ord }
  true
end

#to_sObject



26
27
28
# File 'lib/rubyXL/objects/text.rb', line 26

def to_s
  value.to_s.gsub(ESCAPED_UNICODE) { |m| $1.hex.chr(::Encoding::UTF_8) }
end