changeset 81458:c5bc6e90f8ec

(add_menu_item): Don't use multibyte string functions on unicode strings.
author Jason Rumney <jasonr@gnu.org>
date Sun, 17 Jun 2007 22:10:06 +0000
parents 00c36cdb7641
children 91a0dbce1695
files src/w32menu.c
diffstat 1 files changed, 46 insertions(+), 22 deletions(-) [+]
line wrap: on
line diff
--- a/src/w32menu.c	Sun Jun 17 15:23:15 2007 +0000
+++ b/src/w32menu.c	Sun Jun 17 22:10:06 2007 +0000
@@ -2291,29 +2291,53 @@
       /* 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;