Line data Source code
1 : /* 2 : * Copyright (c) 2014 Juniper Networks, Inc. All rights reserved. 3 : */ 4 : #ifndef __PARSER_UTIL__ 5 : #define __PARSER_UTIL__ 6 : #include <string> 7 : #include <set> 8 : #include <map> 9 : #include "base/regex.h" 10 : #include <pugixml/pugixml.hpp> 11 : 12 : class LineParser 13 : { 14 : public: 15 : 16 : typedef std::set<std::string> WordListType; 17 : 18 : static bool Parse(std::string s, WordListType *words); 19 : static bool ParseXML(const pugi::xml_node &node, WordListType *w, 20 : bool check_attr=true); 21 : static std::string GetXmlString(const pugi::xml_node node); 22 : static std::string MakeSane(const std::string &text); 23 : static unsigned int SearchPattern(const contrail::regex &exp, 24 : std::string text); 25 7 : static unsigned int SearchPattern(std::string exp, std::string text) { 26 7 : return SearchPattern(contrail::regex(exp, boost::regex::icase), text); } 27 : private: 28 : template <typename Iterator> 29 : static bool ParseDoc(Iterator start, Iterator end, 30 : LineParser::WordListType *pv); 31 : static bool Traverse(const pugi::xml_node &node, WordListType *words, 32 : bool check_attr=true); 33 : static bool GetAtrributes(const pugi::xml_node &node, WordListType *words); 34 : }; 35 : 36 : #endif //__PARSER_UTIL__