bl/utf8.c
author ali <ali@juiblex.co.uk>
Wed Oct 02 23:51:18 2013 +0100 (2013-10-02)
changeset 94 466f43a12118
permissions -rw-r--r--
Fix bug #11: Test for balanced "slanted" UTF-8 quotation marks 8220/8221
     1 #include <stdlib.h>
     2 #include <string.h>
     3 #include <glib.h>
     4 #include <bl/bl.h>
     5 
     6 /*
     7  * Creates a new string length bytes long filled with fill_char.
     8  * The returned string should be freed when no longer needed.
     9  */
    10 gchar *utf8_strnfill(gsize length,gunichar fill_char)
    11 {
    12     int n,i;
    13     gchar *s;
    14     char utf8[6];
    15     n=g_unichar_to_utf8(fill_char,utf8);
    16     s=g_new(gchar,length*n+1);
    17     if (n==1)
    18 	memset(s,utf8[0],length);
    19     else
    20 	for(i=0;i<length;i++)
    21 	    memcpy(s+i*n,utf8,n);
    22     s[length*n]='\0';
    23     return s;
    24 }