summaryrefslogtreecommitdiff
path: root/src/gallery-utils.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/gallery-utils.c')
-rw-r--r--src/gallery-utils.c34
1 files changed, 34 insertions, 0 deletions
diff --git a/src/gallery-utils.c b/src/gallery-utils.c
index d97cef3..403b3c6 100644
--- a/src/gallery-utils.c
+++ b/src/gallery-utils.c
@@ -94,6 +94,40 @@ str_replace (gchar **dst, const gchar *search, const gchar *replace)
/*
+ * str_trim_inside: trims any leading, trailing and repeated whitespaces in the whole string
+ */
+#define IS_WHITESPACE(s) (s == ' ' || s == '\t')
+
+void
+str_trim_inside (gchar **s)
+{
+ gchar *dst;
+ gboolean was_whitespace;
+ int pos;
+ gchar *src;
+
+ if (! s || strlen (*s) == 0 )
+ return;
+
+ /* suppose the new string is not longer than the input string */
+ dst = g_malloc0 (strlen (*s) + 1);
+ was_whitespace = TRUE; /* handles beginning of the string */
+ pos = 0;
+ for (src = *s; *src != '\0'; src++)
+ if (! IS_WHITESPACE (*src) || ! was_whitespace) {
+ dst[pos++] = *src;
+ was_whitespace = IS_WHITESPACE (*src);
+ }
+ if (IS_WHITESPACE (dst[pos - 1]))
+ dst[pos - 1] = '\0';
+
+ /* return fixed string */
+ g_free (*s);
+ *s = dst;
+}
+
+
+/*
* copy_file: copy file from src to dst
*/
gboolean