Skip to content

Commit 16db299

Browse files
committed
fix: remove xpressive dependency
1 parent 35b782d commit 16db299

1 file changed

Lines changed: 51 additions & 5 deletions

File tree

include/boost/graph/graphviz.hpp

Lines changed: 51 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@
3333
#include <boost/lexical_cast.hpp>
3434
#include <boost/static_assert.hpp>
3535
#include <boost/algorithm/string/replace.hpp>
36-
#include <boost/xpressive/xpressive_static.hpp>
3736

3837
namespace boost
3938
{
@@ -56,13 +55,60 @@ struct default_writer
5655
template < class VorE > void operator()(std::ostream&, const VorE&) const {}
5756
};
5857

58+
namespace detail
59+
{
60+
61+
inline bool dot_id_is_alpha(char c)
62+
{
63+
return c == '_' || (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z');
64+
}
65+
66+
inline bool dot_id_is_digit(char c) { return c >= '0' && c <= '9'; }
67+
68+
inline bool dot_id_is_word(char c)
69+
{
70+
return dot_id_is_alpha(c) || dot_id_is_digit(c);
71+
}
72+
73+
// True when s matches the DOT grammar for an ID that needs no quoting:
74+
// identifier [A-Za-z_][A-Za-z0-9_]*
75+
// numeral -?( .[0-9]* | [0-9]+(.[0-9]*)? )
76+
inline bool is_dot_unquoted_id(const std::string& s)
77+
{
78+
using size_type = std::string::size_type;
79+
if (s.empty())
80+
return false;
81+
if (dot_id_is_alpha(s[0]))
82+
{
83+
for (size_type i = 1; i < s.size(); ++i)
84+
if (!dot_id_is_word(s[i]))
85+
return false;
86+
return true;
87+
}
88+
size_type i = 0;
89+
if (s[i] == '-')
90+
++i;
91+
if (i >= s.size())
92+
return false;
93+
if (s[i] != '.' && !dot_id_is_digit(s[i]))
94+
return false;
95+
if (dot_id_is_digit(s[i]))
96+
while (i < s.size() && dot_id_is_digit(s[i]))
97+
++i;
98+
if (i < s.size() && s[i] == '.')
99+
++i;
100+
for (; i < s.size(); ++i)
101+
if (!dot_id_is_digit(s[i]))
102+
return false;
103+
return true;
104+
}
105+
106+
} // namespace detail
107+
59108
template < typename T > inline std::string escape_dot_string(const T& obj)
60109
{
61-
using namespace boost::xpressive;
62-
static sregex valid_unquoted_id = (((alpha | '_') >> *_w)
63-
| (!as_xpr('-') >> (('.' >> *_d) | (+_d >> !('.' >> *_d)))));
64110
std::string s(boost::lexical_cast< std::string >(obj));
65-
if (regex_match(s, valid_unquoted_id))
111+
if (detail::is_dot_unquoted_id(s))
66112
{
67113
return s;
68114
}

0 commit comments

Comments
 (0)