]> saetta.ns0.it Git - libzakgorg/commitdiff
Use of regex to find header or not.
authorAndrea Zagli <azagli@libero.it>
Sat, 3 Aug 2019 08:23:09 +0000 (10:23 +0200)
committerAndrea Zagli <azagli@libero.it>
Sat, 3 Aug 2019 08:23:09 +0000 (10:23 +0200)
src/parser.c
tests/simple.org

index ace8ce68b653f1c63beaf583753520269bcbb54c..f0d6d237195bf53463a44d59a87a034c9490999a 100644 (file)
@@ -217,7 +217,8 @@ zak_gorg_parser_parse (ZakGorgParser *zak_gorg_parser)
        GNode *root;
        GNode *cur;
 
-       GRegex *regex;
+       GRegex *regex_header;
+       GRegex *regex_tags;
        GMatchInfo *match_info;
        gint rx_start;
        gint rx_end;
@@ -262,7 +263,8 @@ zak_gorg_parser_parse (ZakGorgParser *zak_gorg_parser)
 
        gchar *str = buffer;
 
-       regex = g_regex_new (":[^ .]*:$", 0, 0, NULL);
+       regex_header = g_regex_new ("[*]+ ", 0, 0, NULL);
+       regex_tags = g_regex_new (":[^ .]*:$", 0, 0, NULL);
 
        root = g_node_get_root (zak_gorg_parser->nodes);
 
@@ -278,9 +280,7 @@ zak_gorg_parser_parse (ZakGorgParser *zak_gorg_parser)
                                        g_printf ("%d: %s\n", line, strline);
                                        start = i + 1;
 
-                                       g_regex_match (regex, strline, 0, &match_info);
-
-                                       if (strline[0] != '*')
+                                       if (!g_regex_match (regex_header, strline, 0, &match_info))
                                                {
                                                        Header *h = (Header *)cur->data;
                                                        if (h->body == NULL)
@@ -302,6 +302,8 @@ zak_gorg_parser_parse (ZakGorgParser *zak_gorg_parser)
                                                                                }
                                                                }
 
+                                                       g_regex_match (regex_tags, strline, 0, &match_info);
+
                                                        rx_start = 0;
                                                        h->tags = g_match_info_fetch (match_info, 0);
                                                        if (h->tags != NULL)
@@ -355,5 +357,6 @@ zak_gorg_parser_parse (ZakGorgParser *zak_gorg_parser)
        g_object_unref (ginfo);
        g_object_unref (giostream);
 
-       g_regex_unref (regex);
+       g_regex_unref (regex_header);
+       g_regex_unref (regex_tags);
 }
index 3e70bf813f623070b034d8f6d0c675eea8c972ef..0f26f8835aa53dd232b77ed03818ac38661bbb56 100644 (file)
@@ -9,3 +9,7 @@ body with no space
 * third line                                                     :third:line:
 ** sub 1 :third (no tag): line
 *** sub 1 sub 1 third line
+* no space
+**pippolo
+**asasasa
+body body asasas