Sha256: ad2b6c82510598e7a3dacc5c5bbbecfb4c63f4824ce328b77bd8e3d4d1ac32e5

Contents?: true

Size: 799 Bytes

Versions: 2

Compression:

Stored size: 799 Bytes

Contents

# Extension of String class to handle conversion from/to
# UTF-8/ISO-8869-1
class Object
  require 'iconv'

  #
  # Return an utf-8 representation of this string.
  #
  def to_utf
    begin
      Iconv.new("utf-8", "iso-8859-1").iconv(to_s)
    rescue Iconv::IllegalSequence
      STDERR << "!! Failed converting from UTF-8 -> ISO-8859-1 (#{self}). Already the right charset?"
      self
    end
  end

  #
  # Convert this string to iso-8850-1
  #
  def to_latin
    begin
      Iconv.new("iso-8859-1", "utf-8").iconv(to_s)
    rescue Iconv::IllegalSequence
      STDERR << "!! Failed converting from ISO-8859-1 -> UTF-8 (#{self}). Already the right charset?"
      self
    end
  end
end

class String
  def between(separator, &block)
    split(separator).collect(&block).join(separator)
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
Empact-roxml-2.0 lib/roxml/string.rb
Empact-roxml-2.1 lib/roxml/string.rb