comparison src/search.c @ 282:c42ec1d1cded r21-0b39

Import from CVS: tag r21-0b39
author cvs
date Mon, 13 Aug 2007 10:33:18 +0200
parents c5d627a313b1
children 57709be46d1b
comparison
equal deleted inserted replaced
281:090b52736db2 282:c42ec1d1cded
2245 (num)) 2245 (num))
2246 { 2246 {
2247 return match_limit (num, 0); 2247 return match_limit (num, 0);
2248 } 2248 }
2249 2249
2250 DEFUN ("match-data", Fmatch_data, 0, 0, 0, /* 2250 DEFUN ("match-data", Fmatch_data, 0, 2, 0, /*
2251 Return a list containing all info on what the last regexp search matched. 2251 Return a list containing all info on what the last regexp search matched.
2252 Element 2N is `(match-beginning N)'; element 2N + 1 is `(match-end N)'. 2252 Element 2N is `(match-beginning N)'; element 2N + 1 is `(match-end N)'.
2253 All the elements are markers or nil (nil if the Nth pair didn't match) 2253 All the elements are markers or nil (nil if the Nth pair didn't match)
2254 if the last match was on a buffer; integers or nil if a string was matched. 2254 if the last match was on a buffer; integers or nil if a string was matched.
2255 Use `store-match-data' to reinstate the data in this list. 2255 Use `store-match-data' to reinstate the data in this list.
2256
2257 If INTEGERS (the optional first argument) is non-nil, always use integers
2258 \(rather than markers) to represent buffer positions.
2259 If REUSE is a list, reuse it as part of the value. If REUSE is long enough
2260 to hold all the values, and if INTEGERS is non-nil, no consing is done.
2256 */ 2261 */
2257 ()) 2262 (integers, reuse))
2258 { 2263 {
2259 /* This function has been Mule-ized. */ 2264 /* This function has been Mule-ized. */
2265 Lisp_Object tail, prev;
2260 Lisp_Object *data; 2266 Lisp_Object *data;
2261 int i; 2267 int i;
2262 Charcount len; 2268 Charcount len;
2263 2269
2264 if (NILP (last_thing_searched)) 2270 if (NILP (last_thing_searched))
2271 for (i = 0; i < search_regs.num_regs; i++) 2277 for (i = 0; i < search_regs.num_regs; i++)
2272 { 2278 {
2273 Bufpos start = search_regs.start[i]; 2279 Bufpos start = search_regs.start[i];
2274 if (start >= 0) 2280 if (start >= 0)
2275 { 2281 {
2276 if (EQ (last_thing_searched, Qt)) 2282 if (EQ (last_thing_searched, Qt)
2283 || !NILP (integers))
2277 { 2284 {
2278 data[2 * i] = make_int (start); 2285 data[2 * i] = make_int (start);
2279 data[2 * i + 1] = make_int (search_regs.end[i]); 2286 data[2 * i + 1] = make_int (search_regs.end[i]);
2280 } 2287 }
2281 else if (BUFFERP (last_thing_searched)) 2288 else if (BUFFERP (last_thing_searched))
2296 len = i; 2303 len = i;
2297 } 2304 }
2298 else 2305 else
2299 data[2 * i] = data [2 * i + 1] = Qnil; 2306 data[2 * i] = data [2 * i + 1] = Qnil;
2300 } 2307 }
2301 return Flist (2 * len + 2, data); 2308 if (!CONSP (reuse))
2309 return Flist (2 * len + 2, data);
2310
2311 /* If REUSE is a list, store as many value elements as will fit
2312 into the elements of REUSE. */
2313 for (i = 0, tail = reuse; CONSP (tail); i++, tail = XCDR (tail))
2314 {
2315 if (i < 2 * len + 2)
2316 XCAR (tail) = data[i];
2317 else
2318 XCAR (tail) = Qnil;
2319 prev = tail;
2320 }
2321
2322 /* If we couldn't fit all value elements into REUSE,
2323 cons up the rest of them and add them to the end of REUSE. */
2324 if (i < 2 * len + 2)
2325 XCDR (prev) = Flist (2 * len + 2 - i, data + i);
2326
2327 return reuse;
2302 } 2328 }
2303 2329
2304 2330
2305 DEFUN ("store-match-data", Fstore_match_data, 1, 1, 0, /* 2331 DEFUN ("store-match-data", Fstore_match_data, 1, 1, 0, /*
2306 Set internal data on last search match from elements of LIST. 2332 Set internal data on last search match from elements of LIST.
2425 DEFUN ("regexp-quote", Fregexp_quote, 1, 1, 0, /* 2451 DEFUN ("regexp-quote", Fregexp_quote, 1, 1, 0, /*
2426 Return a regexp string which matches exactly STRING and nothing else. 2452 Return a regexp string which matches exactly STRING and nothing else.
2427 */ 2453 */
2428 (str)) 2454 (str))
2429 { 2455 {
2430 /* This function has been Mule-ized. */
2431 REGISTER Bufbyte *in, *out, *end; 2456 REGISTER Bufbyte *in, *out, *end;
2432 REGISTER Bufbyte *temp; 2457 REGISTER Bufbyte *temp;
2433 2458
2434 CHECK_STRING (str); 2459 CHECK_STRING (str);
2435 2460
2439 2464
2440 in = XSTRING_DATA (str); 2465 in = XSTRING_DATA (str);
2441 end = in + XSTRING_LENGTH (str); 2466 end = in + XSTRING_LENGTH (str);
2442 out = temp; 2467 out = temp;
2443 2468
2444 for (; in != end; in++) 2469 while (in < end)
2445 { 2470 {
2446 if (*in == '[' || *in == ']' 2471 Emchar c = charptr_emchar (in);
2447 || *in == '*' || *in == '.' || *in == '\\' 2472
2448 || *in == '?' || *in == '+' 2473 if (c == '[' || c == ']'
2449 || *in == '^' || *in == '$') 2474 || c == '*' || c == '.' || c == '\\'
2475 || c == '?' || c == '+'
2476 || c == '^' || c == '$')
2450 *out++ = '\\'; 2477 *out++ = '\\';
2451 *out++ = *in; 2478 out += set_charptr_emchar (out, c);
2479 INC_CHARPTR (in);
2452 } 2480 }
2453 2481
2454 return make_string (temp, out - temp); 2482 return make_string (temp, out - temp);
2455 } 2483 }
2456 2484