Mechanism for iterating over all supported charsets.
authorsimon <simon@cda61777-01e9-0310-a592-d414129be87e>
Wed, 18 Jul 2012 22:49:07 +0000 (22:49 +0000)
committersimon <simon@cda61777-01e9-0310-a592-d414129be87e>
Wed, 18 Jul 2012 22:49:07 +0000 (22:49 +0000)
git-svn-id: svn://svn.tartarus.org/sgt/charset@9580 cda61777-01e9-0310-a592-d414129be87e

charset.h
slookup.c

index 5dd4d3a..bbc69e4 100644 (file)
--- a/charset.h
+++ b/charset.h
@@ -93,7 +93,8 @@ typedef enum {
     CS_ISO2022,
     CS_BS4730,
     CS_DEC_GRAPHICS,
-    CS_EUC_TW
+    CS_EUC_TW,
+    CS_LIMIT               /* dummy value indicating extent of enum */
 } charset_t;
 
 typedef struct {
@@ -249,4 +250,19 @@ int charset_contains_ascii(int charset);
  */
 int charset_from_locale(void);
 
+/*
+ * This function simply reports whether a charset identifier
+ * corresponds to an actually usable charset. Not everything in the
+ * above enum does: CS_NONE, for a start, and occasionally other slots
+ * in the enum are reserved before they actually go into service.
+ *
+ * This function permits clients to iterate over _all_ supported
+ * charsets by means of a loop such as
+ *
+ *     for (cs = 0; cs < CS_LIMIT; cs++)
+ *         if (charset_exists(cs))
+ *             do_stuff_with(cs);
+ */
+int charset_exists(int charset);
+
 #endif /* charset_charset_h */
index 7a4d7c2..e49e68c 100644 (file)
--- a/slookup.c
+++ b/slookup.c
@@ -27,3 +27,8 @@ charset_spec const *charset_find_spec(int charset)
 
     return NULL;
 }
+
+int charset_exists(int charset)
+{
+    return charset_find_spec(charset) != NULL;
+}