aboutsummaryrefslogtreecommitdiff
path: root/src/utils.c
diff options
context:
space:
mode:
authorCharles Kerr <charles.kerr@canonical.com>2013-09-07 09:39:38 -0500
committerCharles Kerr <charles.kerr@canonical.com>2013-09-07 09:39:38 -0500
commitdd147887cb70a52dcba1cd26d9bbf7e29545afc4 (patch)
tree3190026fc9bea65c3eb9f67d967802222e2d4927 /src/utils.c
parentddebe3c47040869cb8fe94729c43f10f2b763550 (diff)
downloadayatana-indicator-datetime-dd147887cb70a52dcba1cd26d9bbf7e29545afc4.tar.gz
ayatana-indicator-datetime-dd147887cb70a52dcba1cd26d9bbf7e29545afc4.tar.bz2
ayatana-indicator-datetime-dd147887cb70a52dcba1cd26d9bbf7e29545afc4.zip
add preliminary unit tests for utils
Diffstat (limited to 'src/utils.c')
-rw-r--r--src/utils.c51
1 files changed, 30 insertions, 21 deletions
diff --git a/src/utils.c b/src/utils.c
index b99de94..5dccc52 100644
--- a/src/utils.c
+++ b/src/utils.c
@@ -53,32 +53,41 @@ is_locale_12h (void)
void
split_settings_location (const gchar * location, gchar ** zone, gchar ** name)
{
- gchar * location_dup = g_strdup (location);
- gchar * first = strchr (location_dup, ' ');
+ gchar * location_dup;
+ gchar * first;
- if (first) {
- first[0] = 0;
- }
+ location_dup = g_strdup (location);
+ g_strstrip (location_dup);
- if (zone) {
- *zone = location_dup;
- }
+ if ((first = strchr (location_dup, ' ')))
+ *first = '\0';
- if (name) {
- gchar * after = first ? g_strstrip (first + 1) : NULL;
- if (after == NULL || after[0] == 0) {
- /* Make up name from zone */
- gchar * chr = strrchr (location_dup, '/');
- after = g_strdup (chr ? chr + 1 : location_dup);
- while ((chr = strchr (after, '_')) != NULL) { /* and turn underscores to spaces */
- *chr = ' ';
- }
- *name = after;
+ if (zone != NULL)
+ {
+ *zone = location_dup;
}
- else {
- *name = g_strdup (after);
+
+ if (name != NULL)
+ {
+ gchar * after = first ? g_strstrip (first + 1) : NULL;
+
+ if (after && *after)
+ {
+ *name = g_strdup (after);
+ }
+ else /* make the name from zone */
+ {
+ gchar * chr = strrchr (location_dup, '/');
+ after = g_strdup (chr ? chr + 1 : location_dup);
+
+ /* replace underscores with spaces */
+ for (chr=after; chr && *chr; chr++)
+ if (*chr == '_')
+ *chr = ' ';
+
+ *name = after;
+ }
}
- }
}
gchar *