From d058c8a14e688f90e547b687686a77efaf996845 Mon Sep 17 00:00:00 2001 From: Jason Rumney Date: Sun, 17 Jun 2007 22:25:08 +0000 Subject: [PATCH] (add_menu_item): Don't use multibyte string functions on unicode strings. --- src/ChangeLog | 5 ++++ src/w32menu.c | 68 ++++++++++++++++++++++++++++++++++----------------- 2 files changed, 51 insertions(+), 22 deletions(-) diff --git a/src/ChangeLog b/src/ChangeLog index 3f6e43f2bca..7de6155d427 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,8 @@ +2007-06-17 Jason Rumney + + * w32menu.c (add_menu_item): Don't use multibyte string functions on + unicode strings. + 2007-06-17 Juanma Barranquero * xdisp.c (syms_of_xdisp) : diff --git a/src/w32menu.c b/src/w32menu.c index bcd56c8c88e..d8d6fa186bd 100644 --- a/src/w32menu.c +++ b/src/w32menu.c @@ -2291,29 +2291,53 @@ add_menu_item (HMENU menu, widget_value *wv, HMENU item) /* Quote any special characters within the menu item's text and key binding. */ nlen = orig_len = strlen (out_string); - for (p = out_string; *p; p = _mbsinc (p)) - { - if (_mbsnextc (p) == '&') - nlen++; - } + if (unicode_append_menu) + { + /* With UTF-8, & cannot be part of a multibyte character. */ + for (p = out_string; *p; p++) + { + if (*p == '&') + nlen++; + } + } + else + { + /* If encoded with the system codepage, use multibyte string + functions in case of multibyte characters that contain '&'. */ + for (p = out_string; *p; p = _mbsinc (p)) + { + if (_mbsnextc (p) == '&') + nlen++; + } + } + if (nlen > orig_len) - { - p = out_string; - out_string = alloca (nlen + 1); - q = out_string; - while (*p) - { - if (_mbsnextc (p) == '&') - { - _mbsncpy (q, p, 1); - q = _mbsinc (q); - } - _mbsncpy (q, p, 1); - p = _mbsinc (p); - q = _mbsinc (q); - } - *q = '\0'; - } + { + p = out_string; + out_string = alloca (nlen + 1); + q = out_string; + while (*p) + { + if (unicode_append_menu) + { + if (*p == '&') + *q++ = *p; + *q++ = *p++; + } + else + { + if (_mbsnextc (p) == '&') + { + _mbsncpy (q, p, 1); + q = _mbsinc (q); + } + _mbsncpy (q, p, 1); + p = _mbsinc (p); + q = _mbsinc (q); + } + } + *q = '\0'; + } if (item != NULL) fuFlags = MF_POPUP; -- 2.39.2