From 3e5305f1131c78e7dee9d43ee33d8ea6e5e28c86 Mon Sep 17 00:00:00 2001 From: simon Date: Wed, 18 Jul 2012 22:49:07 +0000 Subject: [PATCH] Mechanism for iterating over all supported charsets. git-svn-id: svn://svn.tartarus.org/sgt/charset@9580 cda61777-01e9-0310-a592-d414129be87e --- charset.h | 18 +++++++++++++++++- slookup.c | 5 +++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/charset.h b/charset.h index 5dd4d3a..bbc69e4 100644 --- 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 */ diff --git a/slookup.c b/slookup.c index 7a4d7c2..e49e68c 100644 --- 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; +} -- 2.11.0