Re: [Nautilus-list] Some RH patches.
- From: Owen Taylor <otaylor redhat com>
- To: Alex Larsson <alexl redhat com>
- Cc: <nautilus-list lists eazel com>
- Subject: Re: [Nautilus-list] Some RH patches.
- Date: 03 Sep 2001 18:03:16 -0400
Alex Larsson <alexl redhat com> writes:
> + const nsString str (uniStr);
> + sSize = str.Length ();
> +
> + /* allocate a wide string big enough to hold the unicode string,
> + * this is necessary since wchar_t is 32-bits with glibc */
> + wide = g_new0 (wchar_t, sSize + 1);
> + for (i = 0; i < sSize + 1; i++) {
> + wide[i] = uniStr[i];
> + }
> +
> + /* use glibc function to determine the size of this string once
> + * encoded to a locale specfic multibyte string */
> + count = wcstombs (NULL, wide, 0);
> +
> + /* check for success */
> + if (count == -1) {
> + /* let Mozilla do a (lossy) conversion then */
> + nsCString str;
> + str.AssignWithConversion (uniStr);
> + g_free (wide);
> + return g_strdup (str.get ()); /* FIXME strdup needed? */
> + /* Phil: Oh Yes! indeed. */
> + }
This code is not portable since it assumes the wchar_t is ISO-10646.
You can surround it with:
#ifdef __STDC_ISO_10646__
But I'm not sure what you'd do as a fallback ... handle ascii only?
(Also there is a question here whether the Mozilla string is UCS-2,
or UTF-16 with possible surrogate pairs.)
Regards,
Owen
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]