24 #ifndef GOBY_MIDDLEWARE_IO_LINE_BASED_COMMON_H
25 #define GOBY_MIDDLEWARE_IO_LINE_BASED_COMMON_H
55 explicit match_regex(std::string eol) : eol_regex_(ctype_narrow_workaround(eol)) {}
57 template <
typename Iterator>
58 std::pair<Iterator, bool>
operator()(Iterator begin, Iterator end)
const
60 std::match_results<Iterator> result;
61 if (std::regex_search(begin, end, result, eol_regex_))
62 return std::make_pair(begin + result.position() + result.length(),
true);
64 return std::make_pair(begin,
false);
68 std::string ctype_narrow_workaround(std::string eol)
75 static std::atomic<bool> ctype_narrow_initialized{
false};
76 if (!ctype_narrow_initialized)
78 const std::ctype<char>& ct(std::use_facet<std::ctype<char>>(std::locale()));
79 for (
size_t i(0); i != 256; ++i) ct.narrow(
static_cast<char>(i),
'\0');
80 ctype_narrow_initialized =
true;
86 std::regex eol_regex_;