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
ali@94
     1
#include <stdlib.h>
ali@94
     2
#include <string.h>
ali@94
     3
#include <glib.h>
ali@94
     4
#include <bl/bl.h>
ali@94
     5
ali@94
     6
/*
ali@94
     7
 * Creates a new string length bytes long filled with fill_char.
ali@94
     8
 * The returned string should be freed when no longer needed.
ali@94
     9
 */
ali@94
    10
gchar *utf8_strnfill(gsize length,gunichar fill_char)
ali@94
    11
{
ali@94
    12
    int n,i;
ali@94
    13
    gchar *s;
ali@94
    14
    char utf8[6];
ali@94
    15
    n=g_unichar_to_utf8(fill_char,utf8);
ali@94
    16
    s=g_new(gchar,length*n+1);
ali@94
    17
    if (n==1)
ali@94
    18
	memset(s,utf8[0],length);
ali@94
    19
    else
ali@94
    20
	for(i=0;i<length;i++)
ali@94
    21
	    memcpy(s+i*n,utf8,n);
ali@94
    22
    s[length*n]='\0';
ali@94
    23
    return s;
ali@94
    24
}