diff th_string.c @ 89:30690f5c4cae

Add new function th_strrcasecmp().
author Matti Hamalainen <ccr@tnsp.org>
date Sat, 17 May 2014 22:39:37 +0300
parents d3d3cd41a95a
children 2b1f7f1ca8e4
line wrap: on
line diff
--- a/th_string.c	Sat May 17 22:39:27 2014 +0300
+++ b/th_string.c	Sat May 17 22:39:37 2014 +0300
@@ -158,6 +158,29 @@
 }
 
 
+/* Check if end of the given string str matches needle
+ * case-insensitively, return pointer to start of the match,
+ * if found, NULL otherwise.
+ */
+char *th_strrcasecmp(char *str, const char *needle)
+{
+    if (str == NULL || needle == NULL)
+        return NULL;
+
+    const size_t
+        slen = strlen(str),
+        nlen = strlen(needle);
+    
+    if (slen < nlen)
+        return NULL;
+
+    if (th_strcasecmp(str - nlen - 1, needle) == 0)
+        return str - nlen - 1;
+    else
+        return NULL;
+}
+
+
 /* Remove all occurences of control characters, in-place.
  * Resulting string is always shorter or same length than original.
  */