aboutsummaryrefslogtreecommitdiff
path: root/src/mm-charsets.c
diff options
context:
space:
mode:
authorDan Williams <dcbw@redhat.com>2010-03-13 16:37:24 -0800
committerDan Williams <dcbw@redhat.com>2010-03-13 16:37:24 -0800
commit2a94d38edcc476022333a93dc979cc2bcf9ba5a2 (patch)
tree0384e2ed6d7740d80dc8885bcb9bf92f5f7f257a /src/mm-charsets.c
parentac7310ab1050701c07705e548c408d97aea76636 (diff)
core: move charset enum/string conversion to it's own file
Diffstat (limited to 'src/mm-charsets.c')
-rw-r--r--src/mm-charsets.c71
1 files changed, 71 insertions, 0 deletions
diff --git a/src/mm-charsets.c b/src/mm-charsets.c
new file mode 100644
index 00000000..36cdd0aa
--- /dev/null
+++ b/src/mm-charsets.c
@@ -0,0 +1,71 @@
+/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details:
+ *
+ * Copyright (C) 2010 Red Hat, Inc.
+ */
+
+#include <config.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <string.h>
+
+#include "mm-charsets.h"
+
+typedef struct {
+ const char *name;
+ MMModemCharset charset;
+} CharsetEntry;
+
+static CharsetEntry charset_map[] = {
+ { "UTF-8", MM_MODEM_CHARSET_UTF8 },
+ { "UCS2", MM_MODEM_CHARSET_UCS2 },
+ { "IRA", MM_MODEM_CHARSET_IRA },
+ { "GSM", MM_MODEM_CHARSET_GSM },
+ { "8859-1", MM_MODEM_CHARSET_8859_1 },
+ { "PCCP437", MM_MODEM_CHARSET_PCCP437 },
+ { "PCDN", MM_MODEM_CHARSET_PCDN },
+ { "HEX", MM_MODEM_CHARSET_HEX },
+ { NULL, MM_MODEM_CHARSET_UNKNOWN }
+};
+
+const char *
+mm_modem_charset_to_string (MMModemCharset charset)
+{
+ CharsetEntry *iter = &charset_map[0];
+
+ g_return_val_if_fail (charset != MM_MODEM_CHARSET_UNKNOWN, NULL);
+
+ while (iter->name) {
+ if (iter->charset == charset)
+ return iter->name;
+ iter++;
+ }
+ g_warn_if_reached ();
+ return NULL;
+}
+
+MMModemCharset
+mm_modem_charset_from_string (const char *string)
+{
+ CharsetEntry *iter = &charset_map[0];
+
+ g_return_val_if_fail (string != NULL, MM_MODEM_CHARSET_UNKNOWN);
+
+ while (iter->name) {
+ if (strcasestr (string, iter->name))
+ return iter->charset;
+ iter++;
+ }
+ return MM_MODEM_CHARSET_UNKNOWN;
+}
+