2 * Copyright (C) 1984-2007 Mark Nudelman
4 * You may distribute under the terms of either the GNU General Public
5 * License or the Less License, as specified in the README file.
7 * For more information about less, or for information on how to
8 * contact the author, see the README file.
13 * Routines to search a file for a pattern.
20 #define MINPOS(a,b) (((a) < (b)) ? (a) : (b))
21 #define MAXPOS(a,b) (((a) > (b)) ? (a) : (b))
23 #if HAVE_POSIX_REGCOMP
26 #define REGCOMP_FLAG REG_EXTENDED
28 #define REGCOMP_FLAG 0
50 extern int how_search;
54 extern int jump_sline;
57 extern int status_col;
58 extern void * constant ml_search;
59 extern POSITION start_attnpos;
60 extern POSITION end_attnpos;
62 extern int hilite_search;
63 extern int screen_trashed;
64 extern int size_linebuf;
66 extern int can_goto_line;
67 static int hide_hilite;
69 static POSITION prep_startpos;
70 static POSITION prep_endpos;
74 struct hilite *hl_next;
78 static struct hilite hilite_anchor = { NULL, NULL_POSITION, NULL_POSITION };
79 #define hl_first hl_next
83 * These are the static variables that represent the "remembered"
86 #if HAVE_POSIX_REGCOMP
87 static regex_t *regpattern = NULL;
90 pcre *regpattern = NULL;
96 static char *cpattern = NULL;
99 static struct regexp *regpattern = NULL;
102 static int is_caseless;
103 static int is_ucase_pattern;
104 static int last_search_type;
105 static char *last_pattern = NULL;
108 * Convert text. Perform one or more of these transformations:
110 #define CVT_TO_LC 01 /* Convert upper-case to lower-case */
111 #define CVT_BS 02 /* Do backspace processing */
112 #define CVT_CRLF 04 /* Remove CR after LF */
113 #define CVT_ANSI 010 /* Remove ANSI escape sequences */
116 cvt_text(odst, osrc, lenp, ops)
124 register char *src_end;
128 src_end = osrc + *lenp;
130 src_end = osrc + strlen(osrc);
132 for (src = osrc, dst = odst; src < src_end; )
134 ch = step_char(&src, +1, src_end);
135 if ((ops & CVT_TO_LC) && IS_UPPER(ch))
137 /* Convert uppercase to lowercase. */
138 put_wchar(&dst, TO_LOWER(ch));
139 } else if ((ops & CVT_BS) && ch == '\b' && dst > odst)
141 /* Delete BS and preceding char. */
144 } while (dst > odst &&
145 !IS_ASCII_OCTET(*dst) && !IS_UTF8_LEAD(*dst));
146 } else if ((ops & CVT_ANSI) && IS_CSI_START(ch))
148 /* Skip to end of ANSI escape sequence. */
149 while (src + 1 != src_end)
150 if (!is_ansi_middle(*++src))
156 if ((ops & CVT_CRLF) && dst > odst && dst[-1] == '\r')
164 * Determine which conversions to perform.
170 if (is_caseless || bs_mode == BS_SPECIAL)
174 if (bs_mode == BS_SPECIAL)
176 if (bs_mode != BS_CONTROL)
178 } else if (bs_mode != BS_CONTROL)
182 if (ctldisp == OPT_ONPLUS)
188 * Are there any uppercase letters in this string?
194 char *str_end = str + strlen(str);
197 while (str < str_end)
199 ch = step_char(&str, +1, str_end);
207 * Is there a previous (remembered) search pattern?
212 if (last_search_type & SRCH_NO_REGEX)
213 return (last_pattern != NULL);
214 #if HAVE_POSIX_REGCOMP
215 return (regpattern != NULL);
218 return (regpattern != NULL);
221 return (re_pattern != 0);
224 return (cpattern != NULL);
227 return (regpattern != NULL);
230 return (last_pattern != NULL);
236 * Repaint the hilites currently displayed on the screen.
237 * Repaint each line which contains highlighted text.
238 * If on==0, force all hilites off.
247 int save_hide_hilite;
252 save_hide_hilite = hide_hilite;
263 hide_hilite = save_hide_hilite;
267 for (slinenum = TOP; slinenum < TOP + sc_height-1; slinenum++)
269 pos = position(slinenum);
270 if (pos == NULL_POSITION)
272 epos = position(slinenum+1);
275 * If any character in the line is highlighted,
278 * {{ This doesn't work -- if line is drawn with highlights
279 * which should be erased (e.g. toggle -i with status column),
280 * we must redraw the line even if it has no highlights.
281 * For now, just repaint every line. }}
283 if (is_hilited(pos, epos, 1, NULL))
286 (void) forw_line(pos);
293 hide_hilite = save_hide_hilite;
297 * Clear the attn hilite.
303 POSITION old_start_attnpos;
304 POSITION old_end_attnpos;
309 if (start_attnpos == NULL_POSITION)
311 old_start_attnpos = start_attnpos;
312 old_end_attnpos = end_attnpos;
313 start_attnpos = end_attnpos = NULL_POSITION;
323 for (slinenum = TOP; slinenum < TOP + sc_height-1; slinenum++)
325 pos = position(slinenum);
326 if (pos == NULL_POSITION)
328 epos = position(slinenum+1);
329 if (pos < old_end_attnpos &&
330 (epos == NULL_POSITION || epos > old_start_attnpos))
332 (void) forw_line(pos);
344 * Hide search string highlighting.
351 error("No previous regular expression", NULL_PARG);
355 hide_hilite = !hide_hilite;
361 * Compile a search pattern, for future use by match_pattern.
364 compile_pattern(pattern, search_type)
368 if ((search_type & SRCH_NO_REGEX) == 0)
370 #if HAVE_POSIX_REGCOMP
371 regex_t *s = (regex_t *) ecalloc(1, sizeof(regex_t));
372 if (regcomp(s, pattern, REGCOMP_FLAG))
375 error("Invalid pattern", NULL_PARG);
378 if (regpattern != NULL)
384 const char *errstring;
387 comp = pcre_compile(pattern, 0,
388 &errstring, &erroffset, NULL);
391 parg.p_string = (char *) errstring;
399 if ((parg.p_string = re_comp(pattern)) != NULL)
408 if ((s = regcmp(pattern, 0)) == NULL)
410 error("Invalid pattern", NULL_PARG);
413 if (cpattern != NULL)
419 if ((s = regcomp(pattern)) == NULL)
422 * regcomp has already printed an error message
427 if (regpattern != NULL)
433 if (last_pattern != NULL)
435 last_pattern = (char *) calloc(1, strlen(pattern)+1);
436 if (last_pattern != NULL)
437 strcpy(last_pattern, pattern);
439 last_search_type = search_type;
444 * Forget that we have a compiled pattern.
449 #if HAVE_POSIX_REGCOMP
450 if (regpattern != NULL)
455 if (regpattern != NULL)
456 pcre_free(regpattern);
463 if (cpattern != NULL)
468 if (regpattern != NULL)
476 * Perform a pattern match with the previously compiled pattern.
477 * Set sp and ep to the start and end of the matched string.
480 match_pattern(line, line_len, sp, ep, notbol)
489 if (last_search_type & SRCH_NO_REGEX)
490 return (match(last_pattern, strlen(last_pattern), line, line_len, sp, ep));
492 #if HAVE_POSIX_REGCOMP
495 int flags = (notbol) ? REG_NOTBOL : 0;
496 matched = !regexec(regpattern, line, 1, &rm, flags);
500 *sp = line + rm.rm_so;
501 *ep = line + rm.rm_eo;
510 int flags = (notbol) ? PCRE_NOTBOL : 0;
512 matched = pcre_exec(regpattern, NULL, line, line_len,
513 0, flags, ovector, 3) >= 0;
516 *sp = line + ovector[0];
517 *ep = line + ovector[1];
521 matched = (re_exec(line) == 1);
523 * re_exec doesn't seem to provide a way to get the matched string.
528 *ep = regex(cpattern, line);
529 matched = (*ep != NULL);
536 matched = regexec2(regpattern, line, notbol);
538 matched = regexec(regpattern, line);
542 *sp = regpattern->startp[0];
543 *ep = regpattern->endp[0];
546 matched = match(last_pattern, strlen(last_pattern), line, line_len, sp, ep);
553 * Clear the hilite list.
559 struct hilite *nexthl;
561 for (hl = hilite_anchor.hl_first; hl != NULL; hl = nexthl)
563 nexthl = hl->hl_next;
566 hilite_anchor.hl_first = NULL;
567 prep_startpos = prep_endpos = NULL_POSITION;
571 * Should any characters in a specified range be highlighted?
574 is_hilited_range(pos, epos)
581 * Look at each highlight and see if any part of it falls in the range.
583 for (hl = hilite_anchor.hl_first; hl != NULL; hl = hl->hl_next)
585 if (hl->hl_endpos > pos &&
586 (epos == NULL_POSITION || epos > hl->hl_startpos))
593 * Should any characters in a specified range be highlighted?
594 * If nohide is nonzero, don't consider hide_hilite.
597 is_hilited(pos, epos, nohide, p_matches)
605 if (p_matches != NULL)
609 start_attnpos != NULL_POSITION &&
611 (epos == NULL_POSITION || epos > start_attnpos))
613 * The attn line overlaps this range.
617 match = is_hilited_range(pos, epos);
621 if (p_matches != NULL)
623 * Report matches, even if we're hiding highlights.
627 if (hilite_search == 0)
629 * Not doing highlighting.
633 if (!nohide && hide_hilite)
635 * Highlighting is hidden.
643 * Add a new hilite to a hilite list.
646 add_hilite(anchor, hl)
647 struct hilite *anchor;
653 * Hilites are sorted in the list; find where new one belongs.
654 * Insert new one after ihl.
656 for (ihl = anchor; ihl->hl_next != NULL; ihl = ihl->hl_next)
658 if (ihl->hl_next->hl_startpos > hl->hl_startpos)
663 * Truncate hilite so it doesn't overlap any existing ones
664 * above and below it.
667 hl->hl_startpos = MAXPOS(hl->hl_startpos, ihl->hl_endpos);
668 if (ihl->hl_next != NULL)
669 hl->hl_endpos = MINPOS(hl->hl_endpos, ihl->hl_next->hl_startpos);
670 if (hl->hl_startpos >= hl->hl_endpos)
673 * Hilite was truncated out of existence.
678 hl->hl_next = ihl->hl_next;
683 adj_hilite_ansi(cvt_ops, line, line_len, npos)
689 char *line_end = *line + line_len;
691 if (cvt_ops & CVT_ANSI)
692 while (IS_CSI_START(**line))
695 * Found an ESC. The file position moves
696 * forward past the entire ANSI escape sequence.
700 while (*line < line_end)
703 if (!is_ansi_middle(*(*line)++))
710 * Adjust hl_startpos & hl_endpos to account for backspace processing.
713 adj_hilite(anchor, linepos, cvt_ops)
714 struct hilite *anchor;
727 * The line was already scanned and hilites were added (in hilite_line).
728 * But it was assumed that each char position in the line
729 * correponds to one char position in the file.
730 * This may not be true if there are backspaces in the line.
731 * Get the raw line again. Look at each character.
733 (void) forw_raw_line(linepos, &line, &line_len);
734 line_end = line + line_len;
735 opos = npos = linepos;
736 hl = anchor->hl_first;
741 * See if we need to adjust the current hl_startpos or
742 * hl_endpos. After adjusting startpos[i], move to endpos[i].
743 * After adjusting endpos[i], move to startpos[i+1].
744 * The hilite list must be sorted thus:
745 * startpos[0] < endpos[0] <= startpos[1] < endpos[1] <= etc.
747 if (checkstart && hl->hl_startpos == opos)
749 hl->hl_startpos = npos;
751 continue; /* {{ not really necessary }} */
752 } else if (!checkstart && hl->hl_endpos == opos)
754 hl->hl_endpos = npos;
757 continue; /* {{ necessary }} */
759 if (line == line_end)
761 adj_hilite_ansi(cvt_ops, &line, line_end - line, &npos);
765 if (cvt_ops & CVT_BS)
767 while (*line == '\b')
771 adj_hilite_ansi(cvt_ops, &line, line_end - line, &npos);
772 if (line == line_end)
779 * Found a backspace. The file position moves
780 * forward by 2 relative to the processed line
781 * which was searched in hilite_line.
791 * Make a hilite for each string in a physical line which matches
792 * the current pattern.
793 * sp,ep delimit the first match already found.
796 hilite_line(linepos, line, line_len, sp, ep, cvt_ops)
805 char *line_end = line + line_len;
807 struct hilite hilites;
809 if (sp == NULL || ep == NULL)
812 * sp and ep delimit the first match in the line.
813 * Mark the corresponding file positions, then
814 * look for further matches and mark them.
815 * {{ This technique, of calling match_pattern on subsequent
816 * substrings of the line, may mark more than is correct
817 * if the pattern starts with "^". This bug is fixed
818 * for those regex functions that accept a notbol parameter
819 * (currently POSIX, PCRE and V8-with-regexec2). }}
823 * Put the hilites into a temporary list until they're adjusted.
825 hilites.hl_first = NULL;
830 * Assume that each char position in the "line"
831 * buffer corresponds to one char position in the file.
832 * This is not quite true; we need to adjust later.
834 hl = (struct hilite *) ecalloc(1, sizeof(struct hilite));
835 hl->hl_startpos = linepos + (sp-line);
836 hl->hl_endpos = linepos + (ep-line);
837 add_hilite(&hilites, hl);
840 * If we matched more than zero characters,
841 * move to the first char after the string we matched.
842 * If we matched zero, just move to the next char.
846 else if (searchp != line_end)
848 else /* end of line */
850 } while (match_pattern(searchp, line_end - searchp, &sp, &ep, 1));
853 * If there were backspaces in the original line, they
854 * were removed, and hl_startpos/hl_endpos are not correct.
855 * {{ This is very ugly. }}
857 adj_hilite(&hilites, linepos, cvt_ops);
860 * Now put the hilites into the real list.
862 while ((hl = hilites.hl_next) != NULL)
864 hilites.hl_next = hl->hl_next;
865 add_hilite(&hilite_anchor, hl);
871 * Change the caseless-ness of searches.
872 * Updates the internal search state to reflect a change in the -i flag.
877 if (!is_ucase_pattern)
879 * Pattern did not have uppercase.
880 * Just set the search caselessness to the global caselessness.
882 is_caseless = caseless;
885 * Pattern did have uppercase.
886 * Discard the pattern; we can't change search caselessness now.
893 * Find matching text which is currently on screen and highlight it.
898 struct scrpos scrpos;
901 if (scrpos.pos == NULL_POSITION)
903 prep_hilite(scrpos.pos, position(BOTTOM_PLUS_ONE), -1);
908 * Change highlighting parameters.
914 * Erase any highlights currently on screen.
919 if (hilite_search == OPT_ONPLUS)
921 * Display highlights.
928 * Figure out where to start a search.
931 search_pos(search_type)
940 * Start at the beginning (or end) of the file.
941 * The empty_screen() case is mainly for
942 * command line initiated searches;
943 * for example, "+/xyz" on the command line.
944 * Also for multi-file (SRCH_PAST_EOF) searches.
946 if (search_type & SRCH_FORW)
952 if (pos == NULL_POSITION)
954 (void) ch_end_seek();
963 * Search does not include current screen.
965 if (search_type & SRCH_FORW)
966 linenum = BOTTOM_PLUS_ONE;
969 pos = position(linenum);
973 * Search includes current screen.
974 * It starts at the jump target (if searching backwards),
975 * or at the jump target plus one (if forwards).
977 linenum = adjsline(jump_sline);
978 pos = position(linenum);
979 if (search_type & SRCH_FORW)
981 pos = forw_raw_line(pos, (char **)NULL, (int *)NULL);
982 while (pos == NULL_POSITION)
984 if (++linenum >= sc_height)
986 pos = position(linenum);
990 while (pos == NULL_POSITION)
994 pos = position(linenum);
1002 * Search a subset of the file, specified by start/end position.
1005 search_range(pos, endpos, search_type, matches, maxlines, plinepos, pendpos)
1020 POSITION linepos, oldpos;
1022 linenum = find_linenum(pos);
1027 * Get lines until we find a matching one or until
1028 * we hit end-of-file (or beginning-of-file if we're
1029 * going backwards), or until we hit the end position.
1034 * A signal aborts the search.
1039 if ((endpos != NULL_POSITION && pos >= endpos) || maxlines == 0)
1042 * Reached end position without a match.
1044 if (pendpos != NULL)
1051 if (search_type & SRCH_FORW)
1054 * Read the next line, and save the
1055 * starting position of that line in linepos.
1058 pos = forw_raw_line(pos, &line, &line_len);
1064 * Read the previous line and save the
1065 * starting position of that line in linepos.
1067 pos = back_raw_line(pos, &line, &line_len);
1073 if (pos == NULL_POSITION)
1076 * Reached EOF/BOF without a match.
1078 if (pendpos != NULL)
1084 * If we're using line numbers, we might as well
1085 * remember the information we have now (the position
1086 * and line number of the current line).
1087 * Don't do it for every line because it slows down
1088 * the search. Remember the line number only if
1089 * we're "far" from the last place we remembered it.
1091 if (linenums && abs((int)(pos - oldpos)) > 1024)
1092 add_lnum(linenum, pos);
1096 * If it's a caseless search, convert the line to lowercase.
1097 * If we're doing backspace processing, delete backspaces.
1099 cvt_ops = get_cvt_ops();
1100 cvt_text(line, line, &line_len, cvt_ops);
1103 * Test the next line to see if we have a match.
1104 * We are successful if we either want a match and got one,
1105 * or if we want a non-match and got one.
1107 line_match = match_pattern(line, line_len, &sp, &ep, 0);
1108 line_match = (!(search_type & SRCH_NO_MATCH) && line_match) ||
1109 ((search_type & SRCH_NO_MATCH) && !line_match);
1115 if (search_type & SRCH_FIND_ALL)
1119 * We are supposed to find all matches in the range.
1120 * Just add the matches in this line to the
1121 * hilite list and keep searching.
1124 hilite_line(linepos, line, line_len, sp, ep, cvt_ops);
1126 } else if (--matches <= 0)
1129 * Found the one match we're looking for.
1133 if (hilite_search == OPT_ON)
1136 * Clear the hilite list and add only
1137 * the matches in this one line.
1141 hilite_line(linepos, line, line_len, sp, ep, cvt_ops);
1144 if (plinepos != NULL)
1145 *plinepos = linepos;
1152 * search for a pattern in history. If found, compile that pattern.
1155 hist_pattern(search_type)
1161 set_mlist(ml_search, 0);
1162 pattern = cmd_lastpattern();
1163 if (pattern == NULL)
1166 if (caseless == OPT_ONPLUS)
1167 cvt_text(pattern, pattern, (int *)NULL, CVT_TO_LC);
1169 if (compile_pattern(pattern, search_type) < 0)
1172 is_ucase_pattern = is_ucase(pattern);
1173 if (is_ucase_pattern && caseless != OPT_ONPLUS)
1176 is_caseless = caseless;
1179 if (hilite_search == OPT_ONPLUS && !hide_hilite)
1184 #else /* CMD_HISTORY */
1186 #endif /* CMD_HISTORY */
1190 * Search for the n-th occurrence of a specified pattern,
1191 * either forward or backward.
1192 * Return the number of matches not yet found in this file
1193 * (that is, n minus the number of matches found).
1194 * Return -1 if the search should be aborted.
1195 * Caller may continue the search in another file
1196 * if less than n matches are found in this file.
1199 search(search_type, pattern, n)
1207 if (pattern == NULL || *pattern == '\0')
1210 * A null pattern means use the previously compiled pattern.
1212 if (!prev_pattern() && !hist_pattern(search_type))
1214 error("No previous regular expression", NULL_PARG);
1217 if ((search_type & SRCH_NO_REGEX) !=
1218 (last_search_type & SRCH_NO_REGEX))
1220 error("Please re-enter search pattern", NULL_PARG);
1224 if (hilite_search == OPT_ON)
1227 * Erase the highlights currently on screen.
1228 * If the search fails, we'll redisplay them later.
1232 if (hilite_search == OPT_ONPLUS && hide_hilite)
1235 * Highlight any matches currently on screen,
1236 * before we actually start the search.
1246 * Compile the pattern.
1248 ucase = is_ucase(pattern);
1249 if (caseless == OPT_ONPLUS)
1250 cvt_text(pattern, pattern, (int *)NULL, CVT_TO_LC);
1251 if (compile_pattern(pattern, search_type) < 0)
1254 * Ignore case if -I is set OR
1255 * -i is set AND the pattern is all lowercase.
1257 is_ucase_pattern = ucase;
1258 if (is_ucase_pattern && caseless != OPT_ONPLUS)
1261 is_caseless = caseless;
1266 * Erase the highlights currently on screen.
1267 * Also permanently delete them from the hilite list.
1273 if (hilite_search == OPT_ONPLUS)
1276 * Highlight any matches currently on screen,
1277 * before we actually start the search.
1285 * Figure out where to start the search.
1287 pos = search_pos(search_type);
1288 if (pos == NULL_POSITION)
1291 * Can't find anyplace to start searching from.
1293 if (search_type & SRCH_PAST_EOF)
1295 /* repaint(); -- why was this here? */
1296 error("Nothing to search", NULL_PARG);
1300 n = search_range(pos, NULL_POSITION, search_type, n, -1,
1301 &pos, (POSITION*)NULL);
1305 * Search was unsuccessful.
1308 if (hilite_search == OPT_ON && n > 0)
1310 * Redisplay old hilites.
1317 if (!(search_type & SRCH_NO_MOVE))
1320 * Go to the matching line.
1322 jump_loc(pos, jump_sline);
1326 if (hilite_search == OPT_ON)
1328 * Display new hilites in the matching line.
1338 * Prepare hilites in a given range of the file.
1340 * The pair (prep_startpos,prep_endpos) delimits a contiguous region
1341 * of the file that has been "prepared"; that is, scanned for matches for
1342 * the current search pattern, and hilites have been created for such matches.
1343 * If prep_startpos == NULL_POSITION, the prep region is empty.
1344 * If prep_endpos == NULL_POSITION, the prep region extends to EOF.
1345 * prep_hilite asks that the range (spos,epos) be covered by the prep region.
1348 prep_hilite(spos, epos, maxlines)
1353 POSITION nprep_startpos = prep_startpos;
1354 POSITION nprep_endpos = prep_endpos;
1360 * Search beyond where we're asked to search, so the prep region covers
1361 * more than we need. Do one big search instead of a bunch of small ones.
1363 #define SEARCH_MORE (3*size_linebuf)
1365 if (!prev_pattern())
1369 * If we're limited to a max number of lines, figure out the
1370 * file position we should stop at.
1373 max_epos = NULL_POSITION;
1377 for (i = 0; i < maxlines; i++)
1378 max_epos = forw_raw_line(max_epos, (char **)NULL, (int *)NULL);
1383 * The range that we need to search (spos,epos); and the range that
1384 * the "prep" region will then cover (nprep_startpos,nprep_endpos).
1387 if (prep_startpos == NULL_POSITION ||
1388 (epos != NULL_POSITION && epos < prep_startpos) ||
1392 * New range is not contiguous with old prep region.
1393 * Discard the old prep region and start a new one.
1396 if (epos != NULL_POSITION)
1397 epos += SEARCH_MORE;
1398 nprep_startpos = spos;
1402 * New range partially or completely overlaps old prep region.
1404 if (epos == NULL_POSITION)
1407 * New range goes to end of file.
1410 } else if (epos > prep_endpos)
1413 * New range ends after old prep region.
1414 * Extend prep region to end at end of new range.
1416 epos += SEARCH_MORE;
1417 } else /* (epos <= prep_endpos) */
1420 * New range ends within old prep region.
1421 * Truncate search to end at start of old prep region.
1423 epos = prep_startpos;
1426 if (spos < prep_startpos)
1429 * New range starts before old prep region.
1430 * Extend old prep region backwards to start at
1431 * start of new range.
1433 if (spos < SEARCH_MORE)
1436 spos -= SEARCH_MORE;
1437 nprep_startpos = spos;
1438 } else /* (spos >= prep_startpos) */
1441 * New range starts within or after old prep region.
1442 * Trim search to start at end of old prep region.
1448 if (epos != NULL_POSITION && max_epos != NULL_POSITION &&
1451 * Don't go past the max position we're allowed.
1455 if (epos == NULL_POSITION || epos > spos)
1457 result = search_range(spos, epos, SRCH_FORW|SRCH_FIND_ALL, 0,
1458 maxlines, (POSITION*)NULL, &new_epos);
1461 if (prep_endpos == NULL_POSITION || new_epos > prep_endpos)
1462 nprep_endpos = new_epos;
1464 prep_startpos = nprep_startpos;
1465 prep_endpos = nprep_endpos;
1470 * Simple pattern matching function.
1471 * It supports no metacharacters like *, etc.
1474 match(pattern, pattern_len, buf, buf_len, pfound, pend)
1479 char **pfound, **pend;
1481 register char *pp, *lp;
1482 register char *pattern_end = pattern + pattern_len;
1483 register char *buf_end = buf + buf_len;
1485 for ( ; buf < buf_end; buf++)
1487 for (pp = pattern, lp = buf; *pp == *lp; pp++, lp++)
1488 if (pp == pattern_end || lp == buf_end)
1490 if (pp == pattern_end)
1504 * This function is called by the V8 regcomp to report
1505 * errors in regular expressions.