Class: Integer

Inherits:
Object
  • Object
show all
Defined in:
lib/builder/xchar.rb

Overview

Enhance the Integer class with a XML escaped character conversion.

Constant Summary collapse

XChar =
Builder::XChar

Instance Method Summary collapse

Instance Method Details

#xchr(escape = true) ⇒ Object

XML escaped version of chr. When escape is set to false the CP1252 fix is still applied but utf-8 characters are not converted to character entities.



172
173
174
175
176
177
178
179
180
# File 'lib/builder/xchar.rb', line 172

def xchr(escape=true)
  n = XChar::CP1252[self] || self
  case n when *XChar::VALID
    XChar::PREDEFINED[n] or 
      (n<128 ? n.chr : (escape ? "&##{n};" : [n].pack('U*')))
  else
    Builder::XChar::REPLACEMENT_CHAR
  end
end