Module: ICU::Calendar::Library
- Extended by:
- FFI::Library
- Defined in:
- lib/icu/calendar/library.rb,
lib/icu/calendar/library/constants.rb,
lib/icu/calendar/library/error_code.rb,
lib/icu/calendar/library/version_info.rb
Defined Under Namespace
Classes: ErrorCode, VersionInfo
Constant Summary
collapse
- U_BUFFER_OVERFLOW_ERROR =
15
- U_MAX_VERSION_LENGTH =
4
- U_MAX_VERSION_STRING_LENGTH =
20
- U_ZERO_ERROR =
0
Class Method Summary
collapse
Class Method Details
.assert_success ⇒ Object
36
37
38
39
40
41
42
|
# File 'lib/icu/calendar/library.rb', line 36
def assert_success
ErrorCode.new do |status|
result = yield status
raise RuntimeError, status.to_s unless status.success?
return result
end
end
|
.read_into_wchar_buffer(length) ⇒ Object
44
45
46
47
48
49
50
51
52
53
54
55
56
|
# File 'lib/icu/calendar/library.rb', line 44
def read_into_wchar_buffer(length)
ErrorCode.new do |status|
for _ in 1..2
FFI::Buffer.new(:uint16, length, false) do |buffer|
length = yield buffer, status
return buffer.read_array_of_uint16(length).pack('U*') if status.success?
raise RuntimeError, status.to_s unless status.buffer_overflow?
status.clear
end
end
raise RuntimeError, "#{status}: Needed #{length}"
end
end
|
.read_wchar_enumeration(open) ⇒ Object
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
|
# File 'lib/icu/calendar/library.rb', line 58
def read_wchar_enumeration(open)
return enum_for(:read_wchar_enumeration, open) unless block_given?
Library::ErrorCode.new do |status|
enumeration = open.call(status)
raise RuntimeError, status.to_s unless status.success?
begin
FFI::MemoryPointer.new(:int32) do |length|
loop do
pointer = Library.uenum_unext(enumeration, length, status)
raise RuntimeError, status.to_s unless status.success?
break if pointer.null?
yield pointer.read_array_of_uint16(length.read_int32).pack('U*')
end
end
ensure
Library.uenum_close(enumeration)
end
end
end
|
.version ⇒ Object
80
81
82
|
# File 'lib/icu/calendar/library.rb', line 80
def version
@version ||= VersionInfo.new.tap { |version| u_getVersion(version) }
end
|
.wchar_buffer_from_string(string, &block) ⇒ Object
84
85
86
87
88
89
90
|
# File 'lib/icu/calendar/library.rb', line 84
def wchar_buffer_from_string(string, &block)
codepoints = string.encode('UTF-8').unpack('U*') << 0
FFI::Buffer.new(:uint16, codepoints.length, false) do |buffer|
buffer.write_array_of_uint16(codepoints)
return yield buffer
end
end
|