bl/utf8.c
author ali <ali@juiblex.co.uk>
Tue Sep 24 07:18:50 2013 +0100 (2013-09-24)
changeset 96 8c2d6a0cf717
permissions -rw-r--r--
Fix bug #10: loupe-test should have an option to display bookloupe output
     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 }