module ICU
Defined in:
icu.cricu/bidi.cr
icu/uchars.cr
icu/udate.cr
icu/version.cr
Constant Summary
-
VERSION =
"1.0.0"
Class Method Summary
- .check_error!(ustatus : LibICU::UErrorCode)
-
.with_auto_resizing_buffer(initial_size : Int, buffer_type : Bytes.class | UChars.class, &block : Bytes | UChars, Pointer(LibICU::UErrorCode) -> Int32) : String
Helper for ICU C functions that fill a resizable buffer (Bytes or UChars) and indicate required size via U_BUFFER_OVERFLOW_ERROR.
Class Method Detail
def self.with_auto_resizing_buffer(initial_size : Int, buffer_type : Bytes.class | UChars.class, &block : Bytes | UChars, Pointer(LibICU::UErrorCode) -> Int32) : String
#
Helper for ICU C functions that fill a resizable buffer (Bytes or UChars) and indicate required size via U_BUFFER_OVERFLOW_ERROR.
It handles the common pattern of calling a C function, checking for buffer overflow, resizing the buffer, and retrying.
Parameters:
initial_size: The initial capacity of the buffer.buffer_type: The type of buffer to use (BytesorUChars).&block: A block that performs the ICU C function call.- The block receives the buffer (
BytesorUChars) and a pointer to theUErrorCode(LibICU::UErrorCode*). The block can access the buffer's capacity viabuffer.size. - The block must return the actual length (
Int32) of the data written (or the required length if overflow occurred).
- The block receives the buffer (
Returns:
- The resulting
Stringconverted from the buffer contents.
Raises:
ICU::Errorif the C function returns an ICU error other thanU_BUFFER_OVERFLOW_ERROR.- Any exception raised within the block (other than
ICU::Errorrelated to overflow).
Example Usage:
result_string = ICU.with_auto_resizing_buffer(64, ICU::UChars) do |buffer, status_ptr|
LibICU.some_icu_function(..., buffer, buffer.size, status_ptr)
end