bug-libunistring
[Top][All Lists]
Advanced

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

[bug-libunistring] heap efficient u8_strconv_from_locale()


From: Pádraig Brady
Subject: [bug-libunistring] heap efficient u8_strconv_from_locale()
Date: Wed, 07 Jul 2010 15:20:56 +0100
User-agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.1.8) Gecko/20100227 Thunderbird/3.0.3

I'm finding the following useful seeing that malloc()
is a relatively expensive operation.
Would it be worth adding an interface like this?

cheers,
Pádraig.

#include <unistring/localcharset.h>
#include <unistr.h>
#include <uniconv.h>

/* Like u8_strconv_from_locale() except that
   the string is not copied if already UTF-8.
   One must free the result only when != src.  */

/* TODO: maybe pass NORM func to this */
static uint8_t *
u8_str_from_locale (const char *string)
{
  const char *encoding = locale_charset();

  if (STREQ (encoding, "UTF-8") || STREQ (encoding, "utf-8"))
    {
      size_t size = strlen (string) + 1;
      if (u8_check ((const uint8_t *) string, size))
        {
          errno = EILSEQ;
          return NULL;
        }
      return (uint8_t *) string;
    }
  else
    return u8_strconv_from_locale (string);
}



reply via email to

[Prev in Thread] Current Thread [Next in Thread]