Class: RubyXL::Text
Overview
Constant Summary
collapse
- INVALID_XML10_CHARS =
/([^\x09\x0A\x0D\x20-\uD7FF\uE000-\uFFFD\u{10000}-\u{10FFFF}])/
- ESCAPED_UNICODE =
/_x([0-9A-F]{4})_/
Instance Attribute Summary
#local_namespaces
Class Method Summary
collapse
Instance Method Summary
collapse
#==, included, #index_in_collection, #init_child_nodes, #initialize, #write_xml
Class Method Details
.escape_bad_xml_chars(str) ⇒ Object
31
32
33
34
|
# File 'lib/rubyXL/objects/text.rb', line 31
def self.escape_bad_xml_chars(str)
return str unless str.is_a?(String)
str.gsub(INVALID_XML10_CHARS) { |bad_char| format('_x%04X_', bad_char.ord) }
end
|
Instance Method Details
#before_write_xml ⇒ Object
21
22
23
24
25
|
# File 'lib/rubyXL/objects/text.rb', line 21
def before_write_xml
preserve_whitespace
self.value = RubyXL::Text::escape_bad_xml_chars(value)
true
end
|
#to_s ⇒ Object
27
28
29
|
# File 'lib/rubyXL/objects/text.rb', line 27
def to_s
value.to_s.gsub(ESCAPED_UNICODE) { Regexp.last_match(1).hex.chr(::Encoding::UTF_8) }
end
|