aboutsummaryrefslogtreecommitdiffstats
path: root/util/strgutil.c
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--util/strgutil.c46
1 files changed, 46 insertions, 0 deletions
diff --git a/util/strgutil.c b/util/strgutil.c
index 809b0c3f2..217b64043 100644
--- a/util/strgutil.c
+++ b/util/strgutil.c
@@ -179,6 +179,52 @@ string_count_chr( const char *string, int c )
return count;
}
+
+/****************
+ * Convert string, which is in native encoding to UTF8 and return the
+ * new allocated UTF8 string.
+ * This code assumes that native is iso-8859-1.
+ */
+char *
+native_to_utf8( const char *string )
+{
+ const byte *s;
+ char *buffer;
+ byte *p;
+ size_t length=0;
+
+ for(s=string; *s; s++ ) {
+ length++;
+ if( *s & 0x80 )
+ length++;
+ }
+ buffer = m_alloc( length + 1 );
+ for(p=buffer, s=string; *s; s++ ) {
+ if( *s & 0x80 ) {
+ *p++ = 0xc0 | ((*s >> 6) & 3);
+ *p++ = 0x80 | ( *s & 0x3f );
+ }
+ else
+ *p++ = *s;
+ }
+ *p = 0;
+ return buffer;
+}
+
+
+/****************
+ * Convert string, which is in UTF8 to native encoding. Replace
+ * illegal encodings by some "\xnn".
+ * This code assumes that native is iso-8859-1.
+ */
+char *
+utf8_to_native( const char *string )
+{
+ /* FIXME: Not yet done */
+ return m_strdup(string);
+}
+
+
/*********************************************
********** missing string functions *********
*********************************************/