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



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

def before_write_xml
  preserve_whitespace
  self.value.gsub(INVALID_XML10_CHARS) { |bad_char| format('_x%04x_', bad_char.ord) }
  true
end

#to_sObject



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

def to_s
  value.to_s.gsub(ESCAPED_UNICODE) { Regexp.last_match(1).hex.chr(::Encoding::UTF_8) }
end