# HG changeset patch # User Kenichi Handa # Date 1213665911 0 # Node ID b52fa52cd0fa70c2d8955bfc2ef7609450536b21 # Parent 6cece6cbe01778e7ee823dd283376b6a3bb046f3 (fontset_pattern_regexp): Escape some regexp characters. diff -r 6cece6cbe017 -r b52fa52cd0fa src/fontset.c --- a/src/fontset.c Mon Jun 16 22:42:46 2008 +0000 +++ b/src/fontset.c Tue Jun 17 01:25:11 2008 +0000 @@ -1005,7 +1005,7 @@ { /* We must at first update the cached data. */ unsigned char *regex, *p0, *p1; - int ndashes = 0, nstars = 0, nplus = 0; + int ndashes = 0, nstars = 0, nescs = 0; for (p0 = SDATA (pattern); *p0; p0++) { @@ -1013,17 +1013,20 @@ ndashes++; else if (*p0 == '*') nstars++; - else if (*p0 == '+') - nplus++; + else if (*p0 == '[' + || *p0 == '.' || *p0 == '\\' + || *p0 == '+' || *p0 == '^' + || *p0 == '$') + nescs++; } /* If PATTERN is not full XLFD we conert "*" to ".*". Otherwise we convert "*" to "[^-]*" which is much faster in regular expression matching. */ if (ndashes < 14) - p1 = regex = (unsigned char *) alloca (SBYTES (pattern) + 2 * nstars + 2 * nplus + 1); + p1 = regex = (unsigned char *) alloca (SBYTES (pattern) + 2 * nstars + 2 * nescs + 1); else - p1 = regex = (unsigned char *) alloca (SBYTES (pattern) + 5 * nstars + 2 * nplus + 1); + p1 = regex = (unsigned char *) alloca (SBYTES (pattern) + 5 * nstars + 2 * nescs + 1); *p1++ = '^'; for (p0 = SDATA (pattern); *p0; p0++) @@ -1038,8 +1041,11 @@ } else if (*p0 == '?') *p1++ = '.'; - else if (*p0 == '+') - *p1++ = '\\', *p1++ = '+'; + else if (*p0 == '[' + || *p0 == '.' || *p0 == '\\' + || *p0 == '+' || *p0 == '^' + || *p0 == '$') + *p1++ = '\\', *p1++ = *p0; else *p1++ = *p0; }