lib/csl/compatibility.rb in csl-1.0.0.pre21 vs lib/csl/compatibility.rb in csl-1.0.0.pre22

- old
+ new

@@ -1,9 +1,9 @@ class Symbol include Comparable - + def <=>(other) return unless other.kind_of? Symbol to_s <=> other.to_s end end unless Symbol.is_a?(Comparable) @@ -18,6 +18,37 @@ end end class Struct alias_method :__class__, :class -end unless Struct.instance_methods.include?(:__class__) \ No newline at end of file +end unless Struct.instance_methods.include?(:__class__) + +module CSL + module_function + + if RUBY_VERSION < '1.9' + + XML_ENTITY_SUBSTITUTION = Hash[*%w{ + & &amp; < &lt; > &gt; ' &apos; " &quot; + }].freeze + + def encode_xml_text(string) + string.gsub(/[&<>]/) { |match| + XML_ENTITY_SUBSTITUTION[match] + } + end + + def encode_xml_attr(string) + string.gsub(/[&<>'"]/) { |match| + XML_ENTITY_SUBSTITUTION[match] + }.inspect + end + else + def encode_xml_text(string) + string.encode(:xml => :text) + end + + def encode_xml_attr(string) + string.encode(:xml => :attr) + end + end +end