[network-manager-applet/aleksander/mobile-providers-mccmnc: 2/2] libnm-gtk, mobile-providers: new method to let clients split a MCCMNC string
- From: Aleksander Morgado <aleksm src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [network-manager-applet/aleksander/mobile-providers-mccmnc: 2/2] libnm-gtk, mobile-providers: new method to let clients split a MCCMNC string
- Date: Mon, 26 Nov 2012 20:07:01 +0000 (UTC)
commit b291df3884d96db94ff23749c5440720ef774234
Author: Aleksander Morgado <aleksander lanedo com>
Date: Mon Nov 26 21:06:32 2012 +0100
libnm-gtk,mobile-providers: new method to let clients split a MCCMNC string
Clients shouldn't need to know how to do the split of the MCCMNC string, just
hide the logic behind a helper method.
src/libnm-gtk/nm-mobile-providers.c | 35 +++++++++++++++++++++++++++++++++++
src/libnm-gtk/nm-mobile-providers.h | 4 ++++
2 files changed, 39 insertions(+), 0 deletions(-)
---
diff --git a/src/libnm-gtk/nm-mobile-providers.c b/src/libnm-gtk/nm-mobile-providers.c
index d293921..9ed46f3 100644
--- a/src/libnm-gtk/nm-mobile-providers.c
+++ b/src/libnm-gtk/nm-mobile-providers.c
@@ -1187,3 +1187,38 @@ nma_mobile_providers_find_for_cdma_sid (GHashTable *country_infos,
return NULL;
}
+
+/**
+ * nma_mobile_providers_split_3gpp_mcc_mnc:
+ * @mccmnc: input MCCMNC string.
+ * @mcc: (out) (transfer full): the MCC.
+ * @mnc: (out) (transfer full): the MNC.
+ *
+ * Splits the input MCCMNC string into separate MCC and MNC strings.
+ *
+ * Returns: %TRUE if correctly split and @mcc and @mnc are set; %FALSE otherwise.
+ */
+gboolean
+nma_mobile_providers_split_3gpp_mcc_mnc (const gchar *mccmnc,
+ gchar **mcc,
+ gchar **mnc)
+{
+ gint len;
+
+ g_return_val_if_fail (mccmnc != NULL, FALSE);
+ g_return_val_if_fail (mcc != NULL, FALSE);
+ g_return_val_if_fail (mnc != NULL, FALSE);
+
+ len = strlen (mccmnc);
+ g_return_val_if_fail (len != 5 && len != 6, FALSE);
+
+ /* MCCMNC is all digits */
+ while (len > 0) {
+ if (!g_ascii_isdigit (mccmnc[len - 1]))
+ return FALSE;
+ }
+
+ *mcc = g_strndup (mccmnc, 3);
+ *mnc = g_strdup (mccmnc + 3);
+ return TRUE;
+}
diff --git a/src/libnm-gtk/nm-mobile-providers.h b/src/libnm-gtk/nm-mobile-providers.h
index 53e30a8..e8c1d93 100644
--- a/src/libnm-gtk/nm-mobile-providers.h
+++ b/src/libnm-gtk/nm-mobile-providers.h
@@ -98,4 +98,8 @@ NMAMobileProvider *nma_mobile_providers_find_for_3gpp_mcc_mnc (GHashTable *coun
NMAMobileProvider *nma_mobile_providers_find_for_cdma_sid (GHashTable *country_infos,
guint32 sid);
+gboolean nma_mobile_providers_split_3gpp_mcc_mnc (const gchar *mccmnc,
+ gchar **mcc,
+ gchar **mnc);
+
#endif /* NM_MOBILE_PROVIDERS_H */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]