31 #ifndef QUERY_CONTAINER_HPP_ 32 #define QUERY_CONTAINER_HPP_ 39 #include "../Helper/Container.hpp" 40 #include "../Helper/Json.hpp" 41 #include "../Helper/Memory.hpp" 42 #include "../Main/Exception.hpp" 43 #include "../Parsing/XML.hpp" 44 #include "../Struct/QueryProperties.hpp" 45 #include "../Struct/QueryStruct.hpp" 47 #include "../_extern/jsoncons/include/jsoncons/json.hpp" 48 #include "../_extern/jsoncons/include/jsoncons_ext/jsonpath/json_query.hpp" 49 #include "../_extern/rapidjson/include/rapidjson/document.h" 90 using XPathJsonPointer = std::pair<XPath, JsonPointer>;
91 using XPathJsonPath = std::pair<XPath, JsonPath>;
158 void setQueryTarget(
const std::string& content,
const std::string& source);
165 bool getXml(std::string& resultTo, std::queue<std::string>& warningsTo);
212 const std::string& target,
214 std::queue<std::string>& warningsTo
218 const std::string& target,
219 std::string& resultTo,
220 std::queue<std::string>& warningsTo
224 const std::string& target,
225 std::vector<std::string>& resultTo,
226 std::queue<std::string>& warningsTo
231 std::queue<std::string>& warningsTo
236 std::queue<std::string>& warningsTo
240 std::string& resultTo,
241 std::queue<std::string>& warningsTo
245 std::string& resultTo,
246 std::queue<std::string>& warningsTo
250 std::vector<std::string>& resultTo,
251 std::queue<std::string>& warningsTo
255 std::vector<std::string>& resultTo,
256 std::queue<std::string>& warningsTo
260 std::queue<std::string>& warningsTo
264 std::queue<std::string>& warningsTo
277 std::vector<RegEx> queriesRegEx;
278 std::vector<XPath> queriesXPath;
279 std::vector<JsonPointer> queriesJsonPointer;
280 std::vector<JsonPath> queriesJsonPath;
281 std::vector<XPathJsonPointer> queriesXPathJsonPointer;
282 std::vector<XPathJsonPath> queriesXPathJsonPath;
285 std::vector<std::uint64_t> queriesId;
286 mutable std::mutex queriesIdLock;
289 bool repairCData{
true};
290 bool repairComments{
true};
291 bool removeXmlInstructions{
false};
292 bool minimizeMemory{
false};
295 const std::string * queryTargetPtr{
nullptr};
296 const std::string * queryTargetSourcePtr{
nullptr};
297 bool xmlParsed{
false};
298 bool jsonParsedRapid{
false};
299 bool jsonParsedCons{
false};
301 rapidjson::Document parsedJsonRapid;
302 jsoncons::json parsedJsonCons;
303 std::string xmlParsingError;
304 std::string jsonParsingError;
308 std::size_t subSetNumber{} ;
309 std::size_t subSetCurrent{};
310 bool subSetXmlParsed{
false};
311 bool subSetJsonParsedRapid{
false};
312 bool subSetJsonParsedCons{
false};
314 rapidjson::Document subSetParsedJsonRapid;
315 jsoncons::json subSetParsedJsonCons;
316 std::string subSetXmlParsingError;
317 std::string subSetJsonParsingError;
320 std::vector<Parsing::XML> xPathSubSets;
321 std::vector<rapidjson::Document> jsonPointerSubSets;
322 std::vector<jsoncons::json> jsonPathSubSets;
324 std::vector<std::string> stringifiedSubSets;
327 bool parseXml(std::queue<std::string>& warningsTo);
328 bool parseJsonRapid(std::queue<std::string>& warningsTo);
329 bool parseJsonCons(std::queue<std::string>& warningsTo);
330 bool parseSubSetXml(std::queue<std::string>& warningsTo);
331 bool parseSubSetJsonRapid(std::queue<std::string>& warningsTo);
332 bool parseSubSetJsonCons(std::queue<std::string>& warningsTo);
333 void resetSubSetParsingState();
336 void stringifySubSets(std::queue<std::string>& warningsTo);
337 void insertSubSets(std::vector<std::string>& subsets);
338 void insertSubSets(std::vector<Parsing::XML>& subsets);
339 void insertSubSets(std::vector<jsoncons::json>& subsets);
340 void insertSubSets(std::vector<rapidjson::Document>& subsets);
358 std::lock_guard<std::mutex> idLock(this->queriesIdLock);
361 this->queriesId.cbegin(),
362 this->queriesId.cend(),
364 ) != this->queriesId.cend();
377 this->repairCData = isRepairCData;
386 this->repairComments = isRepairComments;
395 this->removeXmlInstructions = isRemoveXmlInstructions;
408 this->minimizeMemory = isMinimizeMemory;
429 this->parsedXML.
setOptions(warnings, numOfErrors);
430 this->subSetParsedXML.
setOptions(warnings, numOfErrors);
454 const std::string& content,
455 const std::string& source
461 this->queryTargetPtr = &content;
462 this->queryTargetSourcePtr = &source;
476 return this->subSetNumber;
495 if(this->queryTargetPtr !=
nullptr) {
496 targetTo = *(this->queryTargetPtr);
522 if(this->parseXml(warningsTo)) {
528 if(warningsTo.empty()) {
531 + this->xmlParsingError
533 + *(this->queryTargetSourcePtr)
576 if(!properties.
text.empty()) {
577 if(properties.
type ==
"regex") {
579 newQuery.
index = this->queriesRegEx.size();
582 this->queriesRegEx.emplace_back(
592 + std::string(e.
view())
599 else if(properties.
type ==
"xpath") {
601 newQuery.
index = this->queriesXPath.size();
604 this->queriesXPath.emplace_back(
612 + std::string(e.
view())
618 else if(properties.
type ==
"jsonpointer") {
620 newQuery.
index = this->queriesJsonPointer.size();
623 this->queriesJsonPointer.emplace_back(
631 + std::string(e.
view())
637 else if(properties.
type ==
"jsonpath") {
639 newQuery.
index = this->queriesJsonPath.size();
642 this->queriesJsonPath.emplace_back(
650 + std::string(e.
view())
656 else if(properties.
type ==
"xpathjsonpointer") {
658 newQuery.
index = this->queriesXPathJsonPointer.size();
661 const auto splitPos{properties.
text.find(
'\n')};
662 const std::string xPathQuery(
667 std::string jsonQuery;
670 splitPos != std::string::npos
671 && properties.
text.size() > splitPos + 1
673 jsonQuery = properties.
text.substr(splitPos + 1);
677 this->queriesXPathJsonPointer.emplace_back(
678 XPath(xPathQuery,
true),
685 + std::string(e.
view())
691 + std::string(e.
view())
698 else if(properties.
type ==
"xpathjsonpath") {
700 newQuery.
index = this->queriesXPathJsonPath.size();
703 const auto splitPos{properties.
text.find(
'\n')};
704 const std::string xPathQuery(
709 std::string jsonQuery;
712 splitPos != std::string::npos
713 && properties.
text.size() > splitPos + 1
715 jsonQuery = properties.
text.substr(splitPos + 1);
719 this->queriesXPathJsonPath.emplace_back(
720 XPath(xPathQuery,
true),
727 + std::string(e.
view())
733 + std::string(e.
view())
741 "Query::Container::addQuery(): Unknown query type '" 750 std::lock_guard<std::mutex> lockIds(this->queriesIdLock);
752 this->queriesId.emplace_back(
id);
771 this->clearSubSets();
774 this->parsedXML.
clear();
780 this->xmlParsed =
false;
781 this->jsonParsedRapid =
false;
782 this->jsonParsedCons =
false;
789 this->queryTargetPtr =
nullptr;
790 this->queryTargetSourcePtr =
nullptr;
810 if(this->subSetNumber < this->subSetCurrent) {
812 "Query::Container::nextSubSet():" 813 " Invalid subset selected" 817 if(this->subSetNumber == this->subSetCurrent) {
822 if(this->subSetCurrent > 0) {
824 !(this->stringifiedSubSets.empty()),
825 this->stringifiedSubSets.at(this->subSetCurrent - 1)
828 switch(this->subSetType) {
830 this->xPathSubSets.at(
831 this->subSetCurrent - 1
838 this->jsonPointerSubSets.at(
839 this->subSetCurrent - 1
847 this->jsonPathSubSets.at(
848 this->subSetCurrent - 1
860 ++(this->subSetCurrent);
891 const std::string& target,
893 std::queue<std::string>& warningsTo
899 "WARNING: RegEx query is of invalid type - not RegEx." 906 "WARNING: RegEx query has invalid result type - not boolean." 910 else if(target.empty()) {
918 resultTo = this->queriesRegEx.at(query.
index).getBool(
926 "WARNING: RegEx error - " 927 + std::string(e.
view())
960 const std::string& target,
961 std::string& resultTo,
962 std::queue<std::string>& warningsTo
968 "WARNING: RegEx query is of invalid type - not RegEx." 975 "WARNING: RegEx query has invalid result type - not single." 979 else if(target.empty()) {
987 this->queriesRegEx.at(query.
index).getFirst(
996 "WARNING: RegEx error - " 997 + std::string(e.
view())
1030 const std::string& target,
1031 std::vector<std::string>& resultTo,
1032 std::queue<std::string>& warningsTo
1038 "WARNING: RegEx query is of invalid type - not RegEx." 1045 "WARNING: RegEx query has invalid result type - not multi." 1049 else if(target.empty()) {
1057 this->queriesRegEx.at(query.
index).getAll(
1066 "WARNING: RegEx error - " 1067 + std::string(e.
view())
1101 std::queue<std::string>& warningsTo
1104 if(this->queryTargetPtr ==
nullptr) {
1106 "Query::Container::getBoolFromQuery():" 1107 " No content specified" 1111 if(this->queryTargetSourcePtr ==
nullptr) {
1113 "Query::Container::getBoolFromQuery():" 1114 " No content source specified" 1121 "WARNING: Query has invalid result type - not boolean." 1128 if(this->queryTargetPtr->empty()) {
1134 switch(query.
type) {
1138 resultTo = this->queriesRegEx.at(query.
index).getBool(
1139 *(this->queryTargetPtr)
1146 "WARNING: RegEx error - " 1147 + std::string(e.
view())
1149 + *(this->queryTargetSourcePtr)
1158 if(this->parseXml(warningsTo)) {
1161 resultTo = this->queriesXPath.at(query.
index).getBool(
1169 "WARNING: XPath error - " 1170 + std::string(e.
view())
1172 + *(this->queryTargetSourcePtr)
1182 if(this->parseJsonRapid(warningsTo)) {
1185 resultTo = this->queriesJsonPointer.at(query.
index).getBool(
1186 this->parsedJsonRapid
1193 "WARNING: JSONPointer error - " 1194 + std::string(e.
view())
1196 + *(this->queryTargetSourcePtr)
1206 if(this->parseJsonCons(warningsTo)) {
1209 resultTo = this->queriesJsonPath.at(query.
index).getBool(
1210 this->parsedJsonCons
1217 "WARNING: JSONPath error - " 1218 + std::string(e.
view())
1220 + *(this->queryTargetSourcePtr)
1230 if(this->parseXml(warningsTo)) {
1235 this->queriesXPathJsonPointer.at(query.
index).first.getFirst(
1248 resultTo = this->queriesXPathJsonPointer.at(query.
index).second.getBool(
1257 "WARNING: XPath error - " 1258 + std::string(e.
view())
1260 + *(this->queryTargetSourcePtr)
1266 "WARNING: JSONPointer error - " 1267 + std::string(e.
view())
1269 + *(this->queryTargetSourcePtr)
1275 "WARNING: JSONPath error - " 1276 + std::string(e.
view())
1278 + *(this->queryTargetSourcePtr)
1288 if(this->parseXml(warningsTo)) {
1293 this->queriesXPathJsonPath.at(query.
index).first.getFirst(
1306 resultTo = this->queriesXPathJsonPath.at(query.
index).second.getBool(
1315 "WARNING: XPath error - " 1316 + std::string(e.
view())
1318 + *(this->queryTargetSourcePtr)
1324 "WARNING: JSONPath error - " 1325 + std::string(e.
view())
1327 + *(this->queryTargetSourcePtr)
1333 "WARNING: JSONPath error - " 1334 + std::string(e.
view())
1336 + *(this->queryTargetSourcePtr)
1349 "Query::Container::getBoolFromQuery():" 1350 " Unknown query type" 1381 std::queue<std::string>& warningsTo
1384 if(this->queryTargetSourcePtr ==
nullptr) {
1386 "Query::Container::getBoolFromQueryOnSubSet():" 1387 " No content source has been specified" 1392 if(this->subSetCurrent == 0) {
1394 "Query::Container::getBoolFromQueryOnSubSet():" 1395 " No subset has been specified" 1399 if(this->subSetCurrent > this->subSetNumber) {
1401 "Query::Container::getBoolFromQueryOnSubSet():" 1402 " Invalid subset has been specified" 1409 "WARNING: Query has invalid result type - not boolean." 1415 switch(query.
type) {
1420 this->stringifySubSets(warningsTo);
1423 resultTo = this->queriesRegEx.at(query.
index).getBool(
1424 this->stringifiedSubSets.at(this->subSetCurrent - 1)
1431 "WARNING: RegEx error - " 1432 + std::string(e.
view())
1434 + *(this->queryTargetSourcePtr)
1443 if(this->parseSubSetXml(warningsTo)) {
1447 resultTo = this->queriesXPath.at(query.
index).getBool(
1448 this->xPathSubSets.at(this->subSetCurrent - 1)
1452 resultTo = this->queriesXPath.at(query.
index).getBool(
1453 this->subSetParsedXML
1461 "WARNING: XPath error - " 1462 + std::string(e.
view())
1464 + *(this->queryTargetSourcePtr)
1474 if(this->parseSubSetJsonRapid(warningsTo)) {
1478 resultTo = this->queriesJsonPointer.at(query.
index).getBool(
1479 this->jsonPointerSubSets.at(this->subSetCurrent - 1)
1483 resultTo = this->queriesJsonPointer.at(query.
index).getBool(
1484 this->subSetParsedJsonRapid
1492 "WARNING: JSONPointer error - " 1493 + std::string(e.
view())
1495 + *(this->queryTargetSourcePtr)
1505 if(this->parseSubSetJsonRapid(warningsTo)) {
1509 resultTo = this->queriesJsonPath.at(query.
index).getBool(
1510 this->jsonPathSubSets.at(this->subSetCurrent - 1)
1514 resultTo = this->queriesJsonPath.at(query.
index).getBool(
1515 this->subSetParsedJsonCons
1523 "WARNING: JSONPath error - " 1524 + std::string(e.
view())
1526 + *(this->queryTargetSourcePtr)
1536 if(this->parseSubSetXml(warningsTo)) {
1542 this->queriesXPathJsonPointer.at(query.
index).first.getFirst(
1543 this->xPathSubSets.at(this->subSetCurrent - 1),
1548 this->queriesXPathJsonPointer.at(query.
index).first.getFirst(
1549 this->subSetParsedXML,
1562 resultTo = this->queriesXPathJsonPointer.at(query.
index).second.getBool(
1571 "WARNING: XPath error - " 1572 + std::string(e.
view())
1574 + *(this->queryTargetSourcePtr)
1580 "WARNING: JSONPointer error - " 1581 + std::string(e.
view())
1583 + *(this->queryTargetSourcePtr)
1589 "WARNING: JSONPath error - " 1590 + std::string(e.
view())
1592 + *(this->queryTargetSourcePtr)
1602 if(this->parseSubSetXml(warningsTo)) {
1608 this->queriesXPathJsonPath.at(query.
index).first.getFirst(
1609 this->xPathSubSets.at(this->subSetCurrent - 1),
1614 this->queriesXPathJsonPath.at(query.
index).first.getFirst(
1615 this->subSetParsedXML,
1628 resultTo = this->queriesXPathJsonPath.at(query.
index).second.getBool(
1637 "WARNING: XPath error - " 1638 + std::string(e.
view())
1640 + *(this->queryTargetSourcePtr)
1646 "WARNING: JSONPath error - " 1647 + std::string(e.
view())
1649 + *(this->queryTargetSourcePtr)
1655 "WARNING: JSONPath error - " 1656 + std::string(e.
view())
1658 + *(this->queryTargetSourcePtr)
1671 "Query::Container::getBoolFromQueryOnSubSet():" 1672 " Unknown query type" 1701 std::string& resultTo,
1702 std::queue<std::string>& warningsTo
1705 if(this->queryTargetPtr ==
nullptr) {
1707 "Query::Container::getSingleFromQuery():" 1708 " No content has been specified" 1712 if(this->queryTargetSourcePtr ==
nullptr) {
1714 "Query::Container::getSingleFromQuery():" 1715 " No content source has been specified" 1722 "WARNING: Query has invalid result type - not single." 1729 if(this->queryTargetPtr->empty()) {
1735 switch(query.
type) {
1739 this->queriesRegEx.at(query.
index).getFirst(
1740 *(this->queryTargetPtr),
1748 "WARNING: RegEx error - " 1749 + std::string(e.
view())
1751 + *(this->queryTargetSourcePtr)
1760 if(this->parseXml(warningsTo)) {
1763 this->queriesXPath.at(query.
index).getFirst(
1772 "WARNING: XPath error - " 1773 + std::string(e.
view())
1775 + *(this->queryTargetSourcePtr)
1785 if(this->parseJsonRapid(warningsTo)) {
1788 this->queriesJsonPointer.at(query.
index).getFirst(
1789 this->parsedJsonRapid,
1797 "WARNING: JSONPointer error - " 1798 + std::string(e.
view())
1800 + *(this->queryTargetSourcePtr)
1810 if(this->parseJsonCons(warningsTo)) {
1813 this->queriesJsonPath.at(query.
index).getFirst(
1814 this->parsedJsonCons,
1822 "WARNING: JSONPath error - " 1823 + std::string(e.
view())
1825 + *(this->queryTargetSourcePtr)
1835 if(this->parseXml(warningsTo)) {
1840 this->queriesXPathJsonPointer.at(query.
index).first.getFirst(
1853 this->queriesXPathJsonPointer.at(query.
index).second.getFirst(
1861 "WARNING: XPath error - " 1862 + std::string(e.
view())
1864 + *(this->queryTargetSourcePtr)
1870 "WARNING: JSONPointer error - " 1871 + std::string(e.
view())
1873 + *(this->queryTargetSourcePtr)
1879 "WARNING: JSONPath error - " 1880 + std::string(e.
view())
1882 + *(this->queryTargetSourcePtr)
1892 if(this->parseXml(warningsTo)) {
1897 this->queriesXPathJsonPath.at(query.
index).first.getFirst(
1913 this->queriesXPathJsonPath.at(query.
index).second.getFirst(
1922 "WARNING: JSONPath error - " 1923 + std::string(e.
view())
1925 + *(this->queryTargetSourcePtr)
1932 "WARNING: XPath error - " 1933 + std::string(e.
view())
1935 + *(this->queryTargetSourcePtr)
1941 "WARNING: JSONPath error - " 1942 + std::string(e.
view())
1944 + *(this->queryTargetSourcePtr)
1950 "WARNING: JSONPath error - " 1951 + std::string(e.
view())
1953 + *(this->queryTargetSourcePtr)
1965 throw Exception(
"Query::Container::getSingleFromQuery(): Unknown query type");
1994 std::string& resultTo,
1995 std::queue<std::string>& warningsTo
1998 if(this->queryTargetSourcePtr ==
nullptr) {
2000 "Query::Container::getSingleFromQueryOnSubSet():" 2001 " No content source has been specified" 2006 if(this->subSetCurrent == 0) {
2008 "Query::Container::getSingleFromQueryOnSubSet():" 2009 " No subset has been specified" 2013 if(this->subSetCurrent > this->subSetNumber) {
2015 "Query::Container::getSingleFromQueryOnSubSet():" 2016 " Invalid subset has been specified" 2026 "WARNING: Query has invalid result type - not single." 2032 switch(query.
type) {
2037 this->stringifySubSets(warningsTo);
2040 this->queriesRegEx.at(query.
index).getFirst(
2041 this->stringifiedSubSets.at(this->subSetCurrent - 1),
2049 "WARNING: RegEx error - " 2050 + std::string(e.
view())
2052 + *(this->queryTargetSourcePtr)
2061 if(this->parseSubSetXml(warningsTo)) {
2065 this->queriesXPath.at(query.
index).getFirst(
2066 this->xPathSubSets.at(this->subSetCurrent - 1),
2071 this->queriesXPath.at(query.
index).getFirst(
2072 this->subSetParsedXML,
2081 "WARNING: XPath error - " 2082 + std::string(e.
view())
2084 + *(this->queryTargetSourcePtr)
2094 if(this->parseSubSetJsonRapid(warningsTo)) {
2098 this->queriesJsonPointer.at(query.
index).getFirst(
2099 this->jsonPointerSubSets.at(this->subSetCurrent - 1),
2104 this->queriesJsonPointer.at(query.
index).getFirst(
2105 this->subSetParsedJsonRapid,
2114 "WARNING: JSONPointer error - " 2115 + std::string(e.
view())
2117 + *(this->queryTargetSourcePtr)
2127 if(this->parseSubSetJsonRapid(warningsTo)) {
2131 this->queriesJsonPath.at(query.
index).getFirst(
2132 this->jsonPathSubSets.at(this->subSetCurrent - 1),
2137 this->queriesJsonPath.at(query.
index).getFirst(
2138 this->subSetParsedJsonCons,
2147 "WARNING: JSONPath error - " 2148 + std::string(e.
view())
2150 + *(this->queryTargetSourcePtr)
2160 if(this->parseSubSetXml(warningsTo)) {
2166 this->queriesXPathJsonPointer.at(query.
index).first.getFirst(
2167 this->xPathSubSets.at(this->subSetCurrent - 1),
2172 this->queriesXPathJsonPointer.at(query.
index).first.getFirst(
2173 this->subSetParsedXML,
2186 this->queriesXPathJsonPointer.at(query.
index).second.getFirst(
2196 "WARNING: XPath error - " 2197 + std::string(e.
view())
2199 + *(this->queryTargetSourcePtr)
2205 "WARNING: JSONPointer error - " 2206 + std::string(e.
view())
2208 + *(this->queryTargetSourcePtr)
2214 "WARNING: JSONPath error - " 2215 + std::string(e.
view())
2217 + *(this->queryTargetSourcePtr)
2227 if(this->parseSubSetXml(warningsTo)) {
2233 this->queriesXPathJsonPath.at(query.
index).first.getFirst(
2234 this->xPathSubSets.at(this->subSetCurrent - 1),
2239 this->queriesXPathJsonPath.at(query.
index).first.getFirst(
2240 this->subSetParsedXML,
2253 this->queriesXPathJsonPath.at(query.
index).second.getFirst(
2263 "WARNING: XPath error - " 2264 + std::string(e.
view())
2266 + *(this->queryTargetSourcePtr)
2272 "WARNING: JSONPath error - " 2273 + std::string(e.
view())
2275 + *(this->queryTargetSourcePtr)
2281 "WARNING: JSONPath error - " 2282 + std::string(e.
view())
2284 + *(this->queryTargetSourcePtr)
2297 "Query::Container::getSingleFromQueryOnSubSet():" 2298 " Unknown query type" 2327 std::vector<std::string>& resultTo,
2328 std::queue<std::string>& warningsTo
2331 if(this->queryTargetPtr ==
nullptr) {
2333 "Query::Container::getMultiFromQuery():" 2334 " No content has been specified" 2338 if(this->queryTargetSourcePtr ==
nullptr) {
2340 "Query::Container::getMultiFromQuery():" 2341 " No content source has been specified" 2348 "WARNING: Query has invalid result type - not multi." 2355 if(this->queryTargetPtr->empty()) {
2361 switch(query.
type) {
2365 this->queriesRegEx.at(query.
index).getAll(
2366 *(this->queryTargetPtr),
2374 "WARNING: RegEx error - " 2375 + std::string(e.
view())
2377 + *(this->queryTargetSourcePtr)
2386 if(this->parseXml(warningsTo)) {
2389 this->queriesXPath.at(query.
index).getAll(this->parsedXML, resultTo);
2395 "WARNING: XPath error - " 2396 + std::string(e.
view())
2398 + *(this->queryTargetSourcePtr)
2408 if(this->parseJsonRapid(warningsTo)) {
2411 this->queriesJsonPointer.at(query.
index).getAll(this->parsedJsonRapid, resultTo);
2417 "WARNING: JSONPointer error - " 2418 + std::string(e.
view())
2420 + *(this->queryTargetSourcePtr)
2430 if(this->parseJsonCons(warningsTo)) {
2433 this->queriesJsonPath.at(query.
index).getAll(
2434 this->parsedJsonCons,
2442 "WARNING: JSONPath error - " 2443 + std::string(e.
view())
2445 + *(this->queryTargetSourcePtr)
2455 if(this->parseXml(warningsTo)) {
2460 this->queriesXPathJsonPointer.at(query.
index).first.getFirst(
2473 this->queriesXPathJsonPointer.at(query.
index).second.getAll(
2483 "WARNING: XPath error - " 2484 + std::string(e.
view())
2486 + *(this->queryTargetSourcePtr)
2492 "WARNING: JSONPointer error - " 2493 + std::string(e.
view())
2495 + *(this->queryTargetSourcePtr)
2501 "WARNING: JSONPath error - " 2502 + std::string(e.
view())
2504 + *(this->queryTargetSourcePtr)
2514 if(this->parseXml(warningsTo)) {
2519 this->queriesXPathJsonPath.at(query.
index).first.getFirst(
2532 this->queriesXPathJsonPath.at(query.
index).second.getAll(
2542 "WARNING: XPath error - " 2543 + std::string(e.
view())
2545 + *(this->queryTargetSourcePtr)
2551 "WARNING: JSONPath error - " 2552 + std::string(e.
view())
2554 + *(this->queryTargetSourcePtr)
2560 "WARNING: JSONPath error - " 2561 + std::string(e.
view())
2563 + *(this->queryTargetSourcePtr)
2576 "Query::Container::getMultiFromQuery():" 2577 " Unknown query type" 2607 std::vector<std::string>& resultTo,
2608 std::queue<std::string>& warningsTo
2611 if(this->queryTargetSourcePtr ==
nullptr) {
2613 "Query::Container::getMultiFromQueryOnSubSet():" 2614 " No content source has been specified" 2619 if(this->subSetCurrent == 0) {
2621 "Query::Container::getMultiFromQueryOnSubSet():" 2622 " No subset has been specified" 2626 if(this->subSetCurrent > this->subSetNumber) {
2628 "Query::Container::getMultiFromQueryOnSubSet():" 2629 " Invalid subset has been specified" 2639 "WARNING: Query has invalid result type - not multi." 2645 switch(query.
type) {
2650 this->stringifySubSets(warningsTo);
2653 this->queriesRegEx.at(query.
index).getAll(
2654 this->stringifiedSubSets.at(this->subSetCurrent - 1),
2662 "WARNING: RegEx error - " 2663 + std::string(e.
view())
2665 + *(this->queryTargetSourcePtr)
2674 if(this->parseSubSetXml(warningsTo)) {
2678 this->queriesXPath.at(query.
index).getAll(
2679 this->xPathSubSets.at(this->subSetCurrent - 1),
2684 this->queriesXPath.at(query.
index).getAll(
2685 this->subSetParsedXML,
2694 "WARNING: XPath error - " 2695 + std::string(e.
view())
2697 + *(this->queryTargetSourcePtr)
2707 if(this->parseSubSetJsonRapid(warningsTo)) {
2711 this->queriesJsonPointer.at(query.
index).getAll(
2712 this->jsonPointerSubSets.at(this->subSetCurrent - 1),
2717 this->queriesJsonPointer.at(query.
index).getAll(
2718 this->subSetParsedJsonRapid,
2727 "WARNING: JSONPointer error - " 2728 + std::string(e.
view())
2730 + *(this->queryTargetSourcePtr)
2740 if(this->parseSubSetJsonRapid(warningsTo)) {
2744 this->queriesJsonPath.at(query.
index).getAll(
2745 this->jsonPathSubSets.at(this->subSetCurrent - 1),
2750 this->queriesJsonPath.at(query.
index).getAll(
2751 this->subSetParsedJsonCons,
2760 "WARNING: JSONPath error - " 2761 + std::string(e.
view())
2763 + *(this->queryTargetSourcePtr)
2773 if(this->parseSubSetXml(warningsTo)) {
2779 this->queriesXPathJsonPointer.at(query.
index).first.getFirst(
2780 this->xPathSubSets.at(this->subSetCurrent - 1),
2785 this->queriesXPathJsonPointer.at(query.
index).first.getFirst(
2786 this->subSetParsedXML,
2799 this->queriesXPathJsonPointer.at(query.
index).second.getAll(
2809 "WARNING: XPath error - " 2810 + std::string(e.
view())
2812 + *(this->queryTargetSourcePtr)
2818 "WARNING: JSONPointer error - " 2819 + std::string(e.
view())
2821 + *(this->queryTargetSourcePtr)
2827 "WARNING: JSONPath error - " 2828 + std::string(e.
view())
2830 + *(this->queryTargetSourcePtr)
2840 if(this->parseSubSetXml(warningsTo)) {
2846 this->queriesXPathJsonPath.at(query.
index).first.getFirst(
2847 this->xPathSubSets.at(this->subSetCurrent - 1),
2852 this->queriesXPathJsonPath.at(query.
index).first.getFirst(
2853 this->subSetParsedXML,
2866 this->queriesXPathJsonPath.at(query.
index).second.getAll(
2876 "WARNING: XPath error - " 2877 + std::string(e.
view())
2879 + *(this->queryTargetSourcePtr)
2885 "WARNING: JSONPath error - " 2886 + std::string(e.
view())
2888 + *(this->queryTargetSourcePtr)
2894 "WARNING: JSONPath error - " 2895 + std::string(e.
view())
2897 + *(this->queryTargetSourcePtr)
2910 "Query::Container::getMultiFromQueryOnSubSet():" 2911 " Unknown query type" 2942 std::queue<std::string>& warningsTo
2945 this->clearSubSets();
2948 switch(query.
type) {
2971 if(this->queryTargetPtr ==
nullptr) {
2973 "Query::Container::setSubSetsFromQuery():" 2974 " No content has been specified" 2978 if(this->queryTargetSourcePtr ==
nullptr) {
2980 "Query::Container::setSubSetsFromQuery():" 2981 " No content source has been specified" 2991 "WARNING: Query has invalid result type - not subsets." 2998 if(this->queryTargetPtr->empty()) {
3002 switch(query.
type) {
3006 this->queriesRegEx.at(query.
index).getAll(
3007 *(this->queryTargetPtr),
3008 this->stringifiedSubSets
3011 this->subSetNumber = this->stringifiedSubSets.size();
3017 "WARNING: RegEx error - " 3018 + std::string(e.
view())
3020 + *(this->queryTargetSourcePtr)
3029 if(this->parseXml(warningsTo)) {
3032 this->queriesXPath.at(query.
index).getSubSets(
3037 this->subSetNumber = this->xPathSubSets.size();
3043 "WARNING: XPath error - " 3044 + std::string(e.
view())
3046 + *(this->queryTargetSourcePtr)
3056 if(this->parseJsonRapid(warningsTo)) {
3059 this->queriesJsonPointer.at(query.
index).getSubSets(
3060 this->parsedJsonRapid,
3061 this->jsonPointerSubSets
3064 this->subSetNumber = this->jsonPointerSubSets.size();
3070 "WARNING: JSONPointer error - " 3071 + std::string(e.
view())
3073 + *(this->queryTargetSourcePtr)
3083 if(this->parseJsonCons(warningsTo)) {
3086 this->queriesJsonPath.at(query.
index).getSubSets(
3087 this->parsedJsonCons,
3088 this->jsonPathSubSets
3091 this->subSetNumber = this->jsonPathSubSets.size();
3097 "WARNING: JSONPath error - " 3098 + std::string(e.
view())
3100 + *(this->queryTargetSourcePtr)
3110 if(this->parseXml(warningsTo)) {
3115 this->queriesXPathJsonPointer.at(query.
index).first.getFirst(
3125 this->queriesXPathJsonPointer.at(query.
index).second.getSubSets(
3127 this->jsonPointerSubSets
3135 "WARNING: XPath error - " 3136 + std::string(e.
view())
3138 + *(this->queryTargetSourcePtr)
3144 "WARNING: JSONPointer error - " 3145 + std::string(e.
view())
3147 + *(this->queryTargetSourcePtr)
3153 "WARNING: JSONPath error - " 3154 + std::string(e.
view())
3156 + *(this->queryTargetSourcePtr)
3166 if(this->parseXml(warningsTo)) {
3171 this->queriesXPathJsonPath.at(query.
index).first.getFirst(
3181 this->queriesXPathJsonPath.at(query.
index).second.getSubSets(
3183 this->jsonPathSubSets
3191 "WARNING: XPath error - " 3192 + std::string(e.
view())
3194 + *(this->queryTargetSourcePtr)
3200 "WARNING: JSONPath error - " 3201 + std::string(e.
view())
3203 + *(this->queryTargetSourcePtr)
3209 "WARNING: JSONPath error - " 3210 + std::string(e.
view())
3212 + *(this->queryTargetSourcePtr)
3225 "Query::Container::setSubSetsFromQuery():" 3226 " Unknown query type" 3257 std::queue<std::string>& warningsTo
3260 if(this->queryTargetSourcePtr ==
nullptr) {
3262 "Query::Container::addSubSetsFromQueryOnSubSet():" 3263 " No content source has been specified" 3268 if(this->subSetCurrent == 0) {
3270 "Query::Container::addSubSetsFromQueryOnSubSet():" 3271 " No subset has been specified" 3275 if(this->subSetCurrent > this->subSetNumber) {
3277 "Query::Container::addSubSetsFromQueryOnSubSet():" 3278 " Invalid subset has been specified" 3288 "WARNING: Query has invalid result type - not subset." 3294 switch(query.
type) {
3300 this->stringifySubSets(warningsTo);
3304 std::vector<std::string> subsets;
3306 this->queriesRegEx.at(query.
index).getAll(
3307 this->stringifiedSubSets.at(this->subSetCurrent - 1),
3312 if(subsets.empty()) {
3317 this->insertSubSets(subsets);
3323 "WARNING: RegEx error - " 3324 + std::string(e.
view())
3326 + *(this->queryTargetSourcePtr)
3335 if(this->parseSubSetXml(warningsTo)) {
3338 std::vector<Parsing::XML> subsets;
3341 this->queriesXPath.at(query.
index).getSubSets(
3342 this->xPathSubSets.at(this->subSetCurrent - 1),
3347 this->queriesXPath.at(query.
index).getSubSets(
3348 this->subSetParsedXML,
3354 if(subsets.empty()) {
3359 this->insertSubSets(subsets);
3365 "WARNING: XPath error - " 3366 + std::string(e.
view())
3368 + *(this->queryTargetSourcePtr)
3378 if(this->parseSubSetJsonRapid(warningsTo)) {
3381 std::vector<rapidjson::Document> subsets;
3384 this->queriesJsonPointer.at(query.
index).getSubSets(
3385 this->jsonPointerSubSets.at(this->subSetCurrent - 1),
3390 this->queriesJsonPointer.at(query.
index).getSubSets(
3391 this->subSetParsedJsonRapid,
3397 if(subsets.empty()) {
3402 this->insertSubSets(subsets);
3408 "WARNING: JSONPointer error - " 3409 + std::string(e.
view())
3411 + *(this->queryTargetSourcePtr)
3421 if(this->parseSubSetJsonRapid(warningsTo)) {
3424 std::vector<jsoncons::json> subsets;
3427 this->queriesJsonPath.at(query.
index).getSubSets(
3428 this->jsonPathSubSets.at(this->subSetCurrent - 1),
3433 this->queriesJsonPath.at(query.
index).getSubSets(
3434 this->subSetParsedJsonCons,
3440 if(subsets.empty()) {
3445 this->insertSubSets(subsets);
3451 "WARNING: JSONPath error - " 3452 + std::string(e.
view())
3454 + *(this->queryTargetSourcePtr)
3464 if(this->parseSubSetXml(warningsTo)) {
3470 this->queriesXPathJsonPointer.at(query.
index).first.getFirst(
3471 this->xPathSubSets.at(this->subSetCurrent - 1),
3476 this->queriesXPathJsonPointer.at(query.
index).first.getFirst(
3477 this->subSetParsedXML,
3490 std::vector<rapidjson::Document> subsets;
3492 this->queriesXPathJsonPointer.at(query.
index).second.getSubSets(parsedJson, subsets);
3496 this->stringifySubSets(warningsTo);
3500 if(subsets.empty()) {
3505 this->insertSubSets(subsets);
3511 "WARNING: XPath error - " 3512 + std::string(e.
view())
3514 + *(this->queryTargetSourcePtr)
3520 "WARNING: JSONPointer error - " 3521 + std::string(e.
view())
3523 + *(this->queryTargetSourcePtr)
3529 "WARNING: JSONPath error - " 3530 + std::string(e.
view())
3532 + *(this->queryTargetSourcePtr)
3542 if(this->parseSubSetXml(warningsTo)) {
3548 this->queriesXPathJsonPath.at(query.
index).first.getFirst(
3549 this->xPathSubSets.at(this->subSetCurrent - 1),
3554 this->queriesXPathJsonPath.at(query.
index).first.getFirst(
3555 this->subSetParsedXML,
3568 std::vector<jsoncons::json> subsets;
3571 this->queriesXPathJsonPath.at(query.
index).second.getSubSets(parsedJson, subsets);
3575 this->stringifySubSets(warningsTo);
3579 if(subsets.empty()) {
3584 this->insertSubSets(subsets);
3590 "WARNING: XPath error - " 3591 + std::string(e.
view())
3593 + *(this->queryTargetSourcePtr)
3599 "WARNING: JSONPath error - " 3600 + std::string(e.
view())
3602 + *(this->queryTargetSourcePtr)
3608 "WARNING: JSONPath error - " 3609 + std::string(e.
view())
3611 + *(this->queryTargetSourcePtr)
3624 "Query::Container::addSubSetsFromQueryOnSubSet():" 3625 " Unknown query type" 3646 this->stringifiedSubSets.reserve(n);
3648 switch(query.
type) {
3650 this->xPathSubSets.reserve(n);
3656 this->jsonPointerSubSets.reserve(n);
3662 this->jsonPathSubSets.reserve(n);
3677 inline bool Container::parseXml(std::queue<std::string>& warningsTo) {
3679 if(this->queryTargetPtr ==
nullptr) {
3681 "Query::Container::parseXml():" 3682 " No content has been specified" 3686 if(this->queryTargetSourcePtr ==
nullptr) {
3688 "Query::Container::parseXml():" 3689 " No content source has been specified" 3695 && this->xmlParsingError.empty()
3698 this->parsedXML.
parse(
3699 *(this->queryTargetPtr),
3701 this->repairComments,
3702 this->removeXmlInstructions,
3706 this->xmlParsed =
true;
3709 this->xmlParsingError = e.
view();
3713 + this->xmlParsingError
3715 + *(this->queryTargetSourcePtr)
3721 return this->xmlParsed;
3726 inline bool Container::parseJsonRapid(std::queue<std::string>& warningsTo) {
3728 if(this->queryTargetPtr ==
nullptr) {
3730 "Query::Container::parseJsonRapid():" 3731 " No content has been specified" 3735 if(this->queryTargetSourcePtr ==
nullptr) {
3737 "Query::Container::parseJsonRapid():" 3738 " No content source has been specified" 3743 !(this->jsonParsedRapid)
3744 && this->jsonParsingError.empty()
3748 *(this->queryTargetPtr)
3751 this->jsonParsedRapid =
true;
3754 this->jsonParsingError = e.
view();
3758 + this->jsonParsingError
3760 + *(this->queryTargetSourcePtr)
3766 return this->jsonParsedRapid;
3771 inline bool Container::parseJsonCons(std::queue<std::string>& warningsTo) {
3773 if(this->queryTargetPtr ==
nullptr) {
3775 "Query::Container::parseJsonCons():" 3776 " No content has been specified" 3780 if(this->queryTargetSourcePtr ==
nullptr) {
3782 "Query::Container::parseJsonCons():" 3783 " No content source has been specified" 3788 !(this->jsonParsedCons)
3789 && this->jsonParsingError.empty()
3793 *(this->queryTargetPtr)
3796 this->jsonParsedCons =
true;
3799 this->jsonParsingError = e.
view();
3801 warningsTo.emplace(
"WARNING: [JSON] " + this->jsonParsingError);
3805 return this->jsonParsedCons;
3810 inline bool Container::parseSubSetXml(std::queue<std::string>& warningsTo) {
3812 if(this->subSetCurrent == 0) {
3814 "Query::Container::parseSubSetXml():" 3815 " No subset has been specified" 3819 if(this->subSetCurrent > this->subSetNumber) {
3821 "Query::Container::parseSubSetXml():" 3822 " Invalid subset has been specified" 3828 return this->xPathSubSets.at(this->subSetCurrent - 1).valid();
3832 !(this->subSetXmlParsed)
3833 && this->subSetXmlParsingError.empty()
3836 this->stringifySubSets(warningsTo);
3839 this->subSetParsedXML.
parse(
3840 this->stringifiedSubSets.at(this->subSetCurrent - 1),
3842 this->repairComments,
3843 this->removeXmlInstructions,
3847 this->subSetXmlParsed =
true;
3850 this->subSetXmlParsingError = e.
view();
3852 warningsTo.emplace(
"WARNING: [XML] " + this->subSetXmlParsingError);
3856 return this->subSetXmlParsed;
3861 inline bool Container::parseSubSetJsonRapid(std::queue<std::string>& warningsTo) {
3863 if(this->subSetCurrent == 0) {
3865 "Query::Container::parseSubSetJsonRapid():" 3866 " No subset has been specified" 3870 if(this->subSetCurrent > this->subSetNumber) {
3872 "Query::Container::parseSubSetJsonRapid():" 3873 " Invalid subset has been specified" 3883 !(this->subSetJsonParsedRapid)
3884 && this->subSetJsonParsingError.empty()
3887 this->stringifySubSets(warningsTo);
3891 this->stringifiedSubSets.at(this->subSetCurrent - 1)
3894 this->subSetJsonParsedRapid =
true;
3897 this->subSetJsonParsingError = e.
view();
3899 warningsTo.emplace(
"WARNING: [JSON] " + this->subSetJsonParsingError);
3903 return this->subSetJsonParsedRapid;
3908 inline bool Container::parseSubSetJsonCons(std::queue<std::string>& warningsTo) {
3910 if(this->subSetCurrent == 0) {
3912 "Query::Container::parseSubSetJsonCons():" 3913 " No subset has been specified" 3917 if(this->subSetCurrent > this->subSetNumber) {
3919 "Query::Container::parseSubSetJsonCons():" 3920 " Invalid subset has been specified" 3930 !(this->subSetJsonParsedCons)
3931 && this->subSetJsonParsingError.empty()
3934 this->stringifySubSets(warningsTo);
3938 this->stringifiedSubSets.at(this->subSetCurrent - 1)
3941 this->subSetJsonParsedCons =
true;
3944 this->subSetJsonParsingError = e.
view();
3946 warningsTo.emplace(
"WARNING: [JSON] " + this->subSetJsonParsingError);
3950 return this->subSetJsonParsedCons;
3954 inline void Container::resetSubSetParsingState() {
3956 this->subSetXmlParsed =
false;
3957 this->subSetJsonParsedRapid =
false;
3958 this->subSetJsonParsedCons =
false;
3965 this->subSetParsedXML.
clear();
3972 inline void Container::clearSubSets() {
3973 if(this->minimizeMemory) {
3974 switch(this->subSetType) {
3997 switch(this->subSetType) {
3999 this->xPathSubSets.clear();
4004 this->jsonPointerSubSets.clear();
4009 this->jsonPathSubSets.clear();
4017 this->stringifiedSubSets.clear();
4021 this->subSetNumber = 0;
4022 this->subSetCurrent = 0;
4025 this->resetSubSetParsingState();
4029 inline void Container::stringifySubSets(std::queue<std::string>& warningsTo) {
4030 if(!(this->stringifiedSubSets.empty())) {
4034 switch(this->subSetType) {
4036 for(
const auto& subset : this->xPathSubSets) {
4037 std::string subsetString;
4039 subset.getContent(subsetString);
4041 this->stringifiedSubSets.emplace_back(subsetString);
4047 for(
const auto& subset : this->jsonPathSubSets) {
4048 this->stringifiedSubSets.emplace_back(
4056 for(
const auto& subset : this->jsonPointerSubSets) {
4057 this->stringifiedSubSets.emplace_back(
4066 "WARNING: RegEx subsets cannot be stringified." 4076 "WARNING: Unknown subset type" 4077 " in Query::Container::stringifySubSets(...)." 4085 inline void Container::insertSubSets(std::vector<std::string>& subsets) {
4087 this->subSetNumber += subsets.size();
4093 switch(this->subSetType) {
4095 if(this->minimizeMemory) {
4099 this->xPathSubSets.clear();
4105 if(this->minimizeMemory) {
4109 this->jsonPointerSubSets.clear();
4115 if(this->minimizeMemory) {
4119 this->jsonPathSubSets.clear();
4135 inline void Container::insertSubSets(std::vector<Parsing::XML>& subsets) {
4137 this->subSetNumber += subsets.size();
4145 if(!(this->stringifiedSubSets.empty())) {
4146 std::vector<std::string> stringified;
4148 stringified.reserve(subsets.size());
4150 for(
const auto& subset : subsets) {
4151 std::string subsetString;
4153 subset.getContent(subsetString);
4155 stringified.emplace_back(subsetString);
4159 this->stringifiedSubSets,
4167 std::vector<std::string> stringified;
4169 stringified.reserve(subsets.size());
4171 for(
const auto& subset : subsets) {
4172 stringified.emplace_back();
4174 subset.getContent(stringified.back());
4179 this->stringifiedSubSets,
4185 switch(this->subSetType) {
4187 if(this->minimizeMemory) {
4191 this->jsonPointerSubSets.clear();
4197 if(this->minimizeMemory) {
4201 this->jsonPathSubSets.clear();
4218 inline void Container::insertSubSets(std::vector<jsoncons::json>& subsets) {
4220 this->subSetNumber += subsets.size();
4228 if(!(this->stringifiedSubSets.empty())) {
4229 std::vector<std::string> stringified;
4231 stringified.reserve(subsets.size());
4233 for(
const auto& subset : subsets) {
4234 stringified.emplace_back(
4240 this->stringifiedSubSets,
4248 std::vector<std::string> stringified;
4250 stringified.reserve(subsets.size());
4252 for(
const auto& subset : subsets) {
4253 stringified.emplace_back(
4260 this->stringifiedSubSets,
4266 switch(this->subSetType) {
4268 if(this->minimizeMemory) {
4272 this->xPathSubSets.clear();
4278 if(this->minimizeMemory) {
4282 this->jsonPointerSubSets.clear();
4299 inline void Container::insertSubSets(std::vector<rapidjson::Document>& subsets) {
4301 this->subSetNumber += subsets.size();
4309 if(!(this->stringifiedSubSets.empty())) {
4310 std::vector<std::string> stringified;
4312 stringified.reserve(subsets.size());
4314 for(
const auto& subset : subsets) {
4315 stringified.emplace_back(
4321 this->stringifiedSubSets,
4329 std::vector<std::string> stringified;
4331 stringified.reserve(subsets.size());
4333 for(
const auto& subset : subsets) {
4334 stringified.emplace_back(
4343 switch(this->subSetType) {
4345 if(this->minimizeMemory) {
4349 this->xPathSubSets.clear();
4355 if(this->minimizeMemory) {
4359 this->jsonPathSubSets.clear();
bool resultSingle
Indicates whether the query generates a single result.
Definition: QueryProperties.hpp:56
static constexpr std::uint8_t typeJsonPointer
Query type identifying a JSONPointer query.
Definition: QueryStruct.hpp:58
Class for XPath exceptions.
Definition: XPath.hpp:104
bool resultBool
Indicates whether the query generates a boolean result.
Definition: QueryStruct.hpp:80
Query properties containing its name, text, type, and result type(s).
Definition: QueryProperties.hpp:39
Class for JSONPointer exceptions.
Definition: JsonPointer.hpp:97
void getContent(std::string &resultTo) const
Gets the stringified content inside the underlying document.
Definition: XML.hpp:300
virtual void initQueries()=0
Pure virtual function initializing queries.
std::string text
The query.
Definition: QueryProperties.hpp:47
Class for query container exceptions.
Definition: Container.hpp:148
bool getBoolFromQueryOnSubSet(const QueryStruct &query, bool &resultTo, std::queue< std::string > &warningsTo)
Gets a boolean result from a query of any type on the current subset.
Definition: Container.hpp:1378
void clearQueries()
Clears all queries currently managed by the container and frees the associated memory.
Definition: Container.hpp:759
bool resultSingle
Indicates whether the query generates a single result.
Definition: QueryStruct.hpp:83
bool getBoolFromRegEx(const QueryStruct &query, const std::string &target, bool &resultTo, std::queue< std::string > &warningsTo) const
Gets a boolean result from a RegEx query on a separate string.
Definition: Container.hpp:889
void setOptions(bool showWarnings, std::uint32_t numOfErrors) noexcept
Sets logging options.
Definition: XML.hpp:330
bool resultMulti
Indicates whether the query generates multiple results.
Definition: QueryStruct.hpp:86
static constexpr std::uint8_t typeJsonPath
Query type identifying a JSONPath query.
Definition: QueryStruct.hpp:61
bool resultSubSets
Indicates whether the query generates subsets as results.
Definition: QueryProperties.hpp:66
Query container.
Definition: Container.hpp:76
static void moveInto(T &to, T &from)
Moves the elements of an iterable container into another iterable container.
Definition: Container.hpp:99
std::uint8_t type
The type of the query (see above).
Definition: QueryStruct.hpp:74
bool getSingleFromQuery(const QueryStruct &query, std::string &resultTo, std::queue< std::string > &warningsTo)
Gets a single result from a query of any type on the current query target.
Definition: Container.hpp:1699
rapidjson::Document parseRapid(std::string_view json)
Parses JSON code using RapidJSON.
Definition: Json.hpp:575
bool getSingleFromQueryOnSubSet(const QueryStruct &query, std::string &resultTo, std::queue< std::string > &warningsTo)
Gets a single result from a query of any type on the current subset.
Definition: Container.hpp:1992
bool getSingleFromRegEx(const QueryStruct &query, const std::string &target, std::string &resultTo, std::queue< std::string > &warningsTo) const
Gets a single result from a RegEx query on a separate string.
Definition: Container.hpp:958
Class for JSONPath exceptions.
Definition: RegEx.hpp:108
#define MAIN_EXCEPTION_CLASS()
Macro used to easily define classes for general exceptions.
Definition: Exception.hpp:50
Implements a JSONPath query using the jsoncons library.
Definition: JsonPath.hpp:56
bool getBoolFromQuery(const QueryStruct &query, bool &resultTo, std::queue< std::string > &warningsTo)
Gets a boolean result from a query of any type on the current query target.
Definition: Container.hpp:1098
Class for JSON exceptions.
Definition: Json.hpp:136
Container & operator=(const Container &)=delete
Deleted copy assignment operator.
Container()=default
Default constructor.
void clear()
Clears the content of the underlying XML document.
Definition: XML.hpp:439
void setQueryTarget(const std::string &content, const std::string &source)
Sets the content to use the managed queries on.
Definition: Container.hpp:453
bool resultSubSets
Indicates whether the query generates subsets as results.
Definition: QueryStruct.hpp:93
bool getXml(std::string &resultTo, std::queue< std::string > &warningsTo)
Parses the current query target as tidied XML and writes it to the given string.
Definition: Container.hpp:521
bool resultMulti
Indicates whether the query generates multiple results.
Definition: QueryProperties.hpp:59
void clearQueryTarget()
Clears the current query target and frees the associated memory.
Definition: Container.hpp:769
static void freeIf(bool isFree, T &target)
Frees memory early by swapping, if necessary.
Definition: Memory.hpp:52
bool textOnly
Indicates whether the query should be considered text-only.
Definition: QueryProperties.hpp:69
bool getTarget(std::string &targetTo)
Gets the current query target, if available, and writes it to the given string.
Definition: Container.hpp:494
static constexpr std::uint8_t typeNone
Unspecified query type.
Definition: QueryStruct.hpp:49
static constexpr std::uint8_t typeRegEx
Query type identifying a RegEx query.
Definition: QueryStruct.hpp:52
static constexpr std::uint8_t typeXPathJsonPointer
Query type identifying a combined XPath and JSONPointer query.
Definition: QueryStruct.hpp:64
void setTidyErrorsAndWarnings(bool warnings, std::uint32_t numOfErrors)
Sets how tidy-html5 reports errors and warnings.
Definition: Container.hpp:428
std::size_t index
The index of the query inside its container.
Definition: QueryStruct.hpp:77
Implements a XPath query using the pugixml library.
Definition: XPath.hpp:74
bool resultBool
Indicates whether the query generates a boolean result.
Definition: QueryProperties.hpp:53
void parse(std::string_view content, bool repairCData, bool repairComments, bool removeXmlInstructions, std::queue< std::string > &warningsTo)
Parses the given HTML markup into the underlying XML document.
Definition: XML.hpp:365
static constexpr std::uint8_t typeXPathJsonPath
Query type identifying a combined XPath and JSONPath query.
Definition: QueryStruct.hpp:67
void reserveForSubSets(const QueryStruct &query, std::size_t n)
Reserves memory for a specific number of subsets.
Definition: Container.hpp:3645
void setRepairComments(bool isRepairComments)
Sets whether to try to repair broken HTML/XML comments.
Definition: Container.hpp:385
void setMinimizeMemory(bool isMinimizeMemory)
Sets whether to minimize memory usage.
Definition: Container.hpp:407
void setRemoveXmlInstructions(bool isRemoveXmlInstructions)
Sets whether to remove XML processing instructions (<?xml:...>) before parsing HTML/XML content...
Definition: Container.hpp:394
Class for XML exceptions.
Definition: XML.hpp:207
std::string_view view() const noexcept
Gets the description of the exception as a view to the underlying string.
Definition: Exception.hpp:158
bool isQueryUsed(std::uint64_t queryId) const
Checks whether the specified query is used by the container.
Definition: Container.hpp:357
bool nextSubSet()
Requests the next subset for all subsequent queries.
Definition: Container.hpp:808
Namespace for classes handling queries.
Definition: XML.hpp:51
std::string type
The type of the query.
Definition: QueryProperties.hpp:50
Structure to identify a query including its type and result type(s).
Definition: QueryStruct.hpp:40
Parses HTML markup into clean XML.
Definition: XML.hpp:149
bool setSubSetsFromQuery(const QueryStruct &query, std::queue< std::string > &warningsTo)
Sets subsets for subsequent queries using a query of any type.
Definition: Container.hpp:2940
Class for JSONPath exceptions.
Definition: JsonPath.hpp:85
bool getMultiFromQueryOnSubSet(const QueryStruct &query, std::vector< std::string > &resultTo, std::queue< std::string > &warningsTo)
Gets multiple results from a query of any type on the current subset.
Definition: Container.hpp:2605
virtual void deleteQueries()=0
bool addSubSetsFromQueryOnSubSet(const QueryStruct &query, std::queue< std::string > &warningsTo)
Inserts more subsets after the current one based on a query on the current subset.
Definition: Container.hpp:3255
Implements an extended JSONPointer query using the rapidJSON library.
Definition: JsonPointer.hpp:68
bool getMultiFromRegEx(const QueryStruct &query, const std::string &target, std::vector< std::string > &resultTo, std::queue< std::string > &warningsTo) const
Gets multiple results from a RegEx query on a separate string.
Definition: Container.hpp:1028
QueryStruct addQuery(std::uint64_t id, const QueryProperties &properties)
Adds a query with the given query properties to the container.
Definition: Container.hpp:565
std::size_t getNumberOfSubSets() const
Gets the number of subsets currently acquired.
Definition: Container.hpp:475
virtual ~Container()=default
Default destructor.
bool getMultiFromQuery(const QueryStruct &query, std::vector< std::string > &resultTo, std::queue< std::string > &warningsTo)
Gets multiple results from a query of any type on the current query target.
Definition: Container.hpp:2325
static void free(T &target)
Frees memory by swapping.
Definition: Memory.hpp:42
jsoncons::json parseCons(std::string_view json)
Parses JSON code using jsoncons.
Definition: Json.hpp:645
static constexpr std::uint8_t typeXPath
Query type identifying a XPath query.
Definition: QueryStruct.hpp:55
static void free(rapidjson::Document &target)
Frees memory by swapping.
Definition: Json.hpp:862
std::string stringify(const std::vector< std::string > &vectorToStringify)
Stringifies a vector of strings into one string containing a JSON array.
Definition: Json.hpp:158
void setRepairCData(bool isRepairCData)
Sets whether to try to repair CData when parsing XML.
Definition: Container.hpp:376