[gtksourceview] implregex: make fetch() closer to gregex



commit c775eafd43650895c1d782e59d526b1ff258c3c6
Author: Christian Hergert <chergert redhat com>
Date:   Fri Jul 2 14:31:57 2021 -0700

    implregex: make fetch() closer to gregex

 gtksourceview/implregex.c | 19 +++++++++----------
 1 file changed, 9 insertions(+), 10 deletions(-)
---
diff --git a/gtksourceview/implregex.c b/gtksourceview/implregex.c
index e3edc094..92d55226 100644
--- a/gtksourceview/implregex.c
+++ b/gtksourceview/implregex.c
@@ -345,6 +345,7 @@ char *
 impl_match_info_fetch (const ImplMatchInfo *match_info,
                        int                  match_num)
 {
+       char *match = NULL;
        int begin =  -1;
        int end =  -1;
 
@@ -352,18 +353,16 @@ impl_match_info_fetch (const ImplMatchInfo *match_info,
        g_return_val_if_fail (match_info->string != NULL, NULL);
        g_return_val_if_fail (match_info->offsets != NULL, NULL);
        g_return_val_if_fail (impl_match_info_matches (match_info), NULL);
+       g_return_val_if_fail (match_num >= 0, NULL);
 
-       if (impl_match_info_fetch_pos (match_info, match_num, &begin, &end))
-       {
-               if (begin >= 0 && end >= 0)
-               {
-                       return g_strndup (match_info->string + begin, end - begin);
-               }
-
-               return g_strdup ("");
-       }
+       if (!impl_match_info_fetch_pos (match_info, match_num, &begin, &end))
+               match = NULL;
+       else if (begin == -1)
+               match = g_strdup ("");
+       else
+               match = g_strndup (&match_info->string[begin], end - begin);
 
-       return NULL;
+       return match;
 }
 
 char *


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