emacs-devel
[Top][All Lists]
Advanced

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

Re: [PATCH] * lisp/subr.el (string-suffix-p): New function.


From: Bozhidar Batsov
Subject: Re: [PATCH] * lisp/subr.el (string-suffix-p): New function.
Date: Fri, 22 Nov 2013 12:41:00 +0200

On 22 November 2013 12:15, Lars Magne Ingebrigtsen <address@hidden> wrote:
Bozhidar Batsov <address@hidden> writes:

> I think it's quite important to provide an API closer to that of
> popular programming languages, used often for text processing(Perl,
> Python, Ruby, etc). That would include functions like:
>
> * string-join

`mapconcat'

You can't really favour this:

(mapconcat 'identity '(s1 s2 s3) separator)

over:

(defun string-join (separator &rest strings)
  (mapconcat 'identity strings separator))

(string-join separator s1 s2 s3)
 

> * string-trim/string-trim-left/string-trim-right

Perhaps.

> * string-chop

`split-string'

I'm not sure what split-string has to do with this?

From Ruby's API docs (http://www.ruby-doc.org/core-1.9.3/String.html#method-i-chop):

Returns a new String with the last character removed. If the string ends with \r\n, both characters are removed. Applying chop to an empty string returns an empty string.String#chomp is often a safer alternative, as it leaves the string unchanged if it doesn’t end in a record separator.

It's available in most scripting languages.
 

> * string-chomp

What does that do?

"hello".chomp            #=> "hello"
"hello\n".chomp          #=> "hello"
"hello\r\n".chomp        #=> "hello"
"hello\n\r".chomp        #=> "hello\n"
"hello\r".chomp          #=> "hello"
"hello \n there".chomp   #=> "hello \n there"
"hello".chomp("llo")     #=> "he"

It's origin is Perl, but it's available in most scripting languages.
 

--
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no


reply via email to

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