utf8proc 0.0.1

D port of utf8proc.


To use this package, run the following command in your project's root directory:

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.sizeof / ubyte.sizeof) * mstring.length);
    memcpy(mstr, mstring.ptr, (mstring.sizeof / ubyte.sizeof) * mstring.length);

    // some buffer for output. 
    ubyte** dst = cast(ubyte**)malloc((ubyte*).sizeof * mstring.sizeof);

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

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

    utf8proc_uint8_t* 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;
}
Authors:
  • Steven G. Johnson
  • Jiahao Chen
  • Tony Kelman
  • Jonas Fonseca
  • Ferhat Kurtulmuş
Dependencies:
stringnogc
Versions:
0.0.1 2020-Apr-11
Show all 1 versions
Download Stats:
  • 0 downloads today

  • 0 downloads this week

  • 0 downloads this month

  • 0 downloads total

Score:
0.4
Short URL:
utf8proc.dub.pm