all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Bozhidar Batsov <bozhidar@batsov.com>
To: emacs-devel <emacs-devel@gnu.org>
Subject: [PATCH] * lisp/subr.el (string-suffix-p): New function.
Date: Wed, 20 Nov 2013 13:24:22 +0200	[thread overview]
Message-ID: <96EB3F8805134461A3BA58983F643449@gmail.com> (raw)


[-- Attachment #1.1: Type: text/plain, Size: 298 bytes --]

Hi guys,  

We do have `string-prefix-p' function, but oddly enough we didn’t have a matching `string-suffix-p', so I’ve implemented it.

I also think it might be a good idea to alias those two functions to `string-starts-with-p' and `string-ends-with-p’.  

--  
Cheers,
Bozhidar


[-- Attachment #1.2: Type: text/html, Size: 670 bytes --]

[-- Attachment #2: 0001-lisp-subr.el-string-suffix-p-New-function.patch --]
[-- Type: application/octet-stream, Size: 1451 bytes --]

From f73541c4bc69bc4bb703fb62c87be059bbbba516 Mon Sep 17 00:00:00 2001
From: Bozhidar Batsov <bozhidar@batsov.com>
Date: Wed, 20 Nov 2013 13:17:07 +0200
Subject: [PATCH] * lisp/subr.el (string-suffix-p): New function.

---
 lisp/ChangeLog | 4 ++++
 lisp/subr.el   | 9 +++++++++
 2 files changed, 13 insertions(+)

diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index 357087d..0acdf62 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,3 +1,7 @@
+2013-11-20  Bozhidar Batsov  <bozhidar@batsov.com>
+
+	* subr.el (string-suffix-p): New function.
+
 2013-11-20  era eriksson  <era+emacsbugs@iki.fi>
 
 	* ses.el (ses-mode): Doc fix.  (Bug#14748)
diff --git a/lisp/subr.el b/lisp/subr.el
index 31798b4..b22c719 100644
--- a/lisp/subr.el
+++ b/lisp/subr.el
@@ -3635,6 +3635,15 @@ to case differences."
   (eq t (compare-strings str1 nil nil
                          str2 0 (length str1) ignore-case)))
 
+(defun string-suffix-p (suffix string  &optional ignore-case)
+  "Return non-nil if SUFFIX is a suffix of STRING.
+If IGNORE-CASE is non-nil, the comparison is done without paying
+attention to case differences."
+  (let ((start-pos (- (length string) (length suffix))))
+    (and (>= start-pos 0)
+         (eq t (compare-strings suffix nil nil
+                                string start-pos nil ignore-case)))))
+
 (defun bidi-string-mark-left-to-right (str)
   "Return a string that can be safely inserted in left-to-right text.
 
-- 
1.8.4


             reply	other threads:[~2013-11-20 11:24 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-11-20 11:24 Bozhidar Batsov [this message]
2013-11-22  7:06 ` [PATCH] * lisp/subr.el (string-suffix-p): New function Bozhidar Batsov
2013-11-22  9:12   ` Thien-Thi Nguyen
2013-11-22 10:00     ` Bozhidar Batsov
2013-11-22 10:15       ` Lars Magne Ingebrigtsen
2013-11-22 10:41         ` Bozhidar Batsov
2013-11-22 14:07           ` Stefan Monnier
2013-11-22 14:27             ` Bozhidar Batsov
2013-11-23  1:44               ` Stefan Monnier
2013-11-23  6:05             ` Josh
2013-11-23 13:57               ` Stefan Monnier
2013-11-23 10:16             ` Stephen J. Turnbull
2013-11-23 17:03           ` Lars Magne Ingebrigtsen
2013-11-22 15:06   ` Jarek Czekalski

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=96EB3F8805134461A3BA58983F643449@gmail.com \
    --to=bozhidar@batsov.com \
    --cc=emacs-devel@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

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

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.