Skip to content

Commit

Permalink
Add some null table handling to grapheme_table_capacity and use that …
Browse files Browse the repository at this point in the history
…to simplify the iterator code a bit.

git-svn-id: https://svn.parrot.org/parrot/branches/gsoc_nfg@47829 d31e2699-5ff4-0310-a27c-f18f2fbe73fe
  • Loading branch information
darbelo committed Jun 25, 2010
1 parent b2f549d commit b5fea9f
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 11 deletions.
11 changes: 3 additions & 8 deletions src/string/encoding/nfg.c
Expand Up @@ -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)) {
Expand All @@ -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);
Expand Down
4 changes: 3 additions & 1 deletion src/string/grapheme.c
Expand Up @@ -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 *
Expand Down
4 changes: 2 additions & 2 deletions t/op/string_nfg.t
Expand Up @@ -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
Expand Down

0 comments on commit b5fea9f

Please sign in to comment.