]> code.citadel.org Git - citadel.git/blobdiff - libcitadel/lib/tools.c
bmstrcasestr() now returns NULL if either of its supplied
[citadel.git] / libcitadel / lib / tools.c
index c056fe94d8ea4a4b1ecf50c81dfac15a77c79ddc..dd630420fa4b79b57ded590ddcab02414e5192dd 100644 (file)
@@ -772,6 +772,9 @@ char *bmstrcasestr(char *text, char *pattern) {
        size_t textlen;
        size_t patlen;
 
+       if (!text) return(NULL);
+       if (!pattern) return(NULL);
+
        textlen = strlen (text);
        patlen = strlen (pattern);
 
@@ -895,10 +898,10 @@ int pattern2(char *search, char *patn)
 }
 
 
-/**
- * \brief Strip leading and trailing spaces from a string; with premeasured and adjusted length.
- * \param buf the string to modify
- * \param len length of the string. 
+/*
+ * Strip leading and trailing spaces from a string; with premeasured and adjusted length.
+ * buf - the string to modify
+ * len - length of the string. 
  */
 void stripltlen(char *buf, int *len)
 {
@@ -916,3 +919,21 @@ void stripltlen(char *buf, int *len)
        }
 }
 
+
+/*
+ * Convert all whitespace characters in a supplied string to underscores
+ */
+void convert_spaces_to_underscores(char *str)
+{
+       int len;
+       int i;
+
+       if (!str) return;
+
+       len = strlen(str);
+       for (i=0; i<len; ++i) {
+               if (isspace(str[i])) {
+                       str[i] = '_';
+               }
+       }
+}