Anonymous avatar Anonymous committed 961a97d

2002-03-25 Ville Skyttä <ville.skytta@xemacs.org>;

* regexp-opt.el: Partial synch with GNU Emacs 21.2.
(regexp-opt): Handle PAREN with value 'words.
(regexp-opt-group): Return empty string if STRINGS is empty.

Comments (0)

Files changed (3)

+2002-03-25  Ville Skyttä  <ville.skytta@xemacs.org>
+
+	* regexp-opt.el: Partial synch with GNU Emacs 21.2.
+	(regexp-opt): Handle PAREN with value 'words.
+	(regexp-opt-group): Return empty string if STRINGS is empty.
+
+2002-03-26  Steve Youngs  <youngs@xemacs.org>
+
+	* Makefile (VERSION): 1.60 released.
+
 2002-03-14  David A. Panariti  <panariti@attbi.com>
 
 	* comint.el (comint-strip-ctrl-m):
 # the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 # Boston, MA 02111-1307, USA.
 
-VERSION = 1.59
+VERSION = 1.60
 AUTHOR_VERSION =
 MAINTAINER = XEmacs Development Team <xemacs-beta@xemacs.org>
 PACKAGE = xemacs-base
-;;; regexp-opt.el --- generate efficient regexps to match strings.
+;;; regexp-opt.el --- generate efficient regexps to match strings
 
-;; Copyright (C) 1994, 1995, 1996, 1997 Free Software Foundation, Inc.
+;; Copyright (C) 1994,95,96,97,98,99,2000 Free Software Foundation, Inc.
 
-;; Author: Simon Marshall <simon@gnu.ai.mit.edu>
-;; Keywords: strings, regexps
+;; Author: Simon Marshall <simon@gnu.org>
+;; Maintainer: FSF
+;; Keywords: strings, regexps, extensions
 
 ;; Modified by Karl M. Hegbloom Sep. 1997 to support the new regexp syntax
 ;; with shy groups. (benchmarks pending)
 (defun regexp-opt (strings &optional paren non-shy)
   "Return a regexp to match a string in STRINGS.
 Each string should be unique in STRINGS and should not contain any regexps,
-quoted or not. If optional PAREN is non-nil, ensure that the returned
-regexp is enclosed by at least one regexp match grouping construct.  If
-optional NON-SHY is non nil, the inner groupings will use \"\\\\( \\\\)\" grouping,
+quoted or not.  If optional PAREN is non-nil, ensure that the returned regexp
+is enclosed by at least one regexp match grouping construct.  If optional
+NON-SHY is non nil, the inner groupings will use \"\\\\( \\\\)\" grouping,
 rather than the default \"\\\\(?: \\\\)\" 'shy', or non-match-capturing groups.
 The returned regexp is typically more efficient than the equivalent regexp:
 
    (concat open-paren (mapconcat 'regexp-quote STRINGS \"\\\\|\") close-paren))
 
 but typically contains more regexp grouping constructs.
-Use `regexp-opt-depth' to count them."
+Use `regexp-opt-depth' to count them.
+
+If PAREN is `words', then the resulting regexp is additionally surrounded
+by \\=\\< and \\>."
   (save-match-data
     ;; Recurse on the sorted list.
-    (let ((max-lisp-eval-depth (* 1024 1024))
-	  (completion-ignore-case nil))
-      (regexp-opt-group (sort (copy-sequence strings) 'string-lessp) paren nil non-shy))))
+    (let* ((max-lisp-eval-depth (* 1024 1024))
+	   (completion-ignore-case nil)
+	   (words (eq paren 'words))
+	   (sorted-strings (sort (copy-sequence strings) 'string-lessp))
+	   (re (regexp-opt-group sorted-strings paren nil non-shy)))
+      (if words (concat "\\<" re "\\>") re))))
 
 ;;;###autoload
 (defun regexp-opt-depth (regexp &optional count-shy-groups-too)
   "Return the depth of REGEXP.
-This means the number of regexp grouping constructs (parenthesised expressions)
-in REGEXP, not counting the \"\\\\(?: \\\\)\" non-match-capturing groups unless
-COUNT-SHY-GROUPS-TOO is non-nil.
+This means the number of regexp grouping constructs (parenthesised
+expressions) in REGEXP, not counting the \"\\\\(?: \\\\)\"
+non-match-capturing groups unless COUNT-SHY-GROUPS-TOO is non-nil.
 See `regexp-opt'."
   (save-match-data
     ;; Hack to signal an error if REGEXP does not have balanced parentheses.
   (defalias 'make-bool-vector 'make-vector))
 
 (defun regexp-opt-group (strings &optional paren lax non-shy)
-  ;;
-  ;; Return a regexp to match a string in STRINGS.
-  ;; If PAREN non-nil, output regexp parentheses around returned regexp.
-  ;; If LAX non-nil, don't output parentheses if it doesn't require them.
-  ;; If NON-SHY non-nil, don't use \\(?: \\) shy groups, use match capturing ones.
-  ;; Merges keywords to avoid backtracking in Emacs' regexp matcher.
-  ;;
-  ;; The basic idea is to find the shortest common prefix, remove it and
-  ;; recurse.  If there is no prefix, we divide the list into two so that (at
-  ;; least) one half will have at least a one-character common prefix.
-  ;;
-  ;; Also we delay the addition of grouping parenthesis as long as possible
-  ;; until we're sure we need them, and try to remove one-character sequences
-  ;; so we can use character sets rather than grouping parenthesis.
-  ;;
+  "Return a regexp to match a string in STRINGS.
+If PAREN non-nil, output regexp parentheses around returned regexp.
+If LAX non-nil, don't output parentheses if it doesn't require them.
+If NON-SHY non-nil, don't use \\(?: \\) shy groups, use match capturing ones.
+Merges keywords to avoid backtracking in Emacs' regexp matcher.
+
+The basic idea is to find the shortest common prefix, remove it
+and recurse.  If there is no prefix, we divide the list into two so that
+\(at least) one half will have at least a one-character common prefix.
+
+Also we delay the addition of grouping parenthesis as long as possible
+until we're sure we need them, and try to remove one-character sequences
+so we can use character sets rather than grouping parenthesis."
   (let* ((open-group (cond
                        ((and paren non-shy) "\\(")
                        (paren "\\(?:")
 	 (close-charset (if lax "" close-group)))
     (cond
      ;;
+     ;; If there are no strings, just return the empty string.
+     ((= (length strings) 0)
+      "")
+     ;;
      ;; If there is only one string, just return it.
      ((= (length strings) 1)
       (if (= (length (car strings)) 1)
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.