<commit_before># Simple $5 Iconv implementation using FFI


class Iconv
  extend FFI::Library

  ffi_lib FFI::CURRENT_PROCESS, "libiconv"

  attach_function :create,  "iconv_open", [:string, :string], :pointer
  attach_function :close,   "iconv_close", [:pointer], :int
  attach_function :convert, "iconv",
                            [:pointer, :pointer, :pointer, :pointer, :pointer], :long

  module Failure
    attr_reader :success
    attr_reader :failed

    def initialize(mesg, success, failed)
      super(mesg)
      @success = success
      @failed = failed
    end

    def inspect()
      "<##{self.class}: #{success.inspect}, #{failed.inspect}>"
    end
  end

  class BrokenLibrary < RuntimeError
    include Failure
  end

  class IllegalSequence < ArgumentError
    include Failure
  end

  class InvalidCharacter < ArgumentError<commit_msg>Fix how/where to get iconv symbols<commit_after># Simple $5 Iconv implementation using FFI


class Iconv
  extend FFI::Library

  # Use libiconv if it exists, otherwise get the symbols from the current
  # process.
  ffi_lib ["libiconv", FFI::CURRENT_PROCESS]

  attach_function :create,  "iconv_open", [:string, :string], :pointer
  attach_function :close,   "iconv_close", [:pointer], :int
  attach_function :convert, "iconv",
                            [:pointer, :pointer, :pointer, :pointer, :pointer], :long

  module Failure
    attr_reader :success
    attr_reader :failed

    def initialize(mesg, success, failed)
      super(mesg)
      @success = success
      @failed = failed
    end

    def inspect()
      "<##{self.class}: #{success.inspect}, #{failed.inspect}>"
    end
  end

  class BrokenLibrary < RuntimeError
    include Failure
  end

  class IllegalSequence < ArgumentError
    include Failure
  end

  class InvalidCharacter < ArgumentError
{'fraction_non_alphanumeric': 0.10021905805038335, 'fraction_numerical': 0.001095290251916758, 'mean_word_length': 3.278688524590164, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '288239', 'n_tokens_mistral': 558, 'n_tokens_neox': 533, 'n_words': 161}