Skip to content

Instantly share code, notes, and snippets.

@FROGGS
Created May 8, 2015 09:03
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 FROGGS/61a3e002267bf54b1e42 to your computer and use it in GitHub Desktop.
Save FROGGS/61a3e002267bf54b1e42 to your computer and use it in GitHub Desktop.
MVMint64 MVM_string_equal_at_ignore_mark(MVMThreadContext *tc, MVMString *a, MVMString *b, MVMint64 offset) {
MVMNormalizer norm1;
MVMNormalizer norm2;
MVMGrapheme32 ga_nfd;
MVMGrapheme32 gb_nfd;
MVMint32 ready;
MVMGrapheme32 ga = MVM_string_get_grapheme_at_nocheck(tc, a, offset);
MVMGrapheme32 gb = MVM_string_get_grapheme_at_nocheck(tc, b, 0);
MVM_unicode_normalizer_init(tc, &norm1, MVM_NORMALIZE_NFD);
ready = MVM_unicode_normalizer_process_codepoint_to_grapheme(tc, &norm1, ga, &ga_nfd);
MVM_unicode_normalizer_eof(tc, &norm1);
if (!ready)
ga_nfd = MVM_unicode_normalizer_get_grapheme(tc, &norm1);
MVM_unicode_normalizer_init(tc, &norm2, MVM_NORMALIZE_NFD);
ready = MVM_unicode_normalizer_process_codepoint_to_grapheme(tc, &norm2, gb, &gb_nfd);
MVM_unicode_normalizer_eof(tc, &norm2);
if (!ready)
gb_nfd = MVM_unicode_normalizer_get_grapheme(tc, &norm2);
//~ fprintf(stderr, "MVM_string_equal_at_ignore_mark offset=%d %d == %d\n", offset, ga_nfd, gb_nfd);
return ga_nfd == gb_nfd ? 1 : 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment