changeset 138:7a8d960d60c9

Merged
author Andre Heinecke <aheinecke@intevation.de>
date Mon, 24 Mar 2014 14:57:37 +0000
parents 4904fe01055d (current diff) 5fa4791d6d0e (diff)
children 52993db093f4
files
diffstat 2 files changed, 65 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/common/strhelp.c	Mon Mar 24 14:55:48 2014 +0000
+++ b/common/strhelp.c	Mon Mar 24 14:57:37 2014 +0000
@@ -1,4 +1,5 @@
-
+#include <ctype.h>
+#include <stdbool.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
@@ -102,3 +103,38 @@
       free (str_array);
     }
 }
+
+bool
+str_equal (char *s1, char *s2)
+{
+  size_t l1 = strlen(s1);
+  size_t l2 = strlen(s2);
+  if ((l1 == l2) &&
+      (strcmp(s1, s2) == 0))
+    return true;
+  else
+    return false;
+}
+
+bool
+str_starts_with (char *s1, char *s2)
+{
+  if (strncmp(s1, s2, strlen(s2)) == 0)
+    return true;
+  else
+    return false;
+}
+
+void
+str_trim (char **s)
+{
+  size_t i;
+  if (*s != NULL)
+    {
+      while (isspace(**s))
+        (*s)++;
+      i = strlen(*s);
+      while (isspace((*s)[--i]))
+        (*s)[i] = '\0';
+    }
+}
--- a/common/strhelp.h	Mon Mar 24 14:55:48 2014 +0000
+++ b/common/strhelp.h	Mon Mar 24 14:57:37 2014 +0000
@@ -1,6 +1,8 @@
 #ifndef STRHELP_H
 #define STRHELP_H
 
+#include <stdbool.h>
+
 /**
  * @file  strhelp.h
  * @brief Helper functions for c strings and memory management
@@ -47,4 +49,30 @@
  * @param[inout] str_array a %NULL-terminated array of strings
  */
 void strv_free (char **str_array);
+
+/**
+ * @brief Checks whether two strings exactly match
+ * @param[in] s1 the first string
+ * @param[in] s2 the second string
+ * @returns true if s1 and s2 are equal
+ */
+bool str_equal (char *s1, char *s2);
+
+/**
+ * @brief Checks whether s2 exactly matches the beginning of s1.
+ * @param[in] s1 the string who's beginning is searched
+ * @param[in] s2 the string which is searched for
+ * @returns true if s1 starts with s2, false otherwise
+ */
+bool str_starts_with (char *s1, char *s2);
+
+/**
+ * @brief Trims all white space from the start and end of string.
+ * @details the start of the string is trimmed by setting *s to the
+ * first non white space character.  The end is trimmed by setting the
+ * first character after the last non white space character to \0.
+ * @param[inout] s ponter to the string to strip
+ */
+bool str_trim (char **s);
+
 #endif

http://wald.intevation.org/projects/trustbridge/