comparison src/fontset.c @ 96020:b52fa52cd0fa

(fontset_pattern_regexp): Escape some regexp characters.
author Kenichi Handa <handa@m17n.org>
date Tue, 17 Jun 2008 01:25:11 +0000
parents 27b852856cdf
children b6d5b82f877f
comparison
equal deleted inserted replaced
96019:6cece6cbe017 96020:b52fa52cd0fa
1003 if (!CONSP (Vcached_fontset_data) 1003 if (!CONSP (Vcached_fontset_data)
1004 || strcmp ((char *) SDATA (pattern), CACHED_FONTSET_NAME)) 1004 || strcmp ((char *) SDATA (pattern), CACHED_FONTSET_NAME))
1005 { 1005 {
1006 /* We must at first update the cached data. */ 1006 /* We must at first update the cached data. */
1007 unsigned char *regex, *p0, *p1; 1007 unsigned char *regex, *p0, *p1;
1008 int ndashes = 0, nstars = 0, nplus = 0; 1008 int ndashes = 0, nstars = 0, nescs = 0;
1009 1009
1010 for (p0 = SDATA (pattern); *p0; p0++) 1010 for (p0 = SDATA (pattern); *p0; p0++)
1011 { 1011 {
1012 if (*p0 == '-') 1012 if (*p0 == '-')
1013 ndashes++; 1013 ndashes++;
1014 else if (*p0 == '*') 1014 else if (*p0 == '*')
1015 nstars++; 1015 nstars++;
1016 else if (*p0 == '+') 1016 else if (*p0 == '['
1017 nplus++; 1017 || *p0 == '.' || *p0 == '\\'
1018 || *p0 == '+' || *p0 == '^'
1019 || *p0 == '$')
1020 nescs++;
1018 } 1021 }
1019 1022
1020 /* If PATTERN is not full XLFD we conert "*" to ".*". Otherwise 1023 /* If PATTERN is not full XLFD we conert "*" to ".*". Otherwise
1021 we convert "*" to "[^-]*" which is much faster in regular 1024 we convert "*" to "[^-]*" which is much faster in regular
1022 expression matching. */ 1025 expression matching. */
1023 if (ndashes < 14) 1026 if (ndashes < 14)
1024 p1 = regex = (unsigned char *) alloca (SBYTES (pattern) + 2 * nstars + 2 * nplus + 1); 1027 p1 = regex = (unsigned char *) alloca (SBYTES (pattern) + 2 * nstars + 2 * nescs + 1);
1025 else 1028 else
1026 p1 = regex = (unsigned char *) alloca (SBYTES (pattern) + 5 * nstars + 2 * nplus + 1); 1029 p1 = regex = (unsigned char *) alloca (SBYTES (pattern) + 5 * nstars + 2 * nescs + 1);
1027 1030
1028 *p1++ = '^'; 1031 *p1++ = '^';
1029 for (p0 = SDATA (pattern); *p0; p0++) 1032 for (p0 = SDATA (pattern); *p0; p0++)
1030 { 1033 {
1031 if (*p0 == '*') 1034 if (*p0 == '*')
1036 *p1++ = '[', *p1++ = '^', *p1++ = '-', *p1++ = ']'; 1039 *p1++ = '[', *p1++ = '^', *p1++ = '-', *p1++ = ']';
1037 *p1++ = '*'; 1040 *p1++ = '*';
1038 } 1041 }
1039 else if (*p0 == '?') 1042 else if (*p0 == '?')
1040 *p1++ = '.'; 1043 *p1++ = '.';
1041 else if (*p0 == '+') 1044 else if (*p0 == '['
1042 *p1++ = '\\', *p1++ = '+'; 1045 || *p0 == '.' || *p0 == '\\'
1046 || *p0 == '+' || *p0 == '^'
1047 || *p0 == '$')
1048 *p1++ = '\\', *p1++ = *p0;
1043 else 1049 else
1044 *p1++ = *p0; 1050 *p1++ = *p0;
1045 } 1051 }
1046 *p1++ = '$'; 1052 *p1++ = '$';
1047 *p1++ = 0; 1053 *p1++ = 0;