emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: string-strip


From: Andreas Roehler
Subject: Re: string-strip
Date: Fri, 24 Nov 2006 16:02:25 +0100
User-agent: Thunderbird 1.5.0.4 (X11/20060516)

Richard Stallman schrieb:
We could install string-strip after the release, but let's not do it now.


What about to split the regexp into parts? Thus it's
easier to change values.

Regards

__
Andreas Roehler

;;;

;; (setq strip-chars-before "\\`[[:space:],;\/\n]*")
;; (setq strip-chars-after "[[:space:],;\n]*\\'")
;; (setq string-strip-preserve "\\(\\(?:.\\|\n\\)*?\\)")

(defcustom strip-chars-before  "\\`[[:space:]\n]*"
"Regexp indicating which chars shall be stripped before STRING - which is defined by `string-strip-preserve'"

:type 'string
:group 'convenience)

(defcustom strip-chars-after  "[[:space:]\n]*\\'"
"Regexp indicating which chars shall be stripped after STRING - which is defined by `string-strip-preserve'"

:type 'string
:group 'convenience)

(defcustom string-strip-preserve  "\\(\\(?:.\\|\n\\)*?\\)"
 "Regexp indicating which chars shall be constitutents of STRING
thus being preserved - whereas `strip-chars-after' and
`strip-chars-before' indicate what class of chars to strip from beginning or end of STRING"

:type 'string
:group 'convenience)

(defun string-strip (str)
 "Return a copy of STR with leading and trailing CHARS removed.
Customize `strip-chars-before' and `strip-chars-after' respectively.
Default is `[[:space:]\n]*', i.e. spaces, tabs and newlines."
 (interactive)
 (save-match-data
   (string-match
(concat strip-chars-before string-strip-preserve strip-chars-after) str)
   (match-string 1 str)))






reply via email to

[Prev in Thread] Current Thread [Next in Thread]