diff options
| author | Paul Eggert | 2012-05-25 11:19:24 -0700 |
|---|---|---|
| committer | Paul Eggert | 2012-05-25 11:19:24 -0700 |
| commit | 42b2a986d9d4b7040fb20c90ec0efeffb78e761a (patch) | |
| tree | d38e7bf5307837f2f38982757f088100de18a64e /src/search.c | |
| parent | e4d81efc58695c19154d5f6733d91172b4c3e5b7 (diff) | |
| parent | a8d3cbf75d219d7a249fc0623219511179e959da (diff) | |
| download | emacs-42b2a986d9d4b7040fb20c90ec0efeffb78e761a.tar.gz emacs-42b2a986d9d4b7040fb20c90ec0efeffb78e761a.zip | |
Merge from trunk.
Diffstat (limited to 'src/search.c')
| -rw-r--r-- | src/search.c | 191 |
1 files changed, 0 insertions, 191 deletions
diff --git a/src/search.c b/src/search.c index 503720b70ab..a9542a2ed97 100644 --- a/src/search.c +++ b/src/search.c | |||
| @@ -2079,112 +2079,6 @@ set_search_regs (ptrdiff_t beg_byte, ptrdiff_t nbytes) | |||
| 2079 | XSETBUFFER (last_thing_searched, current_buffer); | 2079 | XSETBUFFER (last_thing_searched, current_buffer); |
| 2080 | } | 2080 | } |
| 2081 | 2081 | ||
| 2082 | DEFUN ("word-search-regexp", Fword_search_regexp, Sword_search_regexp, 1, 2, 0, | ||
| 2083 | doc: /* Return a regexp which matches words, ignoring punctuation. | ||
| 2084 | Given STRING, a string of words separated by word delimiters, | ||
| 2085 | compute a regexp that matches those exact words separated by | ||
| 2086 | arbitrary punctuation. If LAX is non-nil, the end of the string | ||
| 2087 | need not match a word boundary unless it ends in whitespace. | ||
| 2088 | |||
| 2089 | Used in `word-search-forward', `word-search-backward', | ||
| 2090 | `word-search-forward-lax', `word-search-backward-lax'. */) | ||
| 2091 | (Lisp_Object string, Lisp_Object lax) | ||
| 2092 | { | ||
| 2093 | register unsigned char *o; | ||
| 2094 | register ptrdiff_t i, i_byte, len, punct_count = 0, word_count = 0; | ||
| 2095 | Lisp_Object val; | ||
| 2096 | int prev_c = 0; | ||
| 2097 | EMACS_INT adjust; | ||
| 2098 | int whitespace_at_end; | ||
| 2099 | |||
| 2100 | CHECK_STRING (string); | ||
| 2101 | len = SCHARS (string); | ||
| 2102 | |||
| 2103 | for (i = 0, i_byte = 0; i < len; ) | ||
| 2104 | { | ||
| 2105 | int c; | ||
| 2106 | |||
| 2107 | FETCH_STRING_CHAR_AS_MULTIBYTE_ADVANCE (c, string, i, i_byte); | ||
| 2108 | |||
| 2109 | if (SYNTAX (c) != Sword) | ||
| 2110 | { | ||
| 2111 | punct_count++; | ||
| 2112 | if (SYNTAX (prev_c) == Sword) | ||
| 2113 | word_count++; | ||
| 2114 | } | ||
| 2115 | |||
| 2116 | prev_c = c; | ||
| 2117 | } | ||
| 2118 | |||
| 2119 | if (SYNTAX (prev_c) == Sword) | ||
| 2120 | { | ||
| 2121 | word_count++; | ||
| 2122 | whitespace_at_end = 0; | ||
| 2123 | } | ||
| 2124 | else | ||
| 2125 | { | ||
| 2126 | whitespace_at_end = 1; | ||
| 2127 | if (!word_count) | ||
| 2128 | return empty_unibyte_string; | ||
| 2129 | } | ||
| 2130 | |||
| 2131 | adjust = word_count - 1; | ||
| 2132 | if (TYPE_MAXIMUM (EMACS_INT) / 5 < adjust) | ||
| 2133 | memory_full (SIZE_MAX); | ||
| 2134 | adjust = - punct_count + 5 * adjust | ||
| 2135 | + ((!NILP (lax) && !whitespace_at_end) ? 2 : 4); | ||
| 2136 | if (STRING_MULTIBYTE (string)) | ||
| 2137 | { | ||
| 2138 | if (INT_ADD_OVERFLOW (SBYTES (string), adjust)) | ||
| 2139 | memory_full (SIZE_MAX); | ||
| 2140 | val = make_uninit_multibyte_string (len + adjust, | ||
| 2141 | SBYTES (string) + adjust); | ||
| 2142 | } | ||
| 2143 | else | ||
| 2144 | { | ||
| 2145 | if (INT_ADD_OVERFLOW (len, adjust)) | ||
| 2146 | memory_full (SIZE_MAX); | ||
| 2147 | val = make_uninit_string (len + adjust); | ||
| 2148 | } | ||
| 2149 | |||
| 2150 | o = SDATA (val); | ||
| 2151 | *o++ = '\\'; | ||
| 2152 | *o++ = 'b'; | ||
| 2153 | prev_c = 0; | ||
| 2154 | |||
| 2155 | for (i = 0, i_byte = 0; i < len; ) | ||
| 2156 | { | ||
| 2157 | int c; | ||
| 2158 | ptrdiff_t i_byte_orig = i_byte; | ||
| 2159 | |||
| 2160 | FETCH_STRING_CHAR_AS_MULTIBYTE_ADVANCE (c, string, i, i_byte); | ||
| 2161 | |||
| 2162 | if (SYNTAX (c) == Sword) | ||
| 2163 | { | ||
| 2164 | memcpy (o, SDATA (string) + i_byte_orig, i_byte - i_byte_orig); | ||
| 2165 | o += i_byte - i_byte_orig; | ||
| 2166 | } | ||
| 2167 | else if (SYNTAX (prev_c) == Sword && --word_count) | ||
| 2168 | { | ||
| 2169 | *o++ = '\\'; | ||
| 2170 | *o++ = 'W'; | ||
| 2171 | *o++ = '\\'; | ||
| 2172 | *o++ = 'W'; | ||
| 2173 | *o++ = '*'; | ||
| 2174 | } | ||
| 2175 | |||
| 2176 | prev_c = c; | ||
| 2177 | } | ||
| 2178 | |||
| 2179 | if (NILP (lax) || whitespace_at_end) | ||
| 2180 | { | ||
| 2181 | *o++ = '\\'; | ||
| 2182 | *o++ = 'b'; | ||
| 2183 | } | ||
| 2184 | |||
| 2185 | return val; | ||
| 2186 | } | ||
| 2187 | |||
| 2188 | DEFUN ("search-backward", Fsearch_backward, Ssearch_backward, 1, 4, | 2082 | DEFUN ("search-backward", Fsearch_backward, Ssearch_backward, 1, 4, |
| 2189 | "MSearch backward: ", | 2083 | "MSearch backward: ", |
| 2190 | doc: /* Search backward from point for STRING. | 2084 | doc: /* Search backward from point for STRING. |
| @@ -2227,86 +2121,6 @@ See also the functions `match-beginning', `match-end' and `replace-match'. */) | |||
| 2227 | return search_command (string, bound, noerror, count, 1, 0, 0); | 2121 | return search_command (string, bound, noerror, count, 1, 0, 0); |
| 2228 | } | 2122 | } |
| 2229 | 2123 | ||
| 2230 | DEFUN ("word-search-backward", Fword_search_backward, Sword_search_backward, 1, 4, | ||
| 2231 | "sWord search backward: ", | ||
| 2232 | doc: /* Search backward from point for STRING, ignoring differences in punctuation. | ||
| 2233 | Set point to the beginning of the occurrence found, and return point. | ||
| 2234 | An optional second argument bounds the search; it is a buffer position. | ||
| 2235 | The match found must not extend before that position. | ||
| 2236 | Optional third argument, if t, means if fail just return nil (no error). | ||
| 2237 | If not nil and not t, move to limit of search and return nil. | ||
| 2238 | Optional fourth argument is repeat count--search for successive occurrences. | ||
| 2239 | |||
| 2240 | Relies on the function `word-search-regexp' to convert a sequence | ||
| 2241 | of words in STRING to a regexp used to search words without regard | ||
| 2242 | to punctuation. */) | ||
| 2243 | (Lisp_Object string, Lisp_Object bound, Lisp_Object noerror, Lisp_Object count) | ||
| 2244 | { | ||
| 2245 | return search_command (Fword_search_regexp (string, Qnil), bound, noerror, count, -1, 1, 0); | ||
| 2246 | } | ||
| 2247 | |||
| 2248 | DEFUN ("word-search-forward", Fword_search_forward, Sword_search_forward, 1, 4, | ||
| 2249 | "sWord search: ", | ||
| 2250 | doc: /* Search forward from point for STRING, ignoring differences in punctuation. | ||
| 2251 | Set point to the end of the occurrence found, and return point. | ||
| 2252 | An optional second argument bounds the search; it is a buffer position. | ||
| 2253 | The match found must not extend after that position. | ||
| 2254 | Optional third argument, if t, means if fail just return nil (no error). | ||
| 2255 | If not nil and not t, move to limit of search and return nil. | ||
| 2256 | Optional fourth argument is repeat count--search for successive occurrences. | ||
| 2257 | |||
| 2258 | Relies on the function `word-search-regexp' to convert a sequence | ||
| 2259 | of words in STRING to a regexp used to search words without regard | ||
| 2260 | to punctuation. */) | ||
| 2261 | (Lisp_Object string, Lisp_Object bound, Lisp_Object noerror, Lisp_Object count) | ||
| 2262 | { | ||
| 2263 | return search_command (Fword_search_regexp (string, Qnil), bound, noerror, count, 1, 1, 0); | ||
| 2264 | } | ||
| 2265 | |||
| 2266 | DEFUN ("word-search-backward-lax", Fword_search_backward_lax, Sword_search_backward_lax, 1, 4, | ||
| 2267 | "sWord search backward: ", | ||
| 2268 | doc: /* Search backward from point for STRING, ignoring differences in punctuation. | ||
| 2269 | Set point to the beginning of the occurrence found, and return point. | ||
| 2270 | |||
| 2271 | Unlike `word-search-backward', the end of STRING need not match a word | ||
| 2272 | boundary, unless STRING ends in whitespace. | ||
| 2273 | |||
| 2274 | An optional second argument bounds the search; it is a buffer position. | ||
| 2275 | The match found must not extend before that position. | ||
| 2276 | Optional third argument, if t, means if fail just return nil (no error). | ||
| 2277 | If not nil and not t, move to limit of search and return nil. | ||
| 2278 | Optional fourth argument is repeat count--search for successive occurrences. | ||
| 2279 | |||
| 2280 | Relies on the function `word-search-regexp' to convert a sequence | ||
| 2281 | of words in STRING to a regexp used to search words without regard | ||
| 2282 | to punctuation. */) | ||
| 2283 | (Lisp_Object string, Lisp_Object bound, Lisp_Object noerror, Lisp_Object count) | ||
| 2284 | { | ||
| 2285 | return search_command (Fword_search_regexp (string, Qt), bound, noerror, count, -1, 1, 0); | ||
| 2286 | } | ||
| 2287 | |||
| 2288 | DEFUN ("word-search-forward-lax", Fword_search_forward_lax, Sword_search_forward_lax, 1, 4, | ||
| 2289 | "sWord search: ", | ||
| 2290 | doc: /* Search forward from point for STRING, ignoring differences in punctuation. | ||
| 2291 | Set point to the end of the occurrence found, and return point. | ||
| 2292 | |||
| 2293 | Unlike `word-search-forward', the end of STRING need not match a word | ||
| 2294 | boundary, unless STRING ends in whitespace. | ||
| 2295 | |||
| 2296 | An optional second argument bounds the search; it is a buffer position. | ||
| 2297 | The match found must not extend after that position. | ||
| 2298 | Optional third argument, if t, means if fail just return nil (no error). | ||
| 2299 | If not nil and not t, move to limit of search and return nil. | ||
| 2300 | Optional fourth argument is repeat count--search for successive occurrences. | ||
| 2301 | |||
| 2302 | Relies on the function `word-search-regexp' to convert a sequence | ||
| 2303 | of words in STRING to a regexp used to search words without regard | ||
| 2304 | to punctuation. */) | ||
| 2305 | (Lisp_Object string, Lisp_Object bound, Lisp_Object noerror, Lisp_Object count) | ||
| 2306 | { | ||
| 2307 | return search_command (Fword_search_regexp (string, Qt), bound, noerror, count, 1, 1, 0); | ||
| 2308 | } | ||
| 2309 | |||
| 2310 | DEFUN ("re-search-backward", Fre_search_backward, Sre_search_backward, 1, 4, | 2124 | DEFUN ("re-search-backward", Fre_search_backward, Sre_search_backward, 1, 4, |
| 2311 | "sRE search backward: ", | 2125 | "sRE search backward: ", |
| 2312 | doc: /* Search backward from point for match for regular expression REGEXP. | 2126 | doc: /* Search backward from point for match for regular expression REGEXP. |
| @@ -3277,11 +3091,6 @@ is to bind it with `let' around a small expression. */); | |||
| 3277 | defsubr (&Sposix_string_match); | 3091 | defsubr (&Sposix_string_match); |
| 3278 | defsubr (&Ssearch_forward); | 3092 | defsubr (&Ssearch_forward); |
| 3279 | defsubr (&Ssearch_backward); | 3093 | defsubr (&Ssearch_backward); |
| 3280 | defsubr (&Sword_search_regexp); | ||
| 3281 | defsubr (&Sword_search_forward); | ||
| 3282 | defsubr (&Sword_search_backward); | ||
| 3283 | defsubr (&Sword_search_forward_lax); | ||
| 3284 | defsubr (&Sword_search_backward_lax); | ||
| 3285 | defsubr (&Sre_search_forward); | 3094 | defsubr (&Sre_search_forward); |
| 3286 | defsubr (&Sre_search_backward); | 3095 | defsubr (&Sre_search_backward); |
| 3287 | defsubr (&Sposix_search_forward); | 3096 | defsubr (&Sposix_search_forward); |