diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/misc.c | 9 | ||||
-rw-r--r-- | lib/misc.h | 1 |
2 files changed, 10 insertions, 0 deletions
@@ -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; +} @@ -149,5 +149,6 @@ G_MODULE_EXPORT gboolean ssl_sockerr_again( void *ssl ); G_MODULE_EXPORT int md5_verify_password( char *password, char *hash ); G_MODULE_EXPORT char **split_command_parts( char *command, int limit ); G_MODULE_EXPORT char *get_rfc822_header( const char *text, const char *header, int len ); +G_MODULE_EXPORT int truncate_utf8( char *string, int maxlen ); #endif |