Skip to content

Instantly share code, notes, and snippets.

@samcv
Last active July 20, 2017 23:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save samcv/5e39280fe1639c0258787f2a5a5547e2 to your computer and use it in GitHub Desktop.
Save samcv/5e39280fe1639c0258787f2a5a5547e2 to your computer and use it in GitHub Desktop.
MVMCodepoint last_a_first_b[2] = {
MVM_string_get_grapheme_at_nocheck(tc, a, a->body.num_graphs - 1),
MVM_string_get_grapheme_at_nocheck(tc, b, 0)
};
MVMROOT(tc, a, {
MVMROOT(tc, b, {
/* Needing both to be CCC = 0 can probably be relaxed some, but be careful optimizing */
if (0 <= last_a_first_b[0] && 0 <= last_a_first_b[1] /*&& MVM_unicode_relative_ccc(tc, last_a_first_b[0]) == 0*/ ) {
renormalized_section = MVM_unicode_codepoints_c_array_to_nfg_string(tc, last_a_first_b, 2);
consumed_a = 1; consumed_b = 1;
}
else {
MVMCodepointIter last_a_ci, first_b_ci;
int a_codes = MVM_string_grapheme_ci_init(tc, &last_a_ci, last_a_first_b[0]);
int b_codes = MVM_string_grapheme_ci_init(tc, &first_b_ci, last_a_first_b[1]);
MVMCodepoint thing[a_codes + b_codes];
int i;
for (i = 0; MVM_string_grapheme_ci_has_more(tc, &last_a_ci); i++) {
thing[i] = MVM_string_grapheme_ci_get_codepoint(tc, &last_a_ci);
//fprintf(stderr, "Got from a %ith char. got %i\n", i, thing[i]);
}
for (; MVM_string_grapheme_ci_has_more(tc, &first_b_ci); i++) {
thing[i] = MVM_string_grapheme_ci_get_codepoint(tc, &first_b_ci);
//fprintf(stderr, "Got from b %ith char. got %i\n", i, thing[i]);
}
renormalized_section = MVM_unicode_codepoints_c_array_to_nfg_string(tc, thing, a_codes + b_codes);
consumed_a = 1; consumed_b = 1;
}
});
});
if (renormalized_section) {
if (agraphs == consumed_a && bgraphs == consumed_b)
return renormalized_section;
renormalized_section_graphs = MVM_string_graphs(tc, renormalized_section);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment