Module: Xlsxtream::XML
- Defined in:
- lib/xlsxtream/xml.rb
Constant Summary collapse
- XML_ESCAPES =
{ '&' => '&', '"' => '"', '<' => '<', '>' => '>', }.freeze
- XML_DECLARATION =
%'<?xml version="1.0" encoding="UTF-8" standalone="yes"?>\r\n'.freeze
- WS_AROUND_TAGS =
/(?<=>)\s+|\s+(?=<)/.freeze
- UNSAFE_ATTR_CHARS =
/[&"<>]/.freeze
- UNSAFE_VALUE_CHARS =
/[&<>]/.freeze
- 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}]/.freeze
- ESCAPE_CHAR =
ST_Xstring escaping
lambda { |c| '_x%04X_'.freeze % c.ord }.freeze
Class Method Summary collapse
Class Method Details
.escape_attr(string) ⇒ Object
35 36 37 |
# File 'lib/xlsxtream/xml.rb', line 35 def escape_attr(string) string.gsub(UNSAFE_ATTR_CHARS, XML_ESCAPES) end |
.escape_value(string) ⇒ Object
39 40 41 |
# File 'lib/xlsxtream/xml.rb', line 39 def escape_value(string) string.gsub(UNSAFE_VALUE_CHARS, XML_ESCAPES).gsub(INVALID_XML10_CHARS, &ESCAPE_CHAR) end |
.header ⇒ Object
27 28 29 |
# File 'lib/xlsxtream/xml.rb', line 27 def header XML_DECLARATION end |
.strip(xml) ⇒ Object
31 32 33 |
# File 'lib/xlsxtream/xml.rb', line 31 def strip(xml) xml.gsub(WS_AROUND_TAGS, ''.freeze) end |