lib/ffi-icu/lib/util.rb in ffi-icu-0.4.1 vs lib/ffi-icu/lib/util.rb in ffi-icu-0.4.2
- old
+ new
@@ -26,11 +26,23 @@
end
result.read_string(length)
end
- def self.read_uchar_buffer(length)
+ def self.read_uchar_buffer(length, &blk)
+ buf, len = read_uchar_buffer_as_ptr_impl(length, &blk)
+ buf.string(len)
+ end
+
+ def self.read_uchar_buffer_as_ptr(length, &blk)
+ buf, _ = read_uchar_buffer_as_ptr_impl(length, &blk)
+ buf
+ end
+
+ private
+
+ def self.read_uchar_buffer_as_ptr_impl(length)
attempts = 0
begin
result = UCharPointer.new(length)
Lib.check_error { |status| length = yield result, status }
@@ -38,10 +50,10 @@
attempts += 1
retry if attempts < 2
raise BufferOverflowError, "needed: #{length}"
end
- result.string(length)
+ [result, length]
end
end
end
end