[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] r18801 - in gnunet/src: include util
From: |
gnunet |
Subject: |
[GNUnet-SVN] r18801 - in gnunet/src: include util |
Date: |
Sat, 24 Dec 2011 22:40:49 +0100 |
Author: grothoff
Date: 2011-12-24 22:40:49 +0100 (Sat, 24 Dec 2011)
New Revision: 18801
Modified:
gnunet/src/include/gnunet_strings_lib.h
gnunet/src/util/strings.c
Log:
-LRN: new charset conversion functions / #2031
Modified: gnunet/src/include/gnunet_strings_lib.h
===================================================================
--- gnunet/src/include/gnunet_strings_lib.h 2011-12-24 19:54:16 UTC (rev
18800)
+++ gnunet/src/include/gnunet_strings_lib.h 2011-12-24 21:40:49 UTC (rev
18801)
@@ -87,6 +87,18 @@
/**
* Convert the len characters long character sequence
+ * given in input that is in the given input charset
+ * to a string in given output charset.
+ * @return the converted string (0-terminated),
+ * if conversion fails, a copy of the orignal
+ * string is returned.
+ */
+char *
+GNUNET_STRINGS_conv (const char *input, size_t len,
+ const char *input_charset, const char *output_charset);
+
+/**
+ * Convert the len characters long character sequence
* given in input that is in the given charset
* to UTF-8.
*
@@ -98,7 +110,18 @@
char *
GNUNET_STRINGS_to_utf8 (const char *input, size_t len, const char *charset);
+/**
+ * Convert the len bytes-long UTF-8 string
+ * given in input to the given charset.
+ * @return the converted string (0-terminated),
+ * if conversion fails, a copy of the orignal
+ * string is returned.
+ */
+char *
+GNUNET_STRINGS_from_utf8 (const char *input, size_t len, const char *charset);
+
+
/**
* Complete filename (a la shell) from abbrevition.
*
Modified: gnunet/src/util/strings.c
===================================================================
--- gnunet/src/util/strings.c 2011-12-24 19:54:16 UTC (rev 18800)
+++ gnunet/src/util/strings.c 2011-12-24 21:40:49 UTC (rev 18801)
@@ -327,17 +327,16 @@
return GNUNET_OK;
}
-
/**
* Convert the len characters long character sequence
- * given in input that is in the given charset
- * to UTF-8.
+ * given in input that is in the given input charset
+ * to a string in given output charset.
* @return the converted string (0-terminated),
* if conversion fails, a copy of the orignal
* string is returned.
*/
char *
-GNUNET_STRINGS_to_utf8 (const char *input, size_t len, const char *charset)
+GNUNET_STRINGS_conv (const char *input, size_t len, const char *input_charset,
const char *output_charset)
{
char *ret;
@@ -348,12 +347,12 @@
char *itmp;
iconv_t cd;
- cd = iconv_open ("UTF-8", charset);
+ cd = iconv_open (output_charset, input_charset);
if (cd == (iconv_t) - 1)
{
LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING, "iconv_open");
- LOG (GNUNET_ERROR_TYPE_WARNING, _("Character set requested was `%s'\n"),
- charset);
+ LOG (GNUNET_ERROR_TYPE_WARNING, _("Character sets requested were
`%s'->`%s'\n"),
+ input_charset, output_charset);
ret = GNUNET_malloc (len + 1);
memcpy (ret, input, len);
ret[len] = '\0';
@@ -396,6 +395,36 @@
/**
+ * Convert the len characters long character sequence
+ * given in input that is in the given charset
+ * to UTF-8.
+ * @return the converted string (0-terminated),
+ * if conversion fails, a copy of the orignal
+ * string is returned.
+ */
+char *
+GNUNET_STRINGS_to_utf8 (const char *input, size_t len, const char *charset)
+{
+ return GNUNET_STRINGS_conv (input, len, charset, "UTF-8");
+}
+
+/**
+ * Convert the len bytes-long UTF-8 string
+ * given in input to the given charset.
+
+ * @return the converted string (0-terminated),
+ * if conversion fails, a copy of the orignal
+ * string is returned.
+ */
+char *
+GNUNET_STRINGS_from_utf8 (const char *input, size_t len, const char *charset)
+{
+ return GNUNET_STRINGS_conv (input, len, "UTF-8", charset);
+}
+
+
+
+/**
* Complete filename (a la shell) from abbrevition.
* @param fil the name of the file, may contain ~/ or
* be relative to the current directory
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [GNUnet-SVN] r18801 - in gnunet/src: include util,
gnunet <=