Class: Canon::Xml::CharacterEncoder
- Inherits:
-
Object
- Object
- Canon::Xml::CharacterEncoder
- Defined in:
- lib/canon/xml/character_encoder.rb
Overview
Character encoder for C14N 1.1 Handles UTF-8 encoding and character reference encoding per spec
Instance Method Summary collapse
-
#encode_attribute(value) ⇒ Object
Encode attribute value Replace: & → &, < → <, “ → ", #x9 → 	, #xA → 
, #xD → 
.
-
#encode_text(text) ⇒ Object
Encode text node content Replace: & → &, < → <, > → >, #xD → 
.
Instance Method Details
#encode_attribute(value) ⇒ Object
Encode attribute value Replace: & → &, < → <, “ → ",
#x9 → 	, #xA → 
, #xD → 
24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/canon/xml/character_encoder.rb', line 24 def encode_attribute(value) value.gsub(/[&<"\t\n\r]/) do |char| case char when "&" then "&" when "<" then "<" when '"' then """ when "\t" then "	" when "\n" then "
" when "\r" then "
" end end end |
#encode_text(text) ⇒ Object
Encode text node content Replace: & → &, < → <, > → >, #xD → 
10 11 12 13 14 15 16 17 18 19 |
# File 'lib/canon/xml/character_encoder.rb', line 10 def encode_text(text) text.gsub(/[&<>\r]/) do |char| case char when "&" then "&" when "<" then "<" when ">" then ">" when "\r" then "
" end end end |