Mercurial > hg > xemacs-beta
comparison lisp/subr.el @ 1495:c3cf7db99b98
[xemacs-hg @ 2003-05-22 07:41:20 by stephent]
oldies faq <87iss3tpac.fsf@tleepslib.sk.tsukuba.ac.jp>
split-string tweaks n dox <87n0hftpht.fsf@tleepslib.sk.tsukuba.ac.jp>
missed commit of broken-sun.h <87r878ihhf.fsf@tleepslib.sk.tsukuba.ac.jp>
already loaded message <87el2rtovc.fsf@tleepslib.sk.tsukuba.ac.jp>
author | stephent |
---|---|
date | Thu, 22 May 2003 07:41:27 +0000 |
parents | 74cb069b8417 |
children | 124ce9dc008b |
comparison
equal
deleted
inserted
replaced
1494:210683f31426 | 1495:c3cf7db99b98 |
---|---|
617 likely to have undesired semantics.") | 617 likely to have undesired semantics.") |
618 | 618 |
619 ;; specification for `split-string' agreed with rms 2003-04-23 | 619 ;; specification for `split-string' agreed with rms 2003-04-23 |
620 ;; xemacs design <87vfx5vor0.fsf@tleepslib.sk.tsukuba.ac.jp> | 620 ;; xemacs design <87vfx5vor0.fsf@tleepslib.sk.tsukuba.ac.jp> |
621 | 621 |
622 ;; The specification says that if both SEPARATORS and OMIT-NULLS are | |
623 ;; defaulted, OMIT-NULLS should be treated as t. Simplifying the logical | |
624 ;; expression leads to the equivalent implementation that if SEPARATORS | |
625 ;; is defaulted, OMIT-NULLS is treated as t. | |
626 | |
622 (defun split-string (string &optional separators omit-nulls) | 627 (defun split-string (string &optional separators omit-nulls) |
623 "Splits STRING into substrings bounded by matches for SEPARATORS. | 628 "Splits STRING into substrings bounded by matches for SEPARATORS. |
624 | 629 |
625 The beginning and end of STRING, and each match for SEPARATORS, are | 630 The beginning and end of STRING, and each match for SEPARATORS, are |
626 splitting points. The substrings matching SEPARATORS are removed, and | 631 splitting points. The substrings matching SEPARATORS are removed, and |
627 the substrings between the splitting points are collected as a list, | 632 the substrings between the splitting points are collected as a list, |
628 which is returned. | 633 which is returned. |
629 | 634 |
630 If SEPARATORS is nil, it defaults to the value of | 635 If SEPARATORS is non-nil, it should be a regular expression matching text |
631 `split-string-default-separators', normally \"[ \\f\\t\\n\\r\\v]+\". | 636 which separates, but is not part of, the substrings. If nil it defaults to |
637 `split-string-default-separators', normally \"[ \\f\\t\\n\\r\\v]+\", and | |
638 OMIT-NULLS is forced to t. | |
632 | 639 |
633 If OMIT-NULLs is t, zero-length substrings are omitted from the list \(so | 640 If OMIT-NULLs is t, zero-length substrings are omitted from the list \(so |
634 that for the default value of SEPARATORS leading and trailing whitespace | 641 that for the default value of SEPARATORS leading and trailing whitespace |
635 are effectively trimmed). If nil, all zero-length substrings are retained, | 642 are effectively trimmed). If nil, all zero-length substrings are retained, |
636 which correctly parses CSV format, for example. | 643 which correctly parses CSV format, for example. |
637 | 644 |
638 As a special case, if both SEPARATORS and OMIT-NULLS are nil, white-space | 645 Note that the effect of `(split-string STRING)' is the same as |
639 will be trimmed (ie, the effect of `(split-string STRING)' is the same as | 646 `(split-string STRING split-string-default-separators t)'). In the rare |
640 `(split-string STRING split-string-default-separators t)'). In the very | 647 case that you wish to retain zero-length substrings when splitting on |
641 rare case that you need to retain zero-length substrings when splitting on | 648 whitespace, use `(split-string STRING split-string-default-separators nil)'. |
642 the default separators, use | |
643 `(split-string STRING split-string-default-separators)'. | |
644 | 649 |
645 Modifies the match data; use `save-match-data' if necessary." | 650 Modifies the match data; use `save-match-data' if necessary." |
646 | 651 |
647 (let ((keep-nulls (if separators (not omit-nulls) nil)) | 652 (let ((keep-nulls (not (if separators omit-nulls t))) |
648 (rexp (or separators split-string-default-separators)) | 653 (rexp (or separators split-string-default-separators)) |
649 (start 0) | 654 (start 0) |
650 notfirst | 655 notfirst |
651 (list nil)) | 656 (list nil)) |
652 (while (and (string-match rexp string | 657 (while (and (string-match rexp string |