Commit 427dfbc0 authored by Andrea Schaefer's avatar Andrea Schaefer

Move e_phonenumber function to utils

Add chatty_utils_strip_blank
parent 8332e99a
......@@ -8,6 +8,7 @@
#include <glib.h>
#include <glib/gi18n.h>
#include "chatty-utils.h"
#include <libebook-contacts/libebook-contacts.h>
#define SECONDS_PER_MINUTE 60.0
......@@ -186,6 +187,53 @@ chatty_utils_time_ago_in_words (time_t time_stamp,
}
char *
chatty_utils_strip_blanks (const char *string)
{
char *result;
char **chunks;
chunks = g_strsplit (string, "%20", 0);
result = g_strjoinv(NULL, chunks);
g_strstrip (result);
g_strfreev (chunks);
return result;
}
char*
chatty_utils_format_phonenumber (const char *phone_number)
{
EPhoneNumber *number;
char *region;
char *stripped;
char *result;
g_autoptr(GError) err = NULL;
stripped = chatty_utils_strip_blanks (phone_number);
region = e_phone_number_get_default_region (NULL);
number = e_phone_number_from_string (stripped, region, &err);
if (!number || !e_phone_number_is_supported ()) {
g_warning ("failed to parse %s: %s", phone_number, err->message);
result = NULL;
} else {
result = e_phone_number_to_string (number, E_PHONE_NUMBER_FORMAT_E164);
}
g_free (region);
e_phone_number_free (number);
return result;
}
char *
chatty_utils_jabber_id_strip (const char *name)
{
......
......@@ -19,9 +19,9 @@ typedef enum {
} ChattyTimeAgoFlags;
char *chatty_utils_jabber_id_strip (const char *name);
char *chatty_utils_strip_blanks (const char *string);
char *chatty_utils_format_phonenumber (const char *phone_number);
void chatty_utils_generate_uuid (char **uuid);
char *chatty_utils_time_ago_in_words (time_t time_stamp, ChattyTimeAgoFlags flags);
#endif
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment