aboutsummaryrefslogtreecommitdiffstats
path: root/lib/misc.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/misc.c')
-rw-r--r--lib/misc.c9
1 files changed, 9 insertions, 0 deletions
diff --git a/lib/misc.c b/lib/misc.c
index 02b1814c..6fedb48f 100644
--- a/lib/misc.c
+++ b/lib/misc.c
@@ -779,3 +779,12 @@ char *get_rfc822_header( const char *text, const char *header, int len )
return NULL;
}
+
+/* Takes a string, truncates it where it's safe, returns the new length */
+int truncate_utf8( char *string, int maxlen )
+{
+ char *end;
+ g_utf8_validate( (const gchar *) string, maxlen, (const gchar **) &end );
+ *end = '\0';
+ return end - string;
+}