unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* string-strip
@ 2006-06-20 10:26 Andreas Roehler
  0 siblings, 0 replies; 35+ messages in thread
From: Andreas Roehler @ 2006-06-20 10:26 UTC (permalink / raw)
  Cc: Richard Stallman

Looks great. Thanks.

Here with this example included:

(defun string-strip (str)
  "Return a copy of STR with leading and trailing white space removed.

\(string-strip \" foo \")      => \"foo\"
\(string-strip \" \\nfoo\\n \")  => \"foo\"
\(string-strip \" foo\\nbar \") => \"foo\\nbar\"
\(string-strip \" \")          => \"\"
\(string-strip \" \\n \")       => \"\"
"
  (save-match-data
    (string-match
"\\`[[:space:]\n]*\\(\\(?:.\\|\n\\)*?\\)[[:space:]\n]*\\'" str)
    (match-string 1 str)))

^ permalink raw reply	[flat|nested] 35+ messages in thread
* string-strip
@ 2006-06-16  8:07 Andreas Roehler
  2006-06-19  7:42 ` string-strip Richard Stallman
  0 siblings, 1 reply; 35+ messages in thread
From: Andreas Roehler @ 2006-06-16  8:07 UTC (permalink / raw)


Hi,

quite often I need a function to correct user-input,
i.e. wrongly inserted white spaces.

Used `comment-string-strip' to that purpose, which
works fine so far. However, there are two problems with
it:

- it's rather difficult to use, as its requires
  handling of three arguments, where just one would
  sufficient in the cases I need it.

- it's in newcomment.el, used for a special purpose
  there and may be changed. So I hesitate to
  make programs depend on them.

What about to introduce a simplified version of `comment-string-strip' 
into subr.el - if it's not already somewhere?

(defun my-string-strip (str)
  "Strip STR of any leading (if BEFOREP) and/or trailing (if AFTERP) space."
  (string-match "\\`\\s-*\\(.*?\\)\\s-*\n?\\'" str)
  (match-string 1 str))

(string-strip "asdf ")"asdf"
(string-strip " asdf")"asdf"
(string-strip " asdf ")"asdf"

__
Andreas Roehler

^ permalink raw reply	[flat|nested] 35+ messages in thread

end of thread, other threads:[~2006-11-25  6:58 UTC | newest]

Thread overview: 35+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-06-20 10:26 string-strip Andreas Roehler
  -- strict thread matches above, loose matches on Subject: below --
2006-06-16  8:07 string-strip Andreas Roehler
2006-06-19  7:42 ` string-strip Richard Stallman
2006-06-19 17:59   ` string-strip Lars Hansen
2006-06-19 18:24     ` string-strip Stuart D. Herring
2006-06-19 20:20       ` string-strip Lars Hansen
2006-06-19 20:23       ` string-strip Andreas Schwab
2006-06-19 22:04         ` string-strip Kim F. Storm
2006-06-19 23:19       ` string-strip Richard Stallman
2006-06-20  6:34         ` string-strip Lars Hansen
2006-06-20 17:55           ` string-strip Richard Stallman
2006-06-20 19:28             ` string-strip Andreas Roehler
2006-06-20 19:50               ` string-strip Nick Roberts
2006-06-20 22:03                 ` string-strip Kim F. Storm
2006-06-20 22:25                   ` string-strip Nick Roberts
2006-06-20 22:42                   ` string-strip Johan Bockgård
2006-06-21 16:47                     ` string-strip Lars Hansen
2006-06-22  9:15                       ` string-strip Kim F. Storm
2006-06-22 11:21                         ` string-strip Andreas Roehler
2006-06-22 15:48                           ` string-strip Kim F. Storm
2006-06-28 11:52                         ` string-strip Lars Hansen
2006-06-28 14:47                           ` string-strip Juri Linkov
2006-06-29 13:00                           ` string-strip Richard Stallman
2006-07-02 16:03                           ` string-strip Stefan Monnier
2006-07-03  9:58                             ` string-strip Lars Hansen
2006-07-06 22:22                               ` string-strip Stefan Monnier
2006-07-07 19:31                                 ` string-strip Richard Stallman
2006-07-08  3:59                                   ` string-strip Stefan Monnier
2006-07-08 20:57                                     ` string-strip Richard Stallman
2006-09-29  7:41                           ` string-strip Andreas Roehler
2006-09-29 14:22                             ` string-strip Lars Hansen
2006-09-29 18:40                               ` string-strip Andreas Roehler
2006-09-29 21:45                               ` string-strip Richard Stallman
2006-11-24 15:02                                 ` string-strip Andreas Roehler
2006-11-25  6:58                                   ` string-strip Richard Stallman

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).