]> code.delx.au - gnu-emacs/commitdiff
(add_menu_item): Don't use multibyte string functions on
authorJason Rumney <jasonr@gnu.org>
Sun, 17 Jun 2007 22:11:16 +0000 (22:11 +0000)
committerJason Rumney <jasonr@gnu.org>
Sun, 17 Jun 2007 22:11:16 +0000 (22:11 +0000)
unicode strings.

src/ChangeLog
src/w32menu.c

index 589f37217f54b06d78e392e2c76002fa35d489b3..5410a13e384f4cd1978e575861e3def35bcab742 100644 (file)
@@ -1,3 +1,8 @@
+2007-06-17  Jason Rumney  <jasonr@gnu.org>
+
+       * w32menu.c (add_menu_item): Don't use multibyte string functions on
+       unicode strings.
+
 2007-06-16  Juanma Barranquero  <lekktu@gmail.com>
 
        * xdisp.c (syms_of_xdisp) <auto-resize-tool-bars>:
index bcd56c8c88e7072abf34ec3ad367b95e32109a38..d8d6fa186bd64b5d4718407b3b4849736204b4f6 100644 (file)
@@ -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;