| author | ali <ali@juiblex.co.uk> |
| Tue Sep 24 22:31:04 2013 +0100 (2013-09-24) | |
| changeset 113 | 27e126ac2e8f |
| permissions | -rw-r--r-- |
| ali@111 | 1 |
#include <stdlib.h> |
| ali@111 | 2 |
#include <string.h> |
| ali@111 | 3 |
#include <glib.h> |
| ali@111 | 4 |
#include <bl/bl.h> |
| ali@111 | 5 |
|
| ali@111 | 6 |
/* |
| ali@111 | 7 |
* Creates a new string length bytes long filled with fill_char. |
| ali@111 | 8 |
* The returned string should be freed when no longer needed. |
| ali@111 | 9 |
*/ |
| ali@111 | 10 |
gchar *utf8_strnfill(gsize length,gunichar fill_char) |
| ali@111 | 11 |
{
|
| ali@111 | 12 |
int n,i; |
| ali@111 | 13 |
gchar *s; |
| ali@111 | 14 |
char utf8[6]; |
| ali@111 | 15 |
n=g_unichar_to_utf8(fill_char,utf8); |
| ali@111 | 16 |
s=g_new(gchar,length*n+1); |
| ali@111 | 17 |
if (n==1) |
| ali@111 | 18 |
memset(s,utf8[0],length); |
| ali@111 | 19 |
else |
| ali@111 | 20 |
for(i=0;i<length;i++) |
| ali@111 | 21 |
memcpy(s+i*n,utf8,n); |
| ali@111 | 22 |
s[length*n]='\0'; |
| ali@111 | 23 |
return s; |
| ali@111 | 24 |
} |