utf8proc

D port of utf8proc.


Keywords
library, encoding, i18n, nogc
License
Artistic-1.0-cl8
Install
dub fetch utf8proc --version 0.0.2

Documentation

A D port of utf8proc

  • Ported from utf8proc version 2.5.0
  • Ported with some help of dstep
  • Works with -betterC

An example

import core.stdc.string;
import core.stdc.stdlib;
import core.stdc.stdio;

import utf8proc;

@nogc nothrow:

extern (C) int main()
{
    string mstring = "ğüşöç ııİıııŞıÜııÇıı"; // 20 entries
    
    // duplicate mstring and cast it to ubyte*
    ubyte* mstr = cast(ubyte*)malloc(mstring.length + 1);
    memcpy(mstr, mstring.ptr, mstring.length + 1);

    // some buffer for output. 
    ubyte* dst;

    auto sz = utf8proc_map(mstr, mstring.length, &dst, UTF8PROC_NULLTERM);

    printf("your string: %s \n", cast(char*)dst);
    
    utf8proc_ssize_t size = sz;
    utf8proc_int32_t data;
    utf8proc_ssize_t n;

    ubyte* char_ptr = mstr;

    printf("Those are your utf8 characters one by one: \n".ptr);

    size_t nchar;

    while ((n = utf8proc_iterate(char_ptr, size, &data)) > 0) {
        printf("%.*s \n", cast(int)n, char_ptr);
        char_ptr += n;
        size -= n;
        nchar++;
    }

    // assert(nchar == 20);
    printf("You have %d entries in your string!", nchar);
    
    free(mstr);
    free(dst);

    return 0;
}