author | ali <ali@juiblex.co.uk> |
Sat Oct 26 18:47:33 2013 +0100 (2013-10-26) | |
changeset 101 | f44c530f80da |
permissions | -rw-r--r-- |
1 #include <stdlib.h>
2 #include <string.h>
3 #include <glib.h>
4 #include <bl/bl.h>
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 }