diff options
| author | Simon Tatham <anakin@pobox.com> | 2004-06-27 13:18:32 +0000 |
|---|---|---|
| committer | Simon Tatham <anakin@pobox.com> | 2004-06-27 13:18:32 +0000 |
| commit | d87fabeacea32abba73d67f991f9e523991369c7 (patch) | |
| tree | 2107cd344ecdf683140efcf9503a23677f55141c /ustring.c | |
| parent | 037337dcc8cc4e7f2f8a628ab73b1b461dae7171 (diff) | |
| download | halibut-d87fabeacea32abba73d67f991f9e523991369c7.zip halibut-d87fabeacea32abba73d67f991f9e523991369c7.tar.gz halibut-d87fabeacea32abba73d67f991f9e523991369c7.tar.bz2 halibut-d87fabeacea32abba73d67f991f9e523991369c7.tar.xz | |
Sort out error handling everywhere a charset name is converted into
an integer charset ID.
[originally from svn r4317]
Diffstat (limited to 'ustring.c')
| -rw-r--r-- | ustring.c | 25 |
1 files changed, 25 insertions, 0 deletions
@@ -459,3 +459,28 @@ int cvt_ok(int charset, const wchar_t *s) } return TRUE; } + +/* + * Wrapper around charset_from_localenc which accepts the charset + * name as a wide string (since that happens to be more useful). + * Also throws a Halibut error and falls back to CS_ASCII if the + * charset is unrecognised, meaning the rest of the program can + * rely on always getting a valid charset id back from this + * function. + */ +int charset_from_ustr(filepos *fpos, const wchar_t *name) +{ + char *csname; + int charset; + + csname = utoa_dup(name, CS_ASCII); + charset = charset_from_localenc(csname); + + if (charset == CS_NONE) { + charset = CS_ASCII; + error(err_charset, fpos, name); + } + + sfree(csname); + return charset; +} |