dealing with utf8 filenames
- From: "Alan M. Evans" <ame1 extratech com>
- To: gtk-app-devel-list gnome org
- Subject: dealing with utf8 filenames
- Date: Tue, 21 Feb 2006 15:39:43 -0800
Suppose I have a filename returned from g_dir_read_name(). It's UTF-8,
at least on Win32. I would like to determine if it has a particular
extension (case insensitive) and display it without the extension.
I can't believe that this manipulation is that uncommon, but the only
solutions I've been able to devise are very convoluted and not
technically correct. Here's what I have so far:
const gchar *name;
gchar *dotxci = g_utf8_casefold(".xci",-1);
while ((name=g_dir_read_name(dir))) {
gchar *utfname = g_utf8_casefold(name,-1);
gchar *extension = g_utf8_strrchr(utfname,-1,'.');
if (extension && !strcmp(extension,dotxci)) {
GString *dname = g_string_new_len(name,extension-utfname);
/* dname->str here contains displayable filename */
g_string_free(dname,TRUE);
}
g_free(utfname);
}
g_free(dotxci);
This seems like an awful lot to go through just to get a filename
without an extension. In particular, I'm unhappy with the amount of
frivolous dynamic allocation. Also, I don't think the string returned
from g_utf8_casefold() is guaranteed to be the same length as the
original, so my calculation for string length is incorrect.
Is there some simple or obvious solution I'm missing?
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]