Re: ASCII & UTF string manipulation functions

Sandip V Honde wrote:


I was replacing some of the deprecated string manipulation function
I found that such string manipulation calls can be replaced by functions from ASCII or Unicode characters familiy

Following  functions are depreacted from <glib.h>


The following replacements are avialable for above functions


These functions only recognizes standard ASCII letters and ignores the
locale, treating all non-ASCII
characters as if they are not letters.

Should I go for the functions from Unicode Manipuations which operate on
Unicode characters and UTF-8 strings instead functions working only on
ASCII characters ?

The functions were renamed to indicate that they work on 8 bit characters (ie. they won't handle utf8 multibyte encodings). For localised utf8 strings, you should use the following two functions:

gint   g_utf8_collate     (const gchar *str1,
                          const gchar *str2);
gchar *g_utf8_collate_key (const gchar *str,
                          gssize       len);

The first is the unicode equivalent of strcoll() (which is what should be used for sorting localised strings). If you are comparing a large number of strings, you can call g_utf8_collate_key() on each string, then simply use strcmp() to sort the keys.


Email: james daa com au

[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]