]> diplodocus.org Git - nmh/commitdiff
Add TrimSuffixC(char *s, int c).
authorRalph Corderoy <ralph@inputplus.co.uk>
Tue, 18 Oct 2016 16:05:24 +0000 (17:05 +0100)
committerRalph Corderoy <ralph@inputplus.co.uk>
Wed, 19 Oct 2016 09:12:00 +0000 (10:12 +0100)
TrimSuffixC deletes c from the end of non-NULL string s if it's present,
shortening s by 1.  Only one instance of c is removed.

h/utils.h
sbr/utils.c

index 9b659501bb6377234a1ca18d41affc4aa4a07ab7..edb2ab03d31ca0be32436e8cbdc3fa1cf62a7e2b 100644 (file)
--- a/h/utils.h
+++ b/h/utils.h
@@ -63,6 +63,8 @@ char *find_str (const char [], size_t, const char *);
 char *rfind_str (const char [], size_t, const char *);
 char *nmh_strcasestr (const char *, const char *);
 
 char *rfind_str (const char [], size_t, const char *);
 char *nmh_strcasestr (const char *, const char *);
 
+void TrimSuffixC(char *s, int c);
+
 /*
  * See if a string contains 8 bit characters (use isascii() for the test).
  * Arguments include:
 /*
  * See if a string contains 8 bit characters (use isascii() for the test).
  * Arguments include:
index c9769fb0b909303789d855e6000ccfea9ae8d938..d9b903e70e01978630d85bf75f364890106ae71c 100644 (file)
@@ -360,6 +360,19 @@ nmh_strcasestr (const char *s1, const char *s2) {
 }
 
 
 }
 
 
+/* TrimSuffixC deletes c from the end of non-NULL string s if it's
+ * present, shortening s by 1.  Only one instance of c is removed. */
+void TrimSuffixC(char *s, int c)
+{
+    if (!*s)
+        return;
+
+    s += strlen(s) - 1;
+    if (*s == c)
+        *s = '\0';
+}
+
+
 int
 nmh_init(const char *argv0, int read_context) {
     if (! setlocale(LC_ALL, "")) {
 int
 nmh_init(const char *argv0, int read_context) {
     if (! setlocale(LC_ALL, "")) {