From b5fea9fbfad6c839a7a6110f467c2a1d2be921df Mon Sep 17 00:00:00 2001 From: Daniel Arbelo Arrocha Date: Fri, 25 Jun 2010 07:06:13 +0000 Subject: [PATCH] Add some null table handling to grapheme_table_capacity and use that to simplify the iterator code a bit. git-svn-id: https://svn.parrot.org/parrot/branches/gsoc_nfg@47829 d31e2699-5ff4-0310-a27c-f18f2fbe73fe --- src/string/encoding/nfg.c | 11 +++-------- src/string/grapheme.c | 4 +++- t/op/string_nfg.t | 4 ++-- 3 files changed, 8 insertions(+), 11 deletions(-) diff --git a/src/string/encoding/nfg.c b/src/string/encoding/nfg.c index 93abe9fe0f..6f3927806a 100644 --- a/src/string/encoding/nfg.c +++ b/src/string/encoding/nfg.c @@ -548,15 +548,15 @@ nfg_encode_and_advance(PARROT_INTERP, ARGMOD(String_iter *i), UINTVAL c) } else { UErrorCode err = U_ZERO_ERROR; + UChar src[3]; int dst_len = 1; - int src_len = 1; - UChar src[2]; UChar dst[2]; src[0] = s[pos - 1]; src[1] = s[pos]; + src[2] = 0; /* Delegate composition to ICU. */ - dst_len = unorm_normalize(src, src_len, UNORM_DEFAULT, 0, + dst_len = unorm_normalize(src, -1 , UNORM_DEFAULT, 0, dst, dst_len, &err); if (U_SUCCESS(err)) { @@ -566,11 +566,6 @@ nfg_encode_and_advance(PARROT_INTERP, ARGMOD(String_iter *i), UINTVAL c) } /* Composition failed, we need a dynamic codepoint. */ - if (table == NULL) { - table = create_grapheme_table(interp, 1); - i->str->extra = table; - } - g.len = 2; g.hash = 0xffff; g.codepoints = mem_gc_allocate_n_typed(interp, g.len, UChar32); diff --git a/src/string/grapheme.c b/src/string/grapheme.c index fdffc74d3d..6e6f8731e3 100644 --- a/src/string/grapheme.c +++ b/src/string/grapheme.c @@ -18,7 +18,9 @@ INTVAL grapheme_table_capacity(PARROT_INTERP, grapheme_table *table) { ASSERT_ARGS(grapheme_table_capacity) - return table->size - table->used; + if (table) + return table->size - table->used; + return 0; } grapheme_table * diff --git a/t/op/string_nfg.t b/t/op/string_nfg.t index 839595cc3c..030614801b 100644 --- a/t/op/string_nfg.t +++ b/t/op/string_nfg.t @@ -49,11 +49,11 @@ string operations. is($I0, $I1, "Bufused is the same.") # Do the same thing again, without dynamic codepoints. - $S2 = utf16:unicode:"O\u0308" + $S2 = utf16:unicode:"n\u0303" $I0 = find_encoding 'nfg' $S2 = trans_encoding $S2, $I0 - $S3 = nfg:unicode:"O\u0308" + $S3 = nfg:unicode:"n\u0303" $I0 = stringinfo $S2, .STRINGINFO_STRLEN $I1 = stringinfo $S3, .STRINGINFO_STRLEN