/[emacs]/emacs/lisp/subr.el
ViewVC logotype

Diff of /emacs/lisp/subr.el

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.353 by rms, Sun May 18 15:04:24 2003 UTC revision 1.354 by lektu, Thu May 22 20:59:57 2003 UTC
# Line 1820  STRING should be given if the last searc Line 1820  STRING should be given if the last searc
1820          (buffer-substring-no-properties (match-beginning num)          (buffer-substring-no-properties (match-beginning num)
1821                                          (match-end num)))))                                          (match-end num)))))
1822    
1823  (defun split-string (string &optional separators)  (defconst split-string-default-separators "[ \f\t\n\r\v]+"
1824    "Splits STRING into substrings where there are matches for SEPARATORS.    "The default value of separators for `split-string'.
1825  Each match for SEPARATORS is a splitting point.  
1826  The substrings between the splitting points are made into a list  A regexp matching strings of whitespace.  May be locale-dependent
1827    \(as yet unimplemented).  Should not match non-breaking spaces.
1828    
1829    Warning: binding this to a different value and using it as default is
1830    likely to have undesired semantics.")
1831    
1832    ;; The specification says that if both SEPARATORS and OMIT-NULLS are
1833    ;; defaulted, OMIT-NULLS should be treated as t.  Simplifying the logical
1834    ;; expression leads to the equivalent implementation that if SEPARATORS
1835    ;; is defaulted, OMIT-NULLS is treated as t.
1836    (defun split-string (string &optional separators omit-nulls)
1837      "Splits STRING into substrings bounded by matches for SEPARATORS.
1838    
1839    The beginning and end of STRING, and each match for SEPARATORS, are
1840    splitting points.  The substrings matching SEPARATORS are removed, and
1841    the substrings between the splitting points are collected as a list,
1842  which is returned.  which is returned.
 If SEPARATORS is absent, it defaults to \"[ \\f\\t\\n\\r\\v]+\".  
1843    
1844  If there is match for SEPARATORS at the beginning of STRING, we do not  If SEPARATORS is non-nil, it should be a regular expression matching text
1845  include a null substring for that.  Likewise, if there is a match  which separates, but is not part of, the substrings.  If nil it defaults to
1846  at the end of STRING, we don't include a null substring for that.  `split-string-default-separators', normally \"[ \\f\\t\\n\\r\\v]+\", and
1847    OMIT-NULLS is forced to t.
1848    
1849    If OMIT-NULLs is t, zero-length substrings are omitted from the list \(so
1850    that for the default value of SEPARATORS leading and trailing whitespace
1851    are effectively trimmed).  If nil, all zero-length substrings are retained,
1852    which correctly parses CSV format, for example.
1853    
1854    Note that the effect of `(split-string STRING)' is the same as
1855    `(split-string STRING split-string-default-separators t)').  In the rare
1856    case that you wish to retain zero-length substrings when splitting on
1857    whitespace, use `(split-string STRING split-string-default-separators)'.
1858    
1859  Modifies the match data; use `save-match-data' if necessary."  Modifies the match data; use `save-match-data' if necessary."
1860    (let ((rexp (or separators "[ \f\t\n\r\v]+"))    (let ((keep-nulls (not (if separators omit-nulls t)))
1861            (rexp (or separators split-string-default-separators))
1862          (start 0)          (start 0)
1863          notfirst          notfirst
1864          (list nil))          (list nil))
# Line 1841  Modifies the match data; use `save-match Line 1867  Modifies the match data; use `save-match
1867                                         (= start (match-beginning 0))                                         (= start (match-beginning 0))
1868                                         (< start (length string)))                                         (< start (length string)))
1869                                    (1+ start) start))                                    (1+ start) start))
1870                  (< (match-beginning 0) (length string)))                  (< start (length string)))
1871        (setq notfirst t)        (setq notfirst t)
1872        (or (eq (match-beginning 0) 0)        (if (or keep-nulls (< start (match-beginning 0)))
           (and (eq (match-beginning 0) (match-end 0))  
                (eq (match-beginning 0) start))  
1873            (setq list            (setq list
1874                  (cons (substring string start (match-beginning 0))                  (cons (substring string start (match-beginning 0))
1875                        list)))                        list)))
1876        (setq start (match-end 0)))        (setq start (match-end 0)))
1877      (or (eq start (length string))      (if (or keep-nulls (< start (length string)))
1878          (setq list          (setq list
1879                (cons (substring string start)                (cons (substring string start)
1880                      list)))                      list)))
# Line 1868  Unless optional argument INPLACE is non- Line 1892  Unless optional argument INPLACE is non-
1892      newstr))      newstr))
1893    
1894  (defun replace-regexp-in-string (regexp rep string &optional  (defun replace-regexp-in-string (regexp rep string &optional
1895                                          fixedcase literal subexp start)                                   fixedcase literal subexp start)
1896    "Replace all matches for REGEXP with REP in STRING.    "Replace all matches for REGEXP with REP in STRING.
1897    
1898  Return a new string containing the replacements.  Return a new string containing the replacements.
# Line 1917  and replace a sub-expression, e.g. Line 1941  and replace a sub-expression, e.g.
1941                                         rep                                         rep
1942                                       (funcall rep (match-string 0 str)))                                       (funcall rep (match-string 0 str)))
1943                                     fixedcase literal str subexp)                                     fixedcase literal str subexp)
1944                      (cons (substring string start mb) ; unmatched prefix                      (cons (substring string start mb)       ; unmatched prefix
1945                            matches)))                            matches)))
1946          (setq start me))          (setq start me))
1947        ;; Reconstruct a string from the pieces.        ;; Reconstruct a string from the pieces.
# Line 2157  included in the mode-line minor mode men Line 2181  included in the mode-line minor mode men
2181  If TOGGLE has a `:menu-tag', that is used for the menu item's label."  If TOGGLE has a `:menu-tag', that is used for the menu item's label."
2182    (unless (memq toggle minor-mode-list)    (unless (memq toggle minor-mode-list)
2183      (push toggle minor-mode-list))      (push toggle minor-mode-list))
2184        
2185    (unless toggle-fun (setq toggle-fun toggle))    (unless toggle-fun (setq toggle-fun toggle))
2186    ;; Add the name to the minor-mode-alist.    ;; Add the name to the minor-mode-alist.
2187    (when name    (when name

Legend:
Removed from v.1.353  
changed lines
  Added in v.1.354

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26