Skip to content

Commit

Permalink
use boost::spirit::qi instead of std::regex
Browse files Browse the repository at this point in the history
  • Loading branch information
p8p committed Aug 23, 2018
1 parent 2647aea commit ab6f37c
Showing 1 changed file with 16 additions and 7 deletions.
23 changes: 16 additions & 7 deletions src/common/is_hdd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,12 @@
#include <regex>
#include <memory>
#include "util.h"
#include <boost/range/iterator_range.hpp>
#include <boost/spirit/include/qi_char_.hpp>
#include <boost/spirit/include/qi_lit.hpp>
#include <boost/spirit/include/qi_difference.hpp>
#include <boost/spirit/include/qi_klenee.hpp>
#include <boost/spirit/include/qi_sequance.hpp>
#endif
#include <boost/optional.hpp>

Expand Down Expand Up @@ -109,14 +115,17 @@ namespace tools
p_size,
VOLUME_NAME_NT | FILE_NAME_NORMALIZED
);
std::regex r("^\\\\Device\\\\([^\\\\]+).*$");
std::smatch m;
if(std::regex_match(p, m, r))
namespace qi = boost::spirit::qi;
boost::iterator_range<const char> m{};
bool success = qi::parse(
p.begin(),
p.end(),
(qi::lit("\\\\Device\\\\") >> *(qi::char_ - "\\\\")),
m
);
if(success and m.begin() != m.end())
{
if(m.size() == 2)
{
return m[1].str();
}
return *m;
}
}
return boost::none;
Expand Down

0 comments on commit ab6f37c

Please sign in to comment.