comparison lisp/subr.el @ 414:da8ed4261e83 r21-2-15

Import from CVS: tag r21-2-15
author cvs
date Mon, 13 Aug 2007 11:21:38 +0200
parents 697ef44129c6
children ebe98a74bd68
comparison
equal deleted inserted replaced
413:901169e5ca31 414:da8ed4261e83
292 (defun split-string (string &optional pattern) 292 (defun split-string (string &optional pattern)
293 "Return a list of substrings of STRING which are separated by PATTERN. 293 "Return a list of substrings of STRING which are separated by PATTERN.
294 If PATTERN is omitted, it defaults to \"[ \\f\\t\\n\\r\\v]+\"." 294 If PATTERN is omitted, it defaults to \"[ \\f\\t\\n\\r\\v]+\"."
295 (or pattern 295 (or pattern
296 (setq pattern "[ \f\t\n\r\v]+")) 296 (setq pattern "[ \f\t\n\r\v]+"))
297 ;; The FSF version of this function takes care not to cons in case 297 (let (parts (start 0) (len (length string)))
298 ;; of infloop. Maybe we should synch? 298 (if (string-match pattern string)
299 (let (parts (start 0)) 299 (setq parts (cons (substring string 0 (match-beginning 0)) parts)
300 (while (string-match pattern string start) 300 start (match-end 0)))
301 (while (and (< start len)
302 (string-match pattern string (if (> start (match-beginning 0))
303 start
304 (1+ start))))
301 (setq parts (cons (substring string start (match-beginning 0)) parts) 305 (setq parts (cons (substring string start (match-beginning 0)) parts)
302 start (match-end 0))) 306 start (match-end 0)))
303 (nreverse (cons (substring string start) parts)))) 307 (nreverse (cons (substring string start) parts))))
304 308
305 ;; #### #### #### AAaargh! Must be in C, because it is used insanely 309 ;; #### #### #### AAaargh! Must be in C, because it is used insanely