[gcompris-devel] XML and accents

pgeorges pascal.georges1 at free.fr
Sat Nov 24 12:36:01 UTC 2001


Bruno Coudoin a écrit :
> 
> Pascal, you need to look at my code in gameutil.c and do the same in
> your xml parsing. there is some clue to do that by using UTF8Toisolat1.
> 
> It has worked for me ;)
> 
> Bruno.

Great, it also works for me. But what happens if the user language is
not an isolatin1 ? Does the code in gameutil.c handles this properly
(conversion is done regardless of lang) ?

As this is a useful conversion, maybe it should be a helper one
avalaible in gameutil.c. Here is a blueprint (I don't include it
directly, as I don't master at all the subject):

/* ==================================== */
static gchar * convertUTF8Toisolat1(gchar * text) {
#define MAX_LENGTH 128
  const char *inptr;
  size_t inleft;
  char *outptr;
  size_t outleft;
  gint retval;
 // this should never happen, it does often with my XML parsing !!
  if (text == NULL)
  	return NULL;

  inptr   = (const char *) text;
  outptr  = (char *) g_malloc(MAX_LENGTH);
  inleft  = xmlUTF8Strsize(text, MAX_LENGTH);
  outleft = MAX_LENGTH;
  // Conversion to ISO-8859-1
  retval = UTF8Toisolat1(outptr, &outleft, text, &inleft);
  if(retval==0)  {
 	    g_free(text);
	    text = outptr;
	    text[outleft]='\0';
	  } else
	  	g_free(outptr);

  return text;
}




More information about the Gcompris-devel mailing list