unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* [PATCH] * lisp/subr.el (string-suffix-p): New function.
@ 2013-11-20 11:24 Bozhidar Batsov
  2013-11-22  7:06 ` Bozhidar Batsov
  0 siblings, 1 reply; 14+ messages in thread
From: Bozhidar Batsov @ 2013-11-20 11:24 UTC (permalink / raw)
  To: emacs-devel


[-- 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


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

end of thread, other threads:[~2013-11-23 17:03 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-11-20 11:24 [PATCH] * lisp/subr.el (string-suffix-p): New function Bozhidar Batsov
2013-11-22  7:06 ` 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

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).