changeset 133:c719d3fdbc15

Added functrion to trim white space from string.
author Sascha Wilde <wilde@intevation.de>
date Mon, 24 Mar 2014 15:11:47 +0100
parents 4691d9e3b1d3
children 5f830969e4a1
files common/strhelp.c common/strhelp.h
diffstat 2 files changed, 20 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/common/strhelp.c	Mon Mar 24 13:35:20 2014 +0100
+++ b/common/strhelp.c	Mon Mar 24 15:11:47 2014 +0100
@@ -123,3 +123,14 @@
   else
     return false;
 }
+
+void
+str_trim (char **s)
+{
+  size_t i;
+  while (isspace(**s))
+    (*s)++;
+  i = strlen(*s);
+  while (isspace((*s)[--i]))
+    (*s)[i] = '\0';
+}
--- a/common/strhelp.h	Mon Mar 24 13:35:20 2014 +0100
+++ b/common/strhelp.h	Mon Mar 24 15:11:47 2014 +0100
@@ -66,4 +66,13 @@
  */
 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/