From b6447ae26b59f8e3ad3da306b72cb0a199398ef5 Mon Sep 17 00:00:00 2001 From: Kalle Olavi Niemitalo Date: Sun, 13 Aug 2006 23:35:50 +0300 Subject: [PATCH] UTF-8: New function cp_to_unicode(). --- src/bfu/dialog.c | 7 ++----- src/intl/charsets.c | 19 +++++++++++++++++++ src/intl/charsets.h | 1 + 3 files changed, 22 insertions(+), 5 deletions(-) diff --git a/src/bfu/dialog.c b/src/bfu/dialog.c index 80e874c0..fad2d7dd 100644 --- a/src/bfu/dialog.c +++ b/src/bfu/dialog.c @@ -320,11 +320,8 @@ select_button_by_key(struct dialog_data *dlg_data) hk_ptr = widget_data->widget->text; #ifdef CONFIG_UTF_8 - if (is_cp_utf8(codepage)) - hk_char = utf_8_to_unicode(&hk_ptr, - strchr(hk_ptr, '\0')); - else - hk_char = cp2u(codepage, *hk_ptr); + hk_char = cp_to_unicode(codepage, &hk_ptr, + strchr(hk_ptr, '\0')); hk_char = unicode_fold_label_case(hk_char); #else hk_char = toupper(*hk_ptr); diff --git a/src/intl/charsets.c b/src/intl/charsets.c index 8fd19f9b..5809403e 100644 --- a/src/intl/charsets.c +++ b/src/intl/charsets.c @@ -522,6 +522,25 @@ cp2utf_8(int from, int c) return encode_utf_8(cp2u_shared(&codepages[from], c)); } +#ifdef CONFIG_UTF_8 +unicode_val_T +cp_to_unicode(int codepage, unsigned char **string, unsigned char *end) +{ + if (is_cp_utf8(codepage)) + return utf_8_to_unicode(string, end); + else { + if (*string >= end) + return UCS_NO_CHAR; + else { + unicode_val_T ret = cp2u(codepage, **string); + ++*string; + return ret; + } + } +} +#endif /* CONFIG_UTF_8 */ + + static void add_utf_8(struct conv_table *ct, unicode_val_T u, unsigned char *str) { diff --git a/src/intl/charsets.h b/src/intl/charsets.h index 16bc8664..6a28c8ae 100644 --- a/src/intl/charsets.h +++ b/src/intl/charsets.h @@ -65,6 +65,7 @@ inline int unicode_to_cell(unicode_val_T); unicode_val_T unicode_fold_label_case(unicode_val_T); inline int strlen_utf8(unsigned char **); inline unicode_val_T utf_8_to_unicode(unsigned char **, unsigned char *); +unicode_val_T cp_to_unicode(int, unsigned char **, unsigned char *); #endif /* CONFIG_UTF_8 */ unicode_val_T cp2u(int, unsigned char); -- 2.11.4.GIT