Skip to content

Instantly share code, notes, and snippets.

@dajobe
Created March 11, 2012 18:40

Revisions

  1. dajobe created this gist Mar 11, 2012.
    36 changes: 36 additions & 0 deletions icu_is_nfc.c
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,36 @@
    /*
    * 4.8 if the pkgconfig files are present:
    * gcc -g -o icu_is_nfc icu_is_nfc.c `pkg-config icu-uc --cflags --libs`
    *
    * Portable:
    * gcc -g -o icu_is_nfc icu_is_nfc.c `icu-config --cppflags-searchpath --ldflags-searchpath` -licuuc
    */
    #include <stdio.h>

    #include <unicode/unorm.h>

    int
    raptor_icu_is_nfc(const unsigned char* string, size_t len)
    {
    UNormalizationCheckResult res;
    UErrorCode error_code = U_ZERO_ERROR;

    res = unorm_quickCheck((const UChar *)string, (int32_t)len,
    UNORM_NFC, &error_code);
    return U_SUCCESS(error_code) && (res == UNORM_YES);
    }

    int
    main (int argc, char *argv[])
    {
    #define BUFLEN 3
    char buffer[BUFLEN + 1]="abc\0";
    int res;

    res = raptor_icu_is_nfc(buffer, BUFLEN);

    fprintf(stderr, "Result is %d\n", res);

    return(0);
    }