def convert_text!(text, error_handler)
      text = AnselToUnicode.new(error_handler, true).convert(text) if convert_marc8_to_utf8?

      # Turn Horizon's weird escaping into UTF8: <U+nnnn> where nnnn is a hex unicode
      # codepoint, turn it UTF8 for that codepoint
      if settings["horizon.destination_encoding"] == "UTF8" &&
          (settings["horizon.codepoint_translate"].to_s == "true" ||
           settings["horizon.character_reference_translate"].to_s == "true")

          regexp = if settings["horizon.codepoint_translate"].to_s == "true" && settings["horizon.character_reference_translate"].to_s == "true"
            # unicode codepoint in either HTML char reference form OR
            # weird horizon form. 
             /(?:\<U\+|&#x)([0-9A-Fa-f]{4})(?:\>|;)/
          elsif settings["horizon.codepoint_translate"].to_s == "true"
            # just weird horizon form
            /\<U\+([0-9A-Fa-f]{4})\>/
          else # just character references
            /&#x([0-9A-Fa-f]{4});/
          end
          
        text.gsub!(regexp) do
          [$1.hex].pack("U")
        end
      end

      # eliminate illegal control chars. All ASCII less than 0x20
      # _except_ for four legal ones (including MARC delimiters). 
      # http://www.loc.gov/marc/specifications/specchargeneral.html#controlfunction
      # this is all bytes from 0x00 to 0x19 except for the allowed 1B, 1D, 1E, 1F. 
      text.gsub!(/[\x00-\x1A\x1C]/, '')

      return text
    end
def convert_text!(text, error_handler)
      text = AnselToUnicode.new(error_handler, true).convert(text) if convert_marc8_to_utf8?

      # Turn Horizon's weird escaping into UTF8: <U+nnnn> where nnnn is a hex unicode
      # codepoint, turn it UTF8 for that codepoint
      if settings["horizon.destination_encoding"] == "UTF8" &&
          (settings["horizon.codepoint_translate"].to_s == "true" ||
           settings["horizon.character_reference_translate"].to_s == "true")

          regexp = if settings["horizon.codepoint_translate"].to_s == "true" && settings["horizon.character_reference_translate"].to_s == "true"
            # unicode codepoint in either HTML char reference form OR
            # weird horizon form. 
             /(?:\<U\+|&#x)([0-9A-Fa-f]{4})(?:\>|;)/
          elsif settings["horizon.codepoint_translate"].to_s == "true"
            # just weird horizon form
            /\<U\+([0-9A-Fa-f]{4})\>/
          else # just character references
            /&#x([0-9A-Fa-f]{4});/
          end
          
        text.gsub!(regexp) do
          [$1.hex].pack("U")
        end
      end

      # eliminate illegal control chars. All ASCII less than 0x20
      # _except_ for four legal ones (including MARC delimiters). 
      # http://www.loc.gov/marc/specifications/specchargeneral.html#controlfunction
      # this is all bytes from 0x00 to 0x19 except for the allowed 1B, 1D, 1E, 1F. 
      text.gsub!(/[\x00-\x1A\x1C]/, '')

      return text
    end
Converts from Marc8 to UTF8 if neccesary.

 Also replaces escaped unicode codepoints using custom Horizon "<U+nnnn>" format
 Or standard MARC 'lossless encoding' "&#xHHHH;" format.