qemacs-commit
[Top][All Lists]
Advanced

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

[Qemacs-commit] qemacs cutils.c cutils.h


From: Charlie Gordon
Subject: [Qemacs-commit] qemacs cutils.c cutils.h
Date: Tue, 04 Feb 2014 03:28:14 +0000

CVSROOT:        /sources/qemacs
Module name:    qemacs
Changes by:     Charlie Gordon <chqrlie>        14/02/04 03:28:14

Modified files:
        .              : cutils.c cutils.h 

Log message:
        add strend to match string suffix

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/qemacs/cutils.c?cvsroot=qemacs&r1=1.16&r2=1.17
http://cvs.savannah.gnu.org/viewcvs/qemacs/cutils.h?cvsroot=qemacs&r1=1.15&r2=1.16

Patches:
Index: cutils.c
===================================================================
RCS file: /sources/qemacs/qemacs/cutils.c,v
retrieving revision 1.16
retrieving revision 1.17
diff -u -b -r1.16 -r1.17
--- cutils.c    3 Dec 2013 17:31:49 -0000       1.16
+++ cutils.c    4 Feb 2014 03:28:14 -0000       1.17
@@ -54,6 +54,28 @@
 }
 
 /**
+ * Return TRUE if val is a suffix of str. If it returns TRUE, ptr is
+ * set to the first character of the suffix in 'str'.
+ *
+ * @param str input string
+ * @param val suffix to test
+ * @param ptr updated to the suffix in str in there is a match
+ * @return TRUE if there is a match
+ */
+int strend(const char *str, const char *val, const char **ptr)
+{
+    int len1 = strlen(str);
+    int len2 = strlen(val);
+
+    if (len1 < len2 || memcmp(str + len1 - len2, val, len2)) {
+        return 0;
+    }
+    if (ptr)
+        *ptr = str + len1 - len2;
+    return 1;
+}
+
+/**
  * Copy the string str to buf. If str length is bigger than buf_size -
  * 1 then it is clamped to buf_size - 1.
  * NOTE: this function does what strncpy should have done to be

Index: cutils.h
===================================================================
RCS file: /sources/qemacs/qemacs/cutils.h,v
retrieving revision 1.15
retrieving revision 1.16
diff -u -b -r1.15 -r1.16
--- cutils.h    23 Jan 2014 12:43:40 -0000      1.15
+++ cutils.h    4 Feb 2014 03:28:14 -0000       1.16
@@ -27,6 +27,7 @@
 /* These definitions prevent a clash with ffmpeg's cutil module. */
 
 #define strstart(str, val, ptr)    qe_strstart(str, val, ptr)
+#define strend(str, val, ptr)      qe_strend(str, val, ptr)
 #define pstrcpy(buf, sz, str)      qe_pstrcpy(buf, sz, str)
 #define pstrcat(buf, sz, str)      qe_pstrcat(buf, sz, str)
 #define pstrncpy(buf, sz, str, n)  qe_pstrncpy(buf, sz, str, n)
@@ -37,6 +38,7 @@
 #define strtok(str,sep)   do_not_use_strtok!!(str,sep)
 
 int strstart(const char *str, const char *val, const char **ptr);
+int strend(const char *str, const char *val, const char **ptr);
 char *pstrcpy(char *buf, int buf_size, const char *str);
 char *pstrcat(char *buf, int buf_size, const char *s);
 char *pstrncpy(char *buf, int buf_size, const char *s, int len);



reply via email to

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