Overpass API regression suite coverage (Saxony) / expat/expat_justparse_interface.h

expat/expat_justparse_interface.h

45 of 52 instrumented lines run by the suite (86.5%) at 8edf11b0419c (this file on GitHub).

runnever runcolumns: line, executions, queries (click for the queries that run the line)

1/** Copyright 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018 Roland Olbricht et al.
2 *
3 * This file is part of Overpass_API.
4 *
5 * Overpass_API is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU Affero General Public License as
7 * published by the Free Software Foundation, either version 3 of the
8 * License, or (at your option) any later version.
9 *
10 * Overpass_API is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU Affero General Public License
16 * along with Overpass_API. If not, see <http://www.gnu.org/licenses/>.
17 */
19#ifndef DE__OSM3S___EXPAT__EXPAT_JUSTPARSE_INTERFACE_H
20#define DE__OSM3S___EXPAT__EXPAT_JUSTPARSE_INTERFACE_H
22#include <string>
24#include <string.h>
25#include <stdio.h>
26#include <time.h>
27#include <expat.h>
29#ifdef XML_LARGE_SIZE
30#if defined(XML_USE_MSC_EXTENSIONS) && _MSC_VER < 1400
31#define XML_FMT_INT_MOD "I64"
32#else
33#define XML_FMT_INT_MOD "ll"
34#endif
35#else
36#define XML_FMT_INT_MOD "l"
37#endif
39328 q#define BUFFSIZE 8192
42typedef unsigned int uint;
44struct Parse_Error
4641 q Parse_Error(std::string s) : message(s) {}
47 std::string message;
48};
50struct Script_Parser
522768692 q Script_Parser() : p(XML_ParserCreate(NULL)), parser_online(true)
532768692 q {
542768692 q if (!p)
550 throw Parse_Error("Couldn't allocate memory for parser.");
562768692 q }
58 ~Script_Parser()
590 {
600 XML_ParserFree(p);
610 }
63 void parse(const std::string& input,
64 void (*start)(const char*, const char**),
65 void (*end)(const char*))
66328 q {
67328 q working_start = start;
68328 q working_end = end;
70328 q XML_SetElementHandler(p, expat_wrapper_start, expat_wrapper_end);
71328 q XML_SetCharacterDataHandler(p, expat_wrapper_text);
72328 q XML_SetUserData(p, this);
74328 q int done(0);
75328 q int len(input.size());
76328 q int pos(0);
77608 q while ((!done) && (pos < len))
78328 q {
79328 q int buff_len(len - pos);
80328 q if (buff_len > BUFFSIZE-1)
810 buff_len = BUFFSIZE-1;
82328 q strcpy(Buff, input.substr(pos, buff_len).c_str());
83328 q pos += buff_len;
85328 q if (XML_Parse(p, Buff, buff_len, done) == XML_STATUS_ERROR)
8641 q throw Parse_Error(XML_ErrorString(XML_GetErrorCode(p)));
87328 q }
89287 q parser_online = false;
90287 q }
92 int current_line_number()
932048 q {
942048 q if (parser_online)
952048 q return (XML_GetCurrentLineNumber(p));
960 else
970 return -1;
982048 q }
100 static void XMLCALL expat_wrapper_start
101 (void *data, const char *el, const char **attr)
1022008 q {
1032008 q ((Script_Parser*)data)->working_start(el, attr);
1042008 q }
106 static void XMLCALL expat_wrapper_end
107 (void *data, const char *el)
1081967 q {
1091967 q ((Script_Parser*)data)->working_end(el);
1101967 q }
112 static void XMLCALL expat_wrapper_text
113 (void *userData, const XML_Char *s, int len)
1144088 q {
1154088 q ((Script_Parser*)userData)->result_buf.append(s, len);
1164088 q }
118 std::string get_parsed_text()
1193968 q {
1203968 q return result_buf;
1213968 q }
123 void reset_parsed_text()
1243688 q {
1253688 q result_buf = "";
1263688 q }
128private:
129 XML_Parser p;
130 bool parser_online;
131 std::string result_buf;
133 void (*working_start)(const char*, const char**);
134 void (*working_end)(const char*);
136 //for the XMLParser
137 char Buff[BUFFSIZE];
138};
140void parse(FILE* in,
141 void (*start)(const char*, const char**),
142 void (*end)(const char*),
143 void (*text_handler)(void *data, const XML_Char *s, int len) = 0);
145XML_Parser get_current_parser();
147#endif