plist解析, 简易实现.

源码

 class Xml {
 public:
     typedef std::pair<std::wstring, std::wstring> NodeT;
     static std::vector<NodeT> parse(const std::wstring &xml)
     {
         std::vector<NodeT> result;

         ;
         std::wstring tagName;
         std::wstring::const_iterator
             curIter = std::begin(xml),
             begIter = std::end(xml), endIter = std::end(xml),
             cbegIter = std::end(xml), cendIter = std::end(xml);

         std::wsmatch smatch;
         while (std::regex_search(curIter, std::end(xml), smatch, std::wregex(LR"(</\w+>|<\w+>)")))
         {
             )
             {
                 begIter = smatch[].first;
                 cbegIter = smatch[].second;
                 tagName = std::regex_replace(smatch[].str(), std::wregex(LR"(<(\w+)>)"), LR"($1)");
             }

             curIter = smatch[].second;
             ].str().substr(, tagName.size()) == tagName)
                 ++stackCount;
             ].str().substr(, tagName.size()) == tagName)
                 --stackCount;

             //    匹配完成.
             )
             {
                 endIter = smatch[].second;
                 cendIter = smatch[].first;

                 result.push_back(std::make_pair(tagName, std::wstring(cbegIter, cendIter)));
             }
         }
         return result;
     };
 };

效果图

plist解析, 简易实现.

由于项目需要输入, 输出plist文件.

C++标准又没有xml库. 索性就自己写了个简易版.

功能相当有限, 仅支持解析个个标签内容.

不过, 对我来说已经足够了.

代码也不算长, 凑合用用.

substr可以优化掉...

上一篇:start.sh


下一篇:Ubuntu解压缩zip,tar,tar.gz,tar.bz2文件命令