Fix failing transliteration spec

This commit is contained in:
Jari Bakken 2010-05-29 01:44:12 +02:00
parent 13ae698e50
commit b0bc5b5f6c
2 changed files with 9 additions and 11 deletions

View File

@ -39,25 +39,23 @@ module ICU
text_length = FFI::MemoryPointer.new :int32
[limit, text_length].each do |ptr|
ptr.put_int32(0, unicode_size)
end
retried = false
begin
# resets to original size on retry
[limit, text_length].each do |ptr|
ptr.put_int32(0, unicode_size)
end
Lib.check_error do |error|
Lib.utrans_transUChars(@tr, buf, text_length, capacity, 0, limit, error)
end
rescue BufferOverflowError
new_size = text_length.get_int32(0)
raise BufferOverflowError, "needed: #{new_size}" if retried
raise BufferOverflowError, "needed #{new_size}" if retried
buf = buf.resized_to(new_size)
capacity = new_size
# reset to original size
text_length.put_int32 0, unicode_size
capacity = new_size + 1
retried = true
retry

4
test.c
View File

@ -29,11 +29,11 @@ int main (int argc, char const *argv[])
}
UChar from[256];
UChar buf[256];
UChar buf[6];
int32_t text_length, limit;
u_uastrcpy(from, "Hello World");
u_uastrcpy(from, "abcde");
u_strcpy(buf, from);
limit = text_length = u_strlen(buf);