Fix bug #21: False positive: Opening slanted double-quote, followed by single slanted quote, should be accepted by BL
6 #include "testcaseparser.h"
9 * Get the flag (the string of characters which bracket tags in test cases).
11 const char *testcase_parser_get_flag(TestcaseParser *parser)
13 char *s=parser->contents;
16 parser->flag=g_string_new(NULL);
17 while(*s>' ' && *s<='~')
18 g_string_append_c(parser->flag,*s++);
20 return parser->flag->str;
24 * Test if the parser has reached the end of the input file
26 gboolean testcase_parser_at_eof(TestcaseParser *parser)
28 return !parser->contents[parser->pos];
32 * Get the next tag (and its associated text, if any) from a test case.
33 * Returns: TRUE if successful and FALSE if no more valid tags are present.
34 * Callers can call testcase_parser_at_eof() when testcase_parser_get_next_tag()
35 * to distinguish EOF and text which isn't a valid tag.
37 gboolean testcase_parser_get_next_tag(TestcaseParser *parser,const char **tag,
45 g_free(parser->tag_text);
46 parser->tag_text=NULL;
47 (void)testcase_parser_get_flag(parser);
48 if (strncmp(parser->contents+parser->pos,parser->flag->str,
51 eol=strchr(parser->contents+parser->pos,'\n');
54 endp=eol-parser->flag->len;
55 if (strncmp(endp,parser->flag->str,parser->flag->len))
57 while(endp>parser->contents && g_ascii_isspace(endp[-1]))
59 parser->pos+=parser->flag->len;
60 while(g_ascii_isspace(parser->contents[parser->pos]))
62 parser->tag=g_strndup(parser->contents+parser->pos,
63 endp-(parser->contents+parser->pos));
64 parser->pos=eol-parser->contents+1;
65 string=g_string_new(NULL);
66 while (!testcase_parser_at_eof(parser) &&
67 strncmp(parser->contents+parser->pos,parser->flag->str,parser->flag->len))
69 eol=strchr(parser->contents+parser->pos,'\n');
71 n=eol-(parser->contents+parser->pos)+1;
73 n=strlen(parser->contents+parser->pos);
74 g_string_append_len(string,parser->contents+parser->pos,n);
77 parser->tag_text=g_string_free(string,FALSE);
78 if (!parser->tag_text)
79 parser->tag_text=g_strdup("");
83 *text=parser->tag_text;
88 * Create a testcase parser to read a regular file.
90 TestcaseParser *testcase_parser_new_from_file(const char *filename)
92 TestcaseParser *parser;
95 parser=g_new0(TestcaseParser,1);
96 if (!file_get_contents_text(filename,&parser->contents,&len,&err))
98 g_printerr("%s: %s\n",filename,err->message);
103 if (!g_utf8_validate(parser->contents,len,NULL))
105 g_printerr("%s: Does not contain valid UTF-8\n",filename);
106 g_free(parser->contents);
110 parser->filename=g_strdup(filename);
115 * Free a testcase parser.
117 void testcase_parser_free(TestcaseParser *parser)
119 g_free(parser->filename);
120 g_free(parser->contents);
122 g_string_free(parser->flag,TRUE);
124 g_free(parser->tag_text);