* add mu_msg_str_normalize (to remove accents from strings, optionally lowercase)

This commit is contained in:
Dirk-Jan C. Binnema 2010-11-02 00:05:27 +02:00
parent 1e93d614a9
commit 23f1275a24
2 changed files with 42 additions and 0 deletions

View File

@ -23,6 +23,31 @@
#include "mu-msg-str.h"
#include "mu-msg-flags.h"
char*
mu_msg_str_normalize (const char *str, gboolean downcase)
{
gchar *s;
if (!str)
return NULL;
s = g_utf8_normalize (str, -1, G_NORMALIZE_ALL);
if (!s) {
g_warning ("%s: not valid utf8 '%s'", __FUNCTION__, str);
return NULL;
}
if (downcase) {
gchar *tmp;
tmp = g_utf8_strdown (s, -1);
g_free (s);
s = tmp;
}
return s;
}
const char*
mu_msg_str_date_s (time_t t)

View File

@ -26,6 +26,8 @@
#include "mu-msg.h"
#include "mu-msg-flags.h"
G_BEGIN_DECLS
/**
* get a display string for a given time_t;
* use the preferred date/time for the current locale
@ -104,4 +106,19 @@ const char* mu_msg_str_prio (MuMsgPrio prio) G_GNUC_CONST;
char* mu_msg_str_summarize (const char* str,
size_t max_lines) G_GNUC_WARN_UNUSED_RESULT;
/**
* normalize a string (ie., collapse accented characters etc.), and
* optionally, downcase it
*
* @param str a valid utf8 string or NULL
* @param downcase if TRUE, convert the string to lowercase
*
* @return the normalize string, or NULL in case of error or str was NULL
*/
char* mu_msg_str_normalize (const char *str, gboolean downcase);
G_END_DECLS
#endif /*__MU_MSG_STR_H__*/