From a010160576d6f6eb269902fe0e26c53bd56d29b1 Mon Sep 17 00:00:00 2001 From: Simon Tatham Date: Wed, 21 Apr 2004 18:07:26 +0000 Subject: Charset support for the info backend (\cfg{info-charset}). (This checkin touches other files because a function in bk_text.c turned out to be of more general use so I moved it out into ustring.c.) [originally from svn r4111] --- ustring.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'ustring.c') diff --git a/ustring.c b/ustring.c index 169a377..11a022c 100644 --- a/ustring.c +++ b/ustring.c @@ -314,3 +314,23 @@ wchar_t *ustrftime(wchar_t *wfmt, struct tm *timespec) { sfree(text); return wblk; } + +/* + * Determine whether a Unicode string can be translated into a + * given charset without any missing characters. + */ +int cvt_ok(int charset, const wchar_t *s) +{ + char buf[256]; + charset_state state = CHARSET_INIT_STATE; + int err, len = ustrlen(s); + + err = 0; + while (len > 0) { + (void)charset_from_unicode(&s, &len, buf, lenof(buf), + charset, &state, &err); + if (err) + return FALSE; + } + return TRUE; +} -- cgit v1.1