utf8proc

A clean C library for processing UTF-8 Unicode data
git clone https://git.sinitax.com/juliastrings/utf8proc
Log | Files | Refs | README | LICENSE | sfeed.txt

printproperty.c (2148B)


      1/* simple test program to print out the utf8proc properties for a codepoint */
      2
      3#include "tests.h"
      4
      5int main(int argc, char **argv)
      6{
      7    int i;
      8
      9    for (i = 1; i < argc; ++i) {
     10        utf8proc_uint8_t cstr[16], *map;
     11        utf8proc_uint32_t x;
     12        utf8proc_int32_t c;
     13        if (!strcmp(argv[i], "-V")) {
     14            printf("utf8proc version %s\n", utf8proc_version());
     15            continue;
     16        }
     17        check(sscanf(argv[i],"%x", &x) == 1, "invalid hex input %s", argv[i]);
     18        c = (utf8proc_int32_t)x;
     19        const utf8proc_property_t *p = utf8proc_get_property(c);
     20
     21        if (utf8proc_codepoint_valid(c))
     22            cstr[utf8proc_encode_char(c, cstr)] = 0;
     23        else
     24            strcat((char*)cstr, "N/A");
     25        utf8proc_map(cstr, 0, &map, UTF8PROC_NULLTERM | UTF8PROC_CASEFOLD);
     26
     27        printf("U+%s: %s\n"
     28            "  category = %s\n"
     29            "  combining_class = %d\n"
     30            "  bidi_class = %d\n"
     31            "  decomp_type = %d\n"
     32            "  uppercase_mapping = %04x (seqindex %04x)%s\n"
     33            "  lowercase_mapping = %04x (seqindex %04x)%s\n"
     34            "  titlecase_mapping = %04x (seqindex %04x)\n"
     35            "  casefold = %s\n"
     36            "  comb_index = %d\n"
     37            "  bidi_mirrored = %d\n"
     38            "  comp_exclusion = %d\n"
     39            "  ignorable = %d\n"
     40            "  control_boundary = %d\n"
     41            "  boundclass = %d\n"
     42            "  indic_conjunct_break = %d\n"
     43            "  charwidth = %d\n",
     44        argv[i], (char*) cstr,
     45        utf8proc_category_string(c),
     46        p->combining_class,
     47        p->bidi_class,
     48        p->decomp_type,
     49        utf8proc_toupper(c), p->uppercase_seqindex, utf8proc_isupper(c) ? " (isupper)" : "",
     50        utf8proc_tolower(c), p->lowercase_seqindex, utf8proc_islower(c) ? " (islower)" : "",
     51        utf8proc_totitle(c), p->titlecase_seqindex,
     52        (char *) map,
     53        p->comb_index,
     54        p->bidi_mirrored,
     55        p->comp_exclusion,
     56        p->ignorable,
     57        p->control_boundary,
     58        p->boundclass,
     59        p->indic_conjunct_break,
     60        utf8proc_charwidth(c));
     61        free(map);
     62    }
     63    return 0;
     64}