Re: gunicode.h
- From: Owen Taylor <otaylor redhat com>
- To: Havoc Pennington <hp redhat com>
- Cc: gtk-devel-list redhat com
- Subject: Re: gunicode.h
- Date: 12 Jun 2000 15:31:22 -0400
Havoc Pennington <hp@redhat.com> writes:
> Owen Taylor <otaylor@redhat.com> writes:
> > gunichar g_utf8_get_char (gchar *iter);
> > gchar * g_utf8_iter_from_index (const gchar *str,
> > gint index);
> > gint g_utf8_iter_to_index (const gchar *str,
> > const gchar *pos);
>
> I think the use of "iter" is cryptic here, I like "pointer" more
> i.e. g_utf8_pointer_from_index() g_utf8_pointer_to_index().
Probably. I originally called all these functions:
g_iter_get_char(), etc.
But decided that was not very clear.
> > gchar * g_utf8_next_char (gchar *iter);
> > gchar * g_utf8_prev_char (gchar *iter);
>
> These args should be const if "pos" above is const, right?
Yes.
> > gchar * g_utf8_find_next_char (gchar *iter,
> > const gchar *bound);
> > gchar * g_utf8_find_prev_char (const gchar *str,
> > gchar *iter);
> >
>
> Why is bound const but not iter?
No particular reason.
> > /* Copies n characters from src to dest */
> > gchar *g_utf8_strncpy (gchar *dest,
> > const gchar *src,
> > size_t n);
> >
>
> Use of size_t here seems weird since size_t is almost always used to
> count bytes. I would think just int, there's no sense in which this n
> is a memory offset or size.
The reason why this is size_t is basically just copying strncpy. Note
that that 'n' counts things which are at smallest just bytes.
Note that size_t is extensively used for things other than bytes in
in the standard C lib.
void qsort (void *base, size_t nmemb, size_t size,
int (*compar)(const void *, const void *))
Note the size_t nmemb.
An int could be smaller than the possible size of 'n'. If you have
a 5 gig string on a 64-bit machine, size_t, works but not char.
Of course we extensively use int in places like this throughout glib,
so this argument doesn't hold a lot of water.
> > gunichar2 *g_utf8_to_ucs2 (const char *str,
> > gint len);
> > gunichar *g_utf8_to_ucs4 (const char *str,
> > int len);
> >
>
> Include the inverse of these, maybe? (g_ucs4_to_utf8() etc.)
Yes. I think so. (Though that gives 6 functions.) I do want to a malloc'ing iconv
wrapper, so you can do:
char *result = g_convert ("utf-8", "ucs-2", (char *)input);
if (!result)
g_warning ("Cannot convert string");
Or something like that. But for efficiency and convenient
Thanks for the feedback,
Owen
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]