mirror of https://github.com/djcb/mu.git
* add mu_msg_str_normalize (to remove accents from strings, optionally lowercase)
This commit is contained in:
parent
1e93d614a9
commit
23f1275a24
|
@ -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)
|
||||
|
|
|
@ -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__*/
|
||||
|
|
Loading…
Reference in New Issue