# # Copyright (c) 2001 by Jim Menard # # Released under the same license as Ruby. See # http://www.ruby-lang.org/en/LICENSE.txt. # require 'nqxml/error' module NQXML # Returns string with entities replaced. def NQXML.encode(str) copy = str.gsub('&', '&') copy.gsub!('<', '<') copy.gsub!('>', '>') copy.gsub!('"', '"') copy.gsub!('\'', ''') return copy end # Returns a new string with all of the #NNN; and #xXXX; character refs # replaced by the characters they represent. def NQXML.replaceCharacterRefs(str) return nil if str.nil? copy = str.gsub(/&\#(\d+);/n) { $1.to_i.chr } return copy.gsub(/&\#x([0-9a-f]+);/ni) { $1.hex.chr } end # Returns a new string with all of the special character refs (for # example, & and <) replaced by the characters they represent. def NQXML.replacePredefinedEntityRefs(str) return nil if str.nil? copy = str.gsub(/&/n, '&') copy.gsub!(/"/n, '"') copy.gsub!(/'/n, '\'') copy.gsub!(/>/n, '>') copy.gsub!(/</n, '<') return copy end end