Re: g_str_is_ascii()
- From: "David Necas (Yeti)" <yeti physics muni cz>
- To: Claudio Saavedra <csaavedra alumnos utalca cl>
- Cc: gtk-app-devel-list gnome org
- Subject: Re: g_str_is_ascii()
- Date: Fri, 20 May 2005 08:55:18 +0200
On Thu, May 19, 2005 at 06:18:44PM -0400, Claudio Saavedra wrote:
I need to write a function to reject strings that are utf-8, i.e. accept
only convencional ascii strings.
I was wondering if there is any other way more nice than making a
gboolean
str_is_ascii (const gchar *str)
{
return (str (mystring) == g_utf8_strlen (str, -1));
I suppose this should read strlen(str)
}
Beside being incorrect -- result of g_utf8_strlen() on
a string that is not valid utf8 is not defined -- this is
quite a waste of resources.
while (*str) {
if ((guchar)*str >= 128)
return FALSE;
}
return TRUE;
does the latter: accept only ASCII strings. It does not do
the former (reject valid UTF-8), except when you know the
string is valid UTF-8 and only need to check whether it is
valid ASCII too, in this case the two checks conincide.
Yeti
--
A: Because it messes up the order in which people normally read text.
Q: Why is top-posting such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]