module Hpricot
def self.build(ele = Doc.new, assigns = {}, &blk)
def self.build(ele = Doc.new, assigns = {}, &blk) ele.extend Builder assigns.each do |k, v| ele.instance_variable_set("@#{k}", v) end ele.instance_eval(&blk) ele end
def self.uxs(str)
def self.uxs(str) str.to_s. gsub(/\&(\w+);/) { [NamedCharacters[$1] || ??].pack("U*") }. gsub(/\&\#(\d+);/) { [$1.to_i].pack("U*") } end
def uxs(str)
def uxs(str) str.to_s. gsub(/\&\w+;/) { |x| (XChar::PREDEFINED_U[x] || ??).chr }. gsub(/\&\#(\d+);/) { [$1.to_i].pack("U*") } end
def xchr(str)
def xchr(str) n = XChar::CP1252[str] || str case n when *XChar::VALID XChar::PREDEFINED[n] or (n<128 ? n.chr : "&##{n};") else '*' end end
def xs(str)
def xs(str) str.to_s.unpack('U*').map {|n| xchr(n)}.join # ASCII, UTF-8 rescue str.to_s.unpack('C*').map {|n| xchr(n)}.join # ISO-8859-1, WIN-1252 end