Re: ASCII & UTF string manipulation functions



Sandip V Honde wrote:

Hi,

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

Following  functions are depreacted from <glib.h>

	g_strcasecmp()
	g_strncasecmp()

The following replacements are avialable for above functions

	g_ascii_strcasecmp()
	g_ascii_strncasecmp()

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.

James.

--
Email: james daa com au
WWW:   http://www.daa.com.au/~james/






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