forked from enlightenment/efl
copy ecore_txt_convert to eina_str_convert
SVN revision: 45790
This commit is contained in:
parent
503e847677
commit
eb29a86306
|
@ -379,6 +379,36 @@ if test "x$res" = "xno"; then
|
|||
fi
|
||||
AC_SUBST(fnmatch_libs)
|
||||
|
||||
# iconv library
|
||||
iconv_cflags=""
|
||||
iconv_libs=""
|
||||
have_iconv="no"
|
||||
AC_ARG_WITH([iconv-link],
|
||||
AC_HELP_STRING([--with-iconv-link=ICONV_LINK], [explicitly specify an iconv link option]),
|
||||
[
|
||||
iconv_libs=$withval
|
||||
have_iconv="yes"
|
||||
])
|
||||
|
||||
AC_MSG_CHECKING(for explicit iconv link options)
|
||||
if test "x${iconv_libs}" = "x" ; then
|
||||
AC_MSG_RESULT([no explicit iconv link option])
|
||||
else
|
||||
AC_MSG_RESULT([$iconv_libs])
|
||||
fi
|
||||
|
||||
AM_ICONV
|
||||
|
||||
if test "x${have_iconv}" = "xno" && test "x${am_cv_func_iconv}" = "xyes" ; then
|
||||
iconv_cflags=${LIBICONV}
|
||||
iconv_libs=${LTLIBICONV}
|
||||
have_iconv="yes"
|
||||
fi
|
||||
|
||||
AC_SUBST(iconv_cflags)
|
||||
AC_SUBST(iconv_libs)
|
||||
|
||||
|
||||
### Modules
|
||||
|
||||
if test "x${have_default_mempool}" = "xyes" ; then
|
||||
|
@ -477,6 +507,7 @@ echo " Report string usage..: ${have_stringshare_usage}"
|
|||
echo " Default mempool......: ${have_default_mempool}"
|
||||
echo " Thread Support.......: ${have_pthread} (spinlock: ${have_pthread_spinlock})"
|
||||
echo " Amalgamation.........: ${do_amalgamation}"
|
||||
echo " Iconv support........: ${have_iconv}"
|
||||
echo
|
||||
echo " Documentation........: ${build_doc}"
|
||||
echo " Tests................: ${enable_tests}"
|
||||
|
|
|
@ -25,6 +25,8 @@ EAPI char **eina_str_split(const char *string, const char *delimiter,
|
|||
|
||||
EAPI size_t eina_str_join_len(char *dst, size_t size, char sep, const char *a, size_t a_len, const char *b, size_t b_len);
|
||||
|
||||
EAPI char *eina_str_convert(const char *enc_from, const char *enc_to, const char *text);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Join two strings of known length.
|
||||
|
|
|
@ -7,7 +7,8 @@ AM_CPPFLAGS = \
|
|||
-DPACKAGE_LIB_DIR=\"$(libdir)\" \
|
||||
-DPACKAGE_DATA_DIR=\"$(datadir)/$(PACKAGE)\" \
|
||||
@EINA_CPPFLAGS@ \
|
||||
@EFL_EINA_BUILD@
|
||||
@EFL_EINA_BUILD@ \
|
||||
@iconv_cflags@
|
||||
|
||||
base_sources = \
|
||||
eina_error.c \
|
||||
|
@ -128,8 +129,8 @@ libeina_la_SOURCES = $(base_sources)
|
|||
endif
|
||||
|
||||
libeina_la_LIBADD = @EINA_LIBS@ @dlopen_libs@
|
||||
libeina_la_LDFLAGS = -no-undefined @lt_enable_auto_import@ -version-info @version_info@ @release_info@ @EFL_PTHREAD_LIBS@
|
||||
libeina_la_CFLAGS = @EINA_CFLAGS@ @EFL_PTHREAD_CFLAGS@
|
||||
libeina_la_LDFLAGS = -no-undefined @lt_enable_auto_import@ -version-info @version_info@ @release_info@ @EFL_PTHREAD_LIBS@ @iconv_libs@
|
||||
libeina_la_CFLAGS = @EINA_CFLAGS@ @EFL_PTHREAD_CFLAGS@ @iconv_cflags@
|
||||
|
||||
clean-local:
|
||||
rm -rf *.gcno eina_amalgamation.c
|
||||
|
|
|
@ -32,6 +32,11 @@
|
|||
#include <string.h>
|
||||
#include <limits.h>
|
||||
|
||||
#ifdef HAVE_ICONV
|
||||
# include <errno.h>
|
||||
# include <iconv.h>
|
||||
#endif
|
||||
|
||||
#include "eina_private.h"
|
||||
|
||||
/*============================================================================*
|
||||
|
@ -339,3 +344,79 @@ eina_str_join_len(char *dst, size_t size, char sep, const char *a, size_t a_len,
|
|||
dst[off + b_len] = '\0';
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Use iconv to convert a text string from one encoding to another
|
||||
*
|
||||
* @param enc_from encoding to convert from
|
||||
* @param enc_to encoding to convert to
|
||||
* @param text text to convert
|
||||
*
|
||||
*/
|
||||
EAPI char *
|
||||
eina_str_convert(const char *enc_from, const char *enc_to, const char *text)
|
||||
{
|
||||
#ifdef HAVE_ICONV
|
||||
iconv_t ic;
|
||||
char *new_txt, *inp, *outp;
|
||||
size_t inb, outb, outlen, tob, outalloc;
|
||||
|
||||
if (!text) return NULL;
|
||||
ic = iconv_open(enc_to, enc_from);
|
||||
if (ic == (iconv_t)(-1)) return NULL;
|
||||
new_txt = malloc(64);
|
||||
inb = strlen(text);
|
||||
outb = 64;
|
||||
inp = (char*)text;
|
||||
outp = new_txt;
|
||||
outalloc = 64;
|
||||
outlen = 0;
|
||||
|
||||
for (;;)
|
||||
{
|
||||
size_t count;
|
||||
|
||||
tob = outb;
|
||||
count = iconv(ic, &inp, &inb, &outp, &outb);
|
||||
outlen += tob - outb;
|
||||
if (count == (size_t)(-1))
|
||||
{
|
||||
if (errno == E2BIG)
|
||||
{
|
||||
new_txt = realloc(new_txt, outalloc + 64);
|
||||
outp = new_txt + outlen;
|
||||
outalloc += 64;
|
||||
outb += 64;
|
||||
}
|
||||
else if (errno == EILSEQ)
|
||||
{
|
||||
if (new_txt) free(new_txt);
|
||||
new_txt = NULL;
|
||||
break;
|
||||
}
|
||||
else if (errno == EINVAL)
|
||||
{
|
||||
if (new_txt) free(new_txt);
|
||||
new_txt = NULL;
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (new_txt) free(new_txt);
|
||||
new_txt = NULL;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (inb == 0)
|
||||
{
|
||||
if (outalloc == outlen) new_txt = realloc(new_txt, outalloc + 1);
|
||||
new_txt[outlen] = 0;
|
||||
break;
|
||||
}
|
||||
}
|
||||
iconv_close(ic);
|
||||
return new_txt;
|
||||
#else
|
||||
return NULL;
|
||||
#endif
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue