Sha256: 26415e7eeb6b33aa028ab9c0286d8269811246d146ffd4a6471f88b3bcf448ff

Contents?: true

Size: 1.1 KB

Versions: 14

Compression:

Stored size: 1.1 KB

Contents

module ICU
  module Lib
    module Util
      def self.read_null_terminated_array_of_strings(pointer)
        offset = 0
        result = []

        until (ptr = pointer.get_pointer(offset)).null?
          result << ptr.read_string
          offset += FFI::Pointer.size
        end

        result
      end

      def self.read_string_buffer(length)
        attempts = 0

        begin
          result = FFI::MemoryPointer.new(:char, length)
          Lib.check_error { |status| length = yield result, status }
        rescue BufferOverflowError
          attempts += 1
          retry if attempts < 2
          raise BufferOverflowError, "needed: #{length}"
        end

        result.read_string(length)
      end

      def self.read_uchar_buffer(length)
        attempts = 0

        begin
          result = UCharPointer.new(length)
          Lib.check_error { |status| length = yield result, status }
        rescue BufferOverflowError
          attempts += 1
          retry if attempts < 2
          raise BufferOverflowError, "needed: #{length}"
        end

        result.string(length)
      end
    end
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
ffi-icu-0.4.1 lib/ffi-icu/lib/util.rb
ffi-icu-0.4.0 lib/ffi-icu/lib/util.rb
ffi-icu-0.3.0 lib/ffi-icu/lib/util.rb
ffi-icu-0.2.0 lib/ffi-icu/lib/util.rb
ffi-icu-0.1.10 lib/ffi-icu/lib/util.rb
ffi-icu-0.1.9 lib/ffi-icu/lib/util.rb
ffi-icu-0.1.8 lib/ffi-icu/lib/util.rb
ffi-icu-0.1.7 lib/ffi-icu/lib/util.rb
ffi-icu-0.1.6 lib/ffi-icu/lib/util.rb
ffi-icu-0.1.5 lib/ffi-icu/lib/util.rb
ffi-icu-0.1.4 lib/ffi-icu/lib/util.rb
ffi-icu-0.1.3 lib/ffi-icu/lib/util.rb
ffi-icu-0.1.2 lib/ffi-icu/lib/util.rb
ffi-icu-0.1.1 lib/ffi-icu/lib/util.rb