[gnome-notes/136-implement-the-list-row-pattern-in-main-view: 6/15] string: added biji_str_clean function



commit 2f9a24391ccac073489cfeee21fe6b03b1ed843a
Author: Isaque Galdino <igaldino gmail com>
Date:   Fri Feb 14 13:36:00 2020 -0300

    string: added biji_str_clean function

 src/libbiji/biji-string.c | 25 +++++++++++++++++++++++++
 src/libbiji/biji-string.h |  4 ++++
 2 files changed, 29 insertions(+)
---
diff --git a/src/libbiji/biji-string.c b/src/libbiji/biji-string.c
index a09898a..2923f5d 100644
--- a/src/libbiji/biji-string.c
+++ b/src/libbiji/biji-string.c
@@ -83,3 +83,28 @@ gchar * biji_str_mass_replace (const gchar *string,
   return result;
 }
 
+char *
+biji_str_clean (const char *text)
+{
+  char *result = biji_str_replace ((const char *) text, "\t", " ");
+  char *tmp    = biji_str_replace ((const char *) result, "\u00A0", " ");
+
+  if (tmp)
+    {
+      g_free (result);
+      result = tmp;
+    }
+
+  while (g_strstr_len (result, -1, "  "))
+    {
+      tmp = biji_str_replace ((const char *) result, "  ", " ");
+      if (tmp)
+        {
+          g_free (result);
+          result = tmp;
+        }
+    }
+  return result;
+}
+
+
diff --git a/src/libbiji/biji-string.h b/src/libbiji/biji-string.h
index db4f9b7..bbbb0cb 100644
--- a/src/libbiji/biji-string.h
+++ b/src/libbiji/biji-string.h
@@ -29,4 +29,8 @@ gchar * biji_str_replace (const gchar *string, const gchar *as_is, const gchar *
  * Returns a newly allocated string */
 gchar * biji_str_mass_replace (const gchar *string, ...) G_GNUC_NULL_TERMINATED ;
 
+/* Cleans extra spaces, including tabs and no-break spaces from strings
+ * Returns a newly allocated string */
+char *biji_str_clean (const char *string);
+
 G_END_DECLS


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]