2013-06-28 20:57:30 +02:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is dual licensed under the MIT and the University of Illinois Open
|
|
|
|
// Source Licenses. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
// <regex>
|
|
|
|
|
|
|
|
// template <class charT, class traits = regex_traits<charT>> class basic_regex;
|
|
|
|
|
|
|
|
// template <class ST, class SA>
|
|
|
|
// basic_regex(const basic_string<charT, ST, SA>& s);
|
|
|
|
|
|
|
|
#include <regex>
|
|
|
|
#include <cassert>
|
|
|
|
|
2013-07-15 20:21:11 +02:00
|
|
|
static bool error_escape_thrown(const char *pat)
|
2013-06-28 20:57:30 +02:00
|
|
|
{
|
2013-07-15 20:21:11 +02:00
|
|
|
bool result = false;
|
2013-06-28 20:57:30 +02:00
|
|
|
try {
|
2013-07-15 20:21:11 +02:00
|
|
|
std::regex re(pat);
|
2013-06-28 20:57:30 +02:00
|
|
|
} catch (std::regex_error &ex) {
|
2013-07-15 20:21:11 +02:00
|
|
|
result = (ex.code() == std::regex_constants::error_escape);
|
2013-06-28 20:57:30 +02:00
|
|
|
}
|
2013-07-15 20:21:11 +02:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
int main()
|
|
|
|
{
|
|
|
|
assert(error_escape_thrown("[\\a]"));
|
|
|
|
assert(error_escape_thrown("\\a"));
|
|
|
|
|
|
|
|
assert(error_escape_thrown("[\\e]"));
|
|
|
|
assert(error_escape_thrown("\\e"));
|
|
|
|
|
|
|
|
assert(error_escape_thrown("[\\c:]"));
|
|
|
|
assert(error_escape_thrown("\\c:"));
|
|
|
|
assert(error_escape_thrown("\\c"));
|
|
|
|
assert(!error_escape_thrown("[\\cA]"));
|
|
|
|
assert(!error_escape_thrown("\\cA"));
|
2013-06-28 20:57:30 +02:00
|
|
|
|
|
|
|
}
|