Sha256: 97975a528ea1c17f3ba4f8bf154686b5f5b248eb0117f73557a0b739f43e964d

Contents?: true

Size: 791 Bytes

Versions: 3

Compression:

Stored size: 791 Bytes

Contents

module ICU
  module Normalization

    def self.normalize(input, mode = :default)
      input_length  = input.unpack("U*").size
      needed_length = out_length = options = 0
      in_ptr        = UCharPointer.from_string(input)
      out_ptr       = UCharPointer.new(out_length)

      retried = false

      begin
        Lib.check_error do |error|
          needed_length = Lib.unorm_normalize(in_ptr, input_length, mode, options, out_ptr, out_length, error)
        end
      rescue BufferOverflowError
        raise BufferOverflowError, "needed: #{needed_length}" if retried

        out_ptr       = out_ptr.resized_to needed_length
        out_length    = needed_length + 1

        retried = true
        retry
      end

      out_ptr.string
    end

  end # Normalization
end # ICU

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
ffi-icu-0.0.5 lib/ffi-icu/normalization.rb
ffi-icu-0.0.4 lib/ffi-icu/normalization.rb
ffi-icu-0.0.3 lib/ffi-icu/normalization.rb