Redesign number 3. The previous design was not handling matching of empty strings inside of loops.

git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@108151 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Howard Hinnant 2010-07-12 15:51:17 +00:00
parent 37f9f9c587
commit ac30386dfe
2 changed files with 425 additions and 384 deletions

File diff suppressed because it is too large Load Diff

View File

@ -229,4 +229,85 @@ int main()
assert(!std::regex_search(s, m, std::regex("abc$", std::regex_constants::basic)));
assert(m.size() == 0);
}
{
std::cmatch m;
const char s[] = "abc";
assert(std::regex_search(s, m, std::regex("a.c", std::regex_constants::basic)));
assert(m.size() == 1);
assert(!m.prefix().matched);
assert(m.prefix().first == s);
assert(m.prefix().second == m[0].first);
assert(!m.suffix().matched);
assert(m.suffix().first == m[0].second);
assert(m.suffix().second == s+3);
assert(m.length(0) == 3);
assert(m.position(0) == 0);
assert(m.str(0) == s);
}
{
std::cmatch m;
const char s[] = "acc";
assert(std::regex_search(s, m, std::regex("a.c", std::regex_constants::basic)));
assert(m.size() == 1);
assert(!m.prefix().matched);
assert(m.prefix().first == s);
assert(m.prefix().second == m[0].first);
assert(!m.suffix().matched);
assert(m.suffix().first == m[0].second);
assert(m.suffix().second == s+3);
assert(m.length(0) == 3);
assert(m.position(0) == 0);
assert(m.str(0) == s);
}
{
std::cmatch m;
const char s[] = "acc";
assert(std::regex_search(s, m, std::regex("a.c", std::regex_constants::basic)));
assert(m.size() == 1);
assert(!m.prefix().matched);
assert(m.prefix().first == s);
assert(m.prefix().second == m[0].first);
assert(!m.suffix().matched);
assert(m.suffix().first == m[0].second);
assert(m.suffix().second == s+3);
assert(m.length(0) == 3);
assert(m.position(0) == 0);
assert(m.str(0) == s);
}
{
std::cmatch m;
const char s[] = "abcdef";
assert(std::regex_search(s, m, std::regex("\\(.*\\).*", std::regex_constants::basic)));
assert(m.size() == 2);
assert(!m.prefix().matched);
assert(m.prefix().first == s);
assert(m.prefix().second == m[0].first);
assert(!m.suffix().matched);
assert(m.suffix().first == m[0].second);
assert(m.suffix().second == s+6);
assert(m.length(0) == 6);
assert(m.position(0) == 0);
assert(m.str(0) == s);
assert(m.length(1) == 6);
assert(m.position(1) == 0);
assert(m.str(1) == s);
}
{
std::cmatch m;
const char s[] = "bc";
assert(std::regex_search(s, m, std::regex("\\(a*\\)*", std::regex_constants::basic)));
assert(m.size() == 2);
assert(!m.prefix().matched);
assert(m.prefix().first == s);
assert(m.prefix().second == m[0].first);
assert(m.suffix().matched);
assert(m.suffix().first == m[0].second);
assert(m.suffix().second == s+2);
assert(m.length(0) == 0);
assert(m.position(0) == 0);
assert(m.str(0) == "");
assert(m.length(1) == 0);
assert(m.position(1) == 0);
assert(m.str(1) == "");
}
}