My code is simple:
"<3>".encode🙂xml => :text)
I am completely new to RGSS and ruby, so I may simply be misusing the #encode method of String. However, whenever I try to invoke #encode with the hash option ":xml => :text", it throws a "Encoding::ConverterNotFoundError" with the text "code converter not found (xml_text)".
This leads me to believe this converter option is invalid in RGSS, and that the converter has not been implemented; So, I would like to do this myself.
I figured simply inheriting from Encoding::Converter would allow me to manage this option, but I just can't seem to get a working example - because the initialize parameters require two different encodings (source and destination); which also causes the ConverterNotFoundError to be thrown if you pass the options. This time, with "UTF-8" to "UTF-8" not found.
class XmlTextEncodingConverter < Encoding::Converter XmlCharRegexp = /[<|>|\&|\"]/ XmlCodes = { '<' => "lt;", '>' => "gt;", '&' => "&", '"' => """ } alias :xml_text_initialize :initialize def initialize(options) xml_text_initialize("UTF-8", "UTF-8") @options = options end alias :xml_text_convert :convert def convert(text) result = xml_text_convert(text) case @options[:xml] when :text result = result.gsub(XmlCharRegexp) { |m| XmlCodes["#{x}"] } end end endAll-in-all, I can't seem to find ANY documentation in RUBY about extending Encoding::Converter to create custom encodings, or find any core "require" commands to allow "xml_text" or "xml_attr" to become valid options.
Any advice on how to resolve the issue of encoding/decoding xml special characters in strings would be tremendously appreciated.
"<3>".encode🙂xml => :text)
I am completely new to RGSS and ruby, so I may simply be misusing the #encode method of String. However, whenever I try to invoke #encode with the hash option ":xml => :text", it throws a "Encoding::ConverterNotFoundError" with the text "code converter not found (xml_text)".
This leads me to believe this converter option is invalid in RGSS, and that the converter has not been implemented; So, I would like to do this myself.
I figured simply inheriting from Encoding::Converter would allow me to manage this option, but I just can't seem to get a working example - because the initialize parameters require two different encodings (source and destination); which also causes the ConverterNotFoundError to be thrown if you pass the options. This time, with "UTF-8" to "UTF-8" not found.
class XmlTextEncodingConverter < Encoding::Converter XmlCharRegexp = /[<|>|\&|\"]/ XmlCodes = { '<' => "lt;", '>' => "gt;", '&' => "&", '"' => """ } alias :xml_text_initialize :initialize def initialize(options) xml_text_initialize("UTF-8", "UTF-8") @options = options end alias :xml_text_convert :convert def convert(text) result = xml_text_convert(text) case @options[:xml] when :text result = result.gsub(XmlCharRegexp) { |m| XmlCodes["#{x}"] } end end endAll-in-all, I can't seem to find ANY documentation in RUBY about extending Encoding::Converter to create custom encodings, or find any core "require" commands to allow "xml_text" or "xml_attr" to become valid options.
Any advice on how to resolve the issue of encoding/decoding xml special characters in strings would be tremendously appreciated.