]> Nishi Git Mirror - libw3.git/commitdiff
comment support for the parser
authornishi <nishi@d27a3e52-49c5-7645-884c-6793ebffc270>
Tue, 30 Jan 2024 01:53:43 +0000 (01:53 +0000)
committernishi <nishi@d27a3e52-49c5-7645-884c-6793ebffc270>
Tue, 30 Jan 2024 01:53:43 +0000 (01:53 +0000)
git-svn-id: file:///raid/svn-main/nishi-libw3/trunk@138 d27a3e52-49c5-7645-884c-6793ebffc270

Library/Tag.c

index 859024e24121739826a396c658d506e1051e1349..42249bb7241d28cd294ad4078fb635ff2db725ef 100644 (file)
@@ -23,8 +23,21 @@ void W3_Tag_Parse(char* data, size_t size, void (*tagfunc)(char* tagname, char*
        char* text = malloc(1);
        text[0] = 0;
        bool dq = false;
+       int incr = 0;
+       bool comm = true;
+       bool comm_on = false;
+       int abc = 0;
        for(i = 0; i < size; i++) {
                if(phase == 1 && data[i] != ' ' && data[i] != '>') {
+                       if(comm) {
+                               if(incr == 0 && data[i] != '!') comm = false;
+                               if(incr == 1 && data[i] != '-') comm = false;
+                               if(incr == 2 && data[i] != '-') comm = false;
+                               if(comm && incr == 2) {
+                                       comm_on = true;
+                               }
+                               incr++;
+                       }
                        cbuf[0] = data[i];
                        char* tmp = tagn;
                        tagn = __W3_Concat(tmp, cbuf);
@@ -38,7 +51,7 @@ void W3_Tag_Parse(char* data, size_t size, void (*tagfunc)(char* tagname, char*
                }
                if(phase == 0 && data[i] == '<') {
                        if(strlen(text) > 0) {
-                               textfunc(text);
+                               if(!comm_on) textfunc(text);
                        }
                        free(text);
                        text = malloc(1);
@@ -47,6 +60,8 @@ void W3_Tag_Parse(char* data, size_t size, void (*tagfunc)(char* tagname, char*
                        free(tagn);
                        tagn = malloc(1);
                        tagn[0] = 0;
+                       comm = true;
+                       incr = 0;
                } else if(phase == 0) {
                        cbuf[0] = data[i];
                        char* tmp = text;
@@ -59,13 +74,23 @@ void W3_Tag_Parse(char* data, size_t size, void (*tagfunc)(char* tagname, char*
                                attr = malloc(1);
                                attr[0] = 0;
                        } else if(data[i] == '>') {
-                               tagfunc(tagn, NULL);
+                               if(!comm_on) tagfunc(tagn, NULL);
                                phase = 0;
                        }
                } else if(phase == 2 && data[i] == '>') {
-                       tagfunc(tagn, attr);
+                       if(!comm_on) tagfunc(tagn, attr);
                        phase = 0;
                }
+               if(data[i] == '-' && abc == 0) {
+                       abc = 1;
+               } else if(data[i] == '-' && abc == 1) {
+                       abc = 2;
+               } else if(data[i] == '>' && abc == 2) {
+                       abc = 0;
+                       comm_on = false;
+               } else {
+                       abc = 0;
+               }
        }
        free(text);
        free(attr);