comparison src/misc2.c @ 3024:27d43855b723 v7.3.284

updated for version 7.3.284 Problem: The str2special() function doesn't handle multi-byte characters properly. Solution: Recognize multi-byte characters. (partly by Vladimir Vichniakov)
author Bram Moolenaar <bram@vim.org>
date Wed, 17 Aug 2011 20:33:22 +0200
parents aa40bddeea9a
children 6018c815e120
comparison
equal deleted inserted replaced
3023:023e84b3592c 3024:27d43855b723
2752 char_u *bp; 2752 char_u *bp;
2753 int modifiers; 2753 int modifiers;
2754 int bit; 2754 int bit;
2755 int key; 2755 int key;
2756 unsigned long n; 2756 unsigned long n;
2757 int l;
2757 2758
2758 src = *srcp; 2759 src = *srcp;
2759 if (src[0] != '<') 2760 if (src[0] != '<')
2760 return 0; 2761 return 0;
2761 2762
2764 for (bp = src + 1; *bp == '-' || vim_isIDc(*bp); bp++) 2765 for (bp = src + 1; *bp == '-' || vim_isIDc(*bp); bp++)
2765 { 2766 {
2766 if (*bp == '-') 2767 if (*bp == '-')
2767 { 2768 {
2768 last_dash = bp; 2769 last_dash = bp;
2769 if (bp[1] != NUL && bp[2] == '>') 2770 if (bp[1] != NUL)
2770 ++bp; /* anything accepted, like <C-?> */ 2771 {
2772 #ifdef FEAT_MBYTE
2773 if (has_mbyte)
2774 l = mb_ptr2len(bp + 1);
2775 else
2776 #endif
2777 l = 1;
2778 if (bp[l + 1] == '>')
2779 bp += l; /* anything accepted, like <C-?> */
2780 }
2771 } 2781 }
2772 if (bp[0] == 't' && bp[1] == '_' && bp[2] && bp[3]) 2782 if (bp[0] == 't' && bp[1] == '_' && bp[2] && bp[3])
2773 bp += 3; /* skip t_xx, xx may be '-' or '>' */ 2783 bp += 3; /* skip t_xx, xx may be '-' or '>' */
2774 } 2784 }
2775 2785
2776 if (*bp == '>') /* found matching '>' */ 2786 if (*bp == '>') /* found matching '>' */
2777 { 2787 {
2778 end_of_name = bp + 1; 2788 end_of_name = bp + 1;
2779
2780 if (STRNICMP(src + 1, "char-", 5) == 0 && VIM_ISDIGIT(src[6]))
2781 {
2782 /* <Char-123> or <Char-033> or <Char-0x33> */
2783 vim_str2nr(src + 6, NULL, NULL, TRUE, TRUE, NULL, &n);
2784 *modp = 0;
2785 *srcp = end_of_name;
2786 return (int)n;
2787 }
2788 2789
2789 /* Which modifiers are given? */ 2790 /* Which modifiers are given? */
2790 modifiers = 0x0; 2791 modifiers = 0x0;
2791 for (bp = src + 1; bp < last_dash; bp++) 2792 for (bp = src + 1; bp < last_dash; bp++)
2792 { 2793 {
2802 /* 2803 /*
2803 * Legal modifier name. 2804 * Legal modifier name.
2804 */ 2805 */
2805 if (bp >= last_dash) 2806 if (bp >= last_dash)
2806 { 2807 {
2808 if (STRNICMP(last_dash + 1, "char-", 5) == 0
2809 && VIM_ISDIGIT(last_dash[6]))
2810 {
2811 /* <Char-123> or <Char-033> or <Char-0x33> */
2812 vim_str2nr(last_dash + 6, NULL, NULL, TRUE, TRUE, NULL, &n);
2813 *modp = modifiers;
2814 *srcp = end_of_name;
2815 return (int)n;
2816 }
2817
2807 /* 2818 /*
2808 * Modifier with single letter, or special key name. 2819 * Modifier with single letter, or special key name.
2809 */ 2820 */
2810 if (modifiers != 0 && last_dash[2] == '>') 2821 #ifdef FEAT_MBYTE
2811 key = last_dash[1]; 2822 if (has_mbyte)
2823 l = mb_ptr2len(last_dash + 1);
2824 else
2825 #endif
2826 l = 1;
2827 if (modifiers != 0 && last_dash[l + 1] == '>')
2828 key = PTR2CHAR(last_dash + 1);
2812 else 2829 else
2813 { 2830 {
2814 key = get_special_key_code(last_dash + 1); 2831 key = get_special_key_code(last_dash + 1);
2815 if (!keep_x_key) 2832 if (!keep_x_key)
2816 key = handle_x_keys(key); 2833 key = handle_x_keys(key);