summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorYifan Hong2018-03-21 19:27:47 -0500
committerYifan Hong2018-03-22 16:54:15 -0500
commit705216b8317ae958f648878019674dd41a549ea9 (patch)
tree52fba7578404bec18fd3e847377a5e8493d84851 /parse_xml.cpp
parent7e9e04d10d74377a13d36d3f945b1cbc1aaf1a50 (diff)
downloadplatform-system-libvintf-705216b8317ae958f648878019674dd41a549ea9.tar.gz
platform-system-libvintf-705216b8317ae958f648878019674dd41a549ea9.tar.xz
platform-system-libvintf-705216b8317ae958f648878019674dd41a549ea9.zip
regex-instance: HalInterface stores regex instances.
Parse <regex-instance> regular expression patterns using Extended Regular Expression syntax, and store it in HalInterface object. Bug: 73738616 Test: libvintf_test Test: vintf_object_test Test: vts_treble_vintf_test Change-Id: If0b8e3bc053a6c2ecd9048092071f52f7896bba0
Diffstat (limited to 'parse_xml.cpp')
-rw-r--r--parse_xml.cpp19
1 files changed, 18 insertions, 1 deletions
diff --git a/parse_xml.cpp b/parse_xml.cpp
index 3d67e1c..27f31c9 100644
--- a/parse_xml.cpp
+++ b/parse_xml.cpp
@@ -25,6 +25,7 @@
25 25
26#include <tinyxml2.h> 26#include <tinyxml2.h>
27 27
28#include "Regex.h"
28#include "constants.h" 29#include "constants.h"
29#include "parse_string.h" 30#include "parse_string.h"
30 31
@@ -475,11 +476,14 @@ struct HalInterfaceConverter : public XmlNodeConverter<HalInterface> {
475 void mutateNode(const HalInterface &intf, NodeType *root, DocType *d) const override { 476 void mutateNode(const HalInterface &intf, NodeType *root, DocType *d) const override {
476 appendTextElement(root, "name", intf.name(), d); 477 appendTextElement(root, "name", intf.name(), d);
477 appendTextElements(root, "instance", intf.mInstances, d); 478 appendTextElements(root, "instance", intf.mInstances, d);
479 appendTextElements(root, "regex-instance", intf.mRegexes, d);
478 } 480 }
479 bool buildObject(HalInterface* intf, NodeType* root, std::string* error) const override { 481 bool buildObject(HalInterface* intf, NodeType* root, std::string* error) const override {
480 std::vector<std::string> instances; 482 std::vector<std::string> instances;
483 std::vector<std::string> regexes;
481 if (!parseTextElement(root, "name", &intf->mName, error) || 484 if (!parseTextElement(root, "name", &intf->mName, error) ||
482 !parseTextElements(root, "instance", &instances, error)) { 485 !parseTextElements(root, "instance", &instances, error) ||
486 !parseTextElements(root, "regex-instance", &regexes, error)) {
483 return false; 487 return false;
484 } 488 }
485 bool success = true; 489 bool success = true;
@@ -490,6 +494,19 @@ struct HalInterfaceConverter : public XmlNodeConverter<HalInterface> {
490 success = false; 494 success = false;
491 } 495 }
492 } 496 }
497 for (const auto& e : regexes) {
498 details::Regex regex;
499 if (!regex.compile(e)) {
500 if (!error->empty()) *error += "\n";
501 *error += "Invalid regular expression '" + e + "' in " + intf->name();
502 success = false;
503 }
504 if (!intf->insertInstance(e, true /* isRegex */)) {
505 if (!error->empty()) *error += "\n";
506 *error += "Duplicated regex-instance '" + e + "' in " + intf->name();
507 success = false;
508 }
509 }
493 return success; 510 return success;
494 } 511 }
495}; 512};