aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/regex.c35
1 files changed, 16 insertions, 19 deletions
diff --git a/src/regex.c b/src/regex.c
index 5cb997336f6..148100805eb 100644
--- a/src/regex.c
+++ b/src/regex.c
@@ -157,8 +157,9 @@
157 { \ 157 { \
158 re_char *dtemp = (p) == (str2) ? (end1) : (p); \ 158 re_char *dtemp = (p) == (str2) ? (end1) : (p); \
159 re_char *dlimit = ((p) > (str2) && (p) <= (end2)) ? (str2) : (str1); \ 159 re_char *dlimit = ((p) > (str2) && (p) <= (end2)) ? (str2) : (str1); \
160 while (dtemp-- > dlimit && !CHAR_HEAD_P (*dtemp)); \ 160 re_char *d0 = dtemp; \
161 c = STRING_CHAR (dtemp, (p) - dtemp); \ 161 PREV_CHAR_BOUNDARY (d0, dlimit); \
162 c = STRING_CHAR (d0, dtemp - d0); \
162 } \ 163 } \
163 else \ 164 else \
164 (c = ((p) == (str2) ? (end1) : (p))[-1]); \ 165 (c = ((p) == (str2) ? (end1) : (p))[-1]); \
@@ -235,6 +236,7 @@ enum syntaxcode { Swhitespace = 0, Sword = 1 };
235# define SINGLE_BYTE_CHAR_P(c) (1) 236# define SINGLE_BYTE_CHAR_P(c) (1)
236# define SAME_CHARSET_P(c1, c2) (1) 237# define SAME_CHARSET_P(c1, c2) (1)
237# define MULTIBYTE_FORM_LENGTH(p, s) (1) 238# define MULTIBYTE_FORM_LENGTH(p, s) (1)
239# define PREV_CHAR_BOUNDARY(p, limit) ((p)--)
238# define STRING_CHAR(p, s) (*(p)) 240# define STRING_CHAR(p, s) (*(p))
239# define RE_STRING_CHAR STRING_CHAR 241# define RE_STRING_CHAR STRING_CHAR
240# define CHAR_STRING(c, s) (*(s) = (c), 1) 242# define CHAR_STRING(c, s) (*(s) = (c), 1)
@@ -4064,6 +4066,10 @@ re_search (bufp, string, size, startpos, range, regs)
4064} 4066}
4065WEAK_ALIAS (__re_search, re_search) 4067WEAK_ALIAS (__re_search, re_search)
4066 4068
4069/* Head address of virtual concatenation of string. */
4070#define HEAD_ADDR_VSTRING(P) \
4071 (((P) >= size1 ? string2 : string1))
4072
4067/* End address of virtual concatenation of string. */ 4073/* End address of virtual concatenation of string. */
4068#define STOP_ADDR_VSTRING(P) \ 4074#define STOP_ADDR_VSTRING(P) \
4069 (((P) >= size1 ? string2 + size2 : string1 + size1)) 4075 (((P) >= size1 ? string2 + size2 : string1 + size1))
@@ -4299,26 +4305,17 @@ re_search_2 (bufp, str1, size1, str2, size2, startpos, range, regs, stop)
4299 /* Update STARTPOS to the previous character boundary. */ 4305 /* Update STARTPOS to the previous character boundary. */
4300 if (multibyte) 4306 if (multibyte)
4301 { 4307 {
4302 re_char *p = POS_ADDR_VSTRING (startpos); 4308 re_char *p = POS_ADDR_VSTRING (startpos) + 1;
4303 int len = 0; 4309 re_char *p0 = p;
4310 re_char *phead = HEAD_ADDR_VSTRING (startpos);
4304 4311
4305 /* Find the head of multibyte form. */ 4312 /* Find the head of multibyte form. */
4306 while (!CHAR_HEAD_P (*p)) 4313 PREV_CHAR_BOUNDARY (p, phead);
4307 p--, len++; 4314 range += p0 - 1 - p;
4308 4315 if (range > 0)
4309 /* Adjust it. */ 4316 break;
4310#if 0 /* XXX */
4311 if (MULTIBYTE_FORM_LENGTH (p, len + 1) != (len + 1))
4312 ;
4313 else
4314#endif
4315 {
4316 range += len;
4317 if (range > 0)
4318 break;
4319 4317
4320 startpos -= len; 4318 startpos -= p0 - 1 - p;
4321 }
4322 } 4319 }
4323 } 4320 }
4324 } 4321 }