[gnome-desktop/wip/hadess/simplify-assignment] gnome-languages: Simplify variable assignment
- From: Bastien Nocera <hadess src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-desktop/wip/hadess/simplify-assignment] gnome-languages: Simplify variable assignment
- Date: Thu, 21 Jul 2022 18:45:35 +0000 (UTC)
commit 99be37ce78f5bc02dee83edfae0f035edf9d3995
Author: Bastien Nocera <hadess hadess net>
Date: Thu Jul 21 20:44:48 2022 +0200
gnome-languages: Simplify variable assignment
libgnome-desktop/gnome-languages.c | 35 ++++++++++++++---------------------
1 file changed, 14 insertions(+), 21 deletions(-)
---
diff --git a/libgnome-desktop/gnome-languages.c b/libgnome-desktop/gnome-languages.c
index 7a0ef6ba..0f604b8a 100644
--- a/libgnome-desktop/gnome-languages.c
+++ b/libgnome-desktop/gnome-languages.c
@@ -105,6 +105,14 @@ normalize_codeset (const char *codeset)
return g_strdup (codeset);
}
+static void
+assign_if_non_empty (char **variable, char *value)
+{
+ if (value == NULL || *value == '\0')
+ return;
+ *variable = value;
+}
+
/**
* gnome_parse_locale:
* @locale: a locale string
@@ -173,33 +181,18 @@ gnome_parse_locale (const char *locale,
}
if (country_codep != NULL) {
- *country_codep = g_match_info_fetch_named (match_info, "territory");
-
- if (*country_codep != NULL &&
- *country_codep[0] == '\0') {
- g_free (*country_codep);
- *country_codep = NULL;
- }
+ assign_if_non_empty (country_codep,
+ g_match_info_fetch_named (match_info, "territory"));
}
if (codesetp != NULL) {
- *codesetp = g_match_info_fetch_named (match_info, "codeset");
-
- if (*codesetp != NULL &&
- *codesetp[0] == '\0') {
- g_free (*codesetp);
- *codesetp = NULL;
- }
+ assign_if_non_empty (codesetp,
+ g_match_info_fetch_named (match_info, "codeset"));
}
if (modifierp != NULL) {
- *modifierp = g_match_info_fetch_named (match_info, "modifier");
-
- if (*modifierp != NULL &&
- *modifierp[0] == '\0') {
- g_free (*modifierp);
- *modifierp = NULL;
- }
+ assign_if_non_empty (modifierp,
+ g_match_info_fetch_named (match_info, "modifier"));
}
if (codesetp != NULL && *codesetp != NULL) {
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]