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
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}"
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.
-DPACKAGE_LIB_DIR=\"$(libdir)\" \
-DPACKAGE_DATA_DIR=\"$(datadir)/$(PACKAGE)\" \
@EINA_CPPFLAGS@ \
-@EFL_EINA_BUILD@
+@EFL_EINA_BUILD@ \
+@iconv_cflags@
base_sources = \
eina_error.c \
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
#include <string.h>
#include <limits.h>
+#ifdef HAVE_ICONV
+# include <errno.h>
+# include <iconv.h>
+#endif
+
#include "eina_private.h"
/*============================================================================*
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
+}