Article View: gnu.emacs.help
Article #189038Re: 'split' for emacs lisp
From: Mike Williams
Date: Thu, 09 May 1991 12:56
Date: Thu, 09 May 1991 12:56
46 lines
2637 bytes
2637 bytes
>>> In article <9105081810.AA18310@bill-the-cat.MIT.EDU>,
>>> "bjaspan" == bjaspan@ATHENA.MIT.EDU ("Barr3y Jaspan") writes:
bjaspan> For emacs-loving perl users, or perl-loving emacs users, here is an
bjaspan> implementation of the perl function 'split' for emacs lisp. It seems
bjaspan> to work for me, your mileage may vary. Comments welcome.
bjaspan> --- snip snip ---
bjaspan> ;;; split.el --- emacs implementation of Perl's 'split' function.
bjaspan> ;;; (C) Copyright 1991 by Barr3y Jaspan (bjaspan@mit.edu)
Neat idea. Here's another version, which acts slighty differently, but
doesn't use a temporary buffer.
;;=== Perl-like split ===
(defun split (STRING &optional SPLIT-RE INCLUDE-SEP)
"Splits STRING into a list of strings. Optional second argument SPLIT-RE
defines the regular expression used to find breakpoints, the default is
\"\\s +\" (whitespace). The SPLIT-RE must not match the null string.
If optional third argument INCLUDE-SEP is non-nil, separator strings are
included in the resulting substrings."
(if SPLIT-RE nil (setq SPLIT-RE "\\s +"))
(if (string-match SPLIT-RE "")
(error "SPLIT-RE must not match null string"))
(let (strings)
(while (and (not (equal STRING ""))
(string-match SPLIT-RE STRING))
(setq strings
(cons
(substring STRING 0 (if INCLUDE-SEP (match-end 0)
(match-beginning 0)))
strings))
(setq STRING (substring STRING (match-end 0))))
(setq strings (cons STRING strings))
(nreverse strings)))
--
/-------------------- mike-w@cs.aukuni.ac.nz ---------------------\
| Mike Williams, Computer Science, Auckland University, Aotearoa. |
\-------------- What's another word for Thesaurus? ---------------/
--
New administrater uofa.
Technical Details
Message-ID:
<MIKE-W.91May9085658@cs17.cs.aukuni.ac.nz>Path:
arc1-ca.pugleaf.net!gmdzi!unido!fauern!ira.uka.de!sol.ctr.columbia.edu!caen!sdd.hp.com!wuarchive!uunet!comp.vuw.ac.nz!waikato.ac.nz!aukuni.ac.nz!mike-wReferences:
<9105081810.AA18310@bill-the-cat.MIT.EDU>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103b8b,93b543a43bc8f04d,start X-Google-Attributes: gid103b8b,public X-Google-ArrivalTime: 1991-05-09 00:50:02 PST Path: arc1-ca.pugleaf.net!gmdzi!unido!fauern!ira.uka.de!sol.ctr.columbia.edu!caen!sdd.hp.com!wuarchive!uunet!comp.vuw.ac.nz!waikato.ac.nz!aukuni.ac.nz!mike-w From: mike-w@cs.aukuni.ac.nz (Mike Williams) Newsgroups: gnu.emacs.help Subject: Re: 'split' for emacs lisp Message-ID: <MIKE-W.91May9085658@cs17.cs.aukuni.ac.nz> Date: 9 May 91 12:56:58 GMT References: <9105081810.AA18310@bill-the-cat.MIT.EDU> Sender: news@ccu1.aukuni.ac.nz (News Owner) Followup-To: gnu.emacs.help Organization: Very little Lines: 46 In-Reply-To: bjaspan@ATHENA.MIT.EDU's message of 8 May 91 18:10:44 GMT Nntp-Posting-Host: cs17.cs.aukuni.ac.nz X-News-Software: GNUS 3.13