[balsa/port-to-pcre2: 10/10] regex: Drop libbalsa_regex_split()




commit d8a479c116ae0ba46e2c48955a1a51eb46c5329d
Author: Peter Bloomfield <PeterBloomfield bellsouth net>
Date:   Wed Dec 9 13:59:51 2020 -0500

    regex: Drop libbalsa_regex_split()
    
    No one uses it any more; it was always an incomplete replacement for
    g_regex_split().

 libbalsa/regex.c | 84 --------------------------------------------------------
 libbalsa/regex.h |  3 --
 2 files changed, 87 deletions(-)
---
diff --git a/libbalsa/regex.c b/libbalsa/regex.c
index 8181b0149..5c537f4f3 100644
--- a/libbalsa/regex.c
+++ b/libbalsa/regex.c
@@ -186,90 +186,6 @@ libbalsa_regex_match_simple(const gchar *pattern,
     return match;
 }
 
-/*
- * libbalsa_regex_split:
- * regex: a LibBalsaRegex structure
- * string: the string to split with the pattern
- * match_options: PCRE2 match options, or 0
- *
- * Breaks the string on the pattern, and returns an array of the tokens.
- * If the pattern contains capturing parentheses, then the text for each
- * of the substrings will also be returned. If the pattern does not match
- * anywhere in the string, then the whole string is returned as the first
- * token.
- *
- * A pattern that can match empty strings splits string into separate
- * characters wherever it matches the empty string between characters.
- * For example splitting "ab c" using as a separator "\s*", you will get
- * "a", "b" and "c".
- *
- * Returns: a NULL-terminated gchar ** array. Free it using g_strfreev().
- */
-gchar **
-libbalsa_regex_split(const LibBalsaRegex *regex,
-                     const gchar         *string,
-                     guint                match_options)
-{
-    GPtrArray *tokens;
-    LibBalsaMatchData *match_data;
-    gint status;
-    PCRE2_SIZE pos;
-
-    g_return_val_if_fail(regex != NULL, FALSE);
-    g_return_val_if_fail(string != NULL, FALSE);
-
-    match_options |= PCRE2_NO_UTF_CHECK;
-    match_data = pcre2_match_data_create_from_pattern(regex, NULL);
-    tokens = g_ptr_array_new();
-    pos = 0;
-
-    while ((status = pcre2_match(regex,
-                                 (PCRE2_SPTR) string,
-                                 PCRE2_ZERO_TERMINATED,
-                                 pos,
-                                 match_options,
-                                 match_data,
-                                 NULL)) > 0) {
-        PCRE2_SIZE *ovector;
-        gint i;
-
-        ovector = pcre2_get_ovector_pointer(match_data);
-
-        /* Token is the string from pos to the start of the match: */
-        g_ptr_array_add(tokens, g_strndup(string + pos, ovector[0] - pos));
-
-        /* Also return any substring matches: */
-        for (i = 1; i < status; i++) {
-            PCRE2_SIZE start = ovector[2 * i];
-            PCRE2_SIZE end   = ovector[2 * i + 1];
-
-            /* end == start means an empty match, which we ignore;
-             * end < start is possible if the pattern included \K,
-             * which we also ignore, although perhaps we shouldn't */
-            if (end > start)
-                g_ptr_array_add(tokens, g_strndup(string + start, end - start));
-        }
-
-        /* Avoid an infinite loop: */
-        if (ovector[1] > pos)
-            pos = ovector[1];
-        else
-            pos = g_utf8_next_char(string + pos) - string;
-    }
-    pcre2_match_data_free(match_data);
-
-    if (status != PCRE2_ERROR_NOMATCH) {
-        g_ptr_array_free(tokens, TRUE);
-        return NULL;
-    }
-
-    /* Last token is the remainder of the string */
-    g_ptr_array_add(tokens, g_strdup(string + pos));
-    g_ptr_array_add(tokens, NULL);
-
-    return (gchar **) g_ptr_array_free(tokens, FALSE);
-}
-
 /*
  * libbalsa_match_data_fetch_pos:
  * match_data: LibBalsaMatchData structure
diff --git a/libbalsa/regex.h b/libbalsa/regex.h
index 6541a5b2d..67fca8603 100644
--- a/libbalsa/regex.h
+++ b/libbalsa/regex.h
@@ -47,9 +47,6 @@ gboolean       libbalsa_regex_match_simple  (const gchar         *pattern,
                                              const gchar         *string,
                                              guint                compile_options,
                                              guint                match_options);
-gchar        **libbalsa_regex_split         (const LibBalsaRegex *regex,
-                                             const gchar         *string,
-                                             guint                options);
 gboolean       libbalsa_match_data_fetch_pos(LibBalsaMatchData   *match_data,
                                              gint                 match_num,
                                              gint                *start_pos,


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