From f409d2f2fc3b8ee5d2af59ae83dae8b7cbba6135 Mon Sep 17 00:00:00 2001 From: Howard Hinnant Date: Mon, 21 Jun 2010 21:01:43 +0000 Subject: [PATCH] Finished [re.traits]. I'd like to acknowledge the help of Bjorn Reese with . git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@106478 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/regex | 101 +++++++- src/regex.cpp | 49 +++- test/re/re.traits/default.pass.cpp | 16 +- test/re/re.traits/getloc.pass.cpp | 15 +- test/re/re.traits/imbue.pass.cpp | 9 +- test/re/re.traits/isctype.pass.cpp | 260 +++++++++++++++++++- test/re/re.traits/lookup_classname.pass.cpp | 187 +++++++++++++- test/re/re.traits/value.pass.cpp | 108 +++++++- 8 files changed, 731 insertions(+), 14 deletions(-) diff --git a/include/regex b/include/regex index eab475d6..e48f0722 100644 --- a/include/regex +++ b/include/regex @@ -917,8 +917,9 @@ public: typedef _CharT char_type; typedef basic_string string_type; typedef locale locale_type; - typedef unsigned char_class_type; + typedef ctype_base::mask char_class_type; + static const char_class_type __regex_word = 0x80; private: locale __loc_; const ctype* __ct_; @@ -945,9 +946,11 @@ public: template char_class_type lookup_classname(_ForwardIterator __f, _ForwardIterator __l, - bool __icase = false) const; - bool isctype(char_type __c, char_class_type __f) const; - int value(char_type __ch, int __radix) const; + bool __icase = false) const + {return __lookup_classname(__f, __l, __icase, char_type());} + bool isctype(char_type __c, char_class_type __m) const; + int value(char_type __ch, int __radix) const + {return __value(__ch, __radix);} locale_type imbue(locale_type __l); locale_type getloc()const {return __loc_;} @@ -967,6 +970,20 @@ private: template string_type __lookup_collatename(_ForwardIterator __f, _ForwardIterator __l, wchar_t) const; + + template + char_class_type + __lookup_classname(_ForwardIterator __f, _ForwardIterator __l, + bool __icase, char) const; + template + char_class_type + __lookup_classname(_ForwardIterator __f, _ForwardIterator __l, + bool __icase, wchar_t) const; + + static int __value(unsigned char __ch, int __radix); + int __value(char __ch, int __radix) const + {return __value(static_cast(__ch), __radix);} + int __value(wchar_t __ch, int __radix) const; }; template @@ -1057,7 +1074,7 @@ regex_traits<_CharT>::__transform_primary(_ForwardIterator __f, // lookup_collatename is very FreeBSD-specific -string __get_collation_name(const char* s); +string __get_collation_name(const char* __s); template template @@ -1116,6 +1133,80 @@ regex_traits<_CharT>::__lookup_collatename(_ForwardIterator __f, return __r; } +// lookup_classname + +ctype_base::mask __get_classname(const char* __s, bool __icase); + +template +template +typename regex_traits<_CharT>::char_class_type +regex_traits<_CharT>::__lookup_classname(_ForwardIterator __f, + _ForwardIterator __l, + bool __icase, char) const +{ + string_type __s(__f, __l); + __ct_->tolower(&__s[0], &__s[0] + __s.size()); + return __get_classname(__s.c_str(), __icase); +} + +template +template +typename regex_traits<_CharT>::char_class_type +regex_traits<_CharT>::__lookup_classname(_ForwardIterator __f, + _ForwardIterator __l, + bool __icase, wchar_t) const +{ + string_type __s(__f, __l); + __ct_->tolower(&__s[0], &__s[0] + __s.size()); + string __n; + __n.reserve(__s.size()); + for (typename string_type::const_iterator __i = __s.begin(), __e = __s.end(); + __i != __e; ++__i) + { + if (static_cast(*__i) >= 127) + return char_class_type(); + __n.push_back(char(*__i)); + } + return __get_classname(__n.c_str(), __icase); +} + +template +bool +regex_traits<_CharT>::isctype(char_type __c, char_class_type __m) const +{ + if (__ct_->is(__m, __c)) + return true; + return (__c == '_' && (__m & __regex_word)); +} + +template +int +regex_traits<_CharT>::__value(unsigned char __ch, int __radix) +{ + if ((__ch & 0xF8u) == 0x30) // '0' <= __ch && __ch <= '7' + return __ch - '0'; + if (__radix != 8) + { + if ((__ch & 0xFEu) == 0x38) // '8' <= __ch && __ch <= '9' + return __ch - '0'; + if (__radix == 16) + { + __ch |= 0x20; // tolower + if ('a' <= __ch && __ch <= 'f') + return __ch - 'a' + 10; + } + } + return -1; +} + +template +inline +int +regex_traits<_CharT>::__value(wchar_t __ch, int __radix) const +{ + return __value(static_cast(__ct_->narrow(__ch, char_type())), __radix); +} + _LIBCPP_END_NAMESPACE_STD #endif // _LIBCPP_REGEX diff --git a/src/regex.cpp b/src/regex.cpp index 5dff3964..abb1b668 100644 --- a/src/regex.cpp +++ b/src/regex.cpp @@ -11,7 +11,6 @@ #include "algorithm" #include "iterator" - _LIBCPP_BEGIN_NAMESPACE_STD static @@ -180,10 +179,37 @@ const collationnames collatenames[] = {"zero", 0x30} }; +struct classnames +{ + const char* elem_; + ctype_base::mask mask_; +}; + +const classnames ClassNames[] = +{ + {"alnum", ctype_base::alnum}, + {"alpha", ctype_base::alpha}, + {"blank", ctype_base::blank}, + {"cntrl", ctype_base::cntrl}, + {"d", ctype_base::digit}, + {"digit", ctype_base::digit}, + {"graph", ctype_base::graph}, + {"lower", ctype_base::lower}, + {"print", ctype_base::print}, + {"punct", ctype_base::punct}, + {"s", ctype_base::space}, + {"space", ctype_base::space}, + {"upper", ctype_base::upper}, + {"w", regex_traits::__regex_word}, + {"xdigit", ctype_base::xdigit} +}; + struct use_strcmp { bool operator()(const collationnames& x, const char* y) {return strcmp(x.elem_, y) < 0;} + bool operator()(const classnames& x, const char* y) + {return strcmp(x.elem_, y) < 0;} }; } @@ -191,7 +217,6 @@ struct use_strcmp string __get_collation_name(const char* s) { - typedef std::pair P; const collationnames* i = lower_bound(begin(collatenames), end(collatenames), s, use_strcmp()); string r; @@ -200,4 +225,24 @@ __get_collation_name(const char* s) return r; } +ctype_base::mask +__get_classname(const char* s, bool __icase) +{ + const classnames* i = + lower_bound(begin(ClassNames), end(ClassNames), s, use_strcmp()); + ctype_base::mask r = 0; + if (i != end(ClassNames) && strcmp(s, i->elem_) == 0) + { + r = i->mask_; + if (r == regex_traits::__regex_word) + r |= ctype_base::alnum | ctype_base::upper | ctype_base::lower; + else if (__icase) + { + if (r & (ctype_base::lower | ctype_base::upper)) + r |= ctype_base::alpha; + } + } + return r; +} + _LIBCPP_END_NAMESPACE_STD diff --git a/test/re/re.traits/default.pass.cpp b/test/re/re.traits/default.pass.cpp index ebc3d80e..0e071e8d 100644 --- a/test/re/re.traits/default.pass.cpp +++ b/test/re/re.traits/default.pass.cpp @@ -15,9 +15,21 @@ // regex_traits(); #include +#include int main() { - std::regex_traits t1(); - std::regex_traits t2(); + { + std::regex_traits t1; + assert(t1.getloc().name() == "C"); + std::regex_traits t2; + assert(t2.getloc().name() == "C"); + } + { + std::locale::global(std::locale("en_US")); + std::regex_traits t1; + assert(t1.getloc().name() == "en_US"); + std::regex_traits t2; + assert(t2.getloc().name() == "en_US"); + } } diff --git a/test/re/re.traits/getloc.pass.cpp b/test/re/re.traits/getloc.pass.cpp index b5d1b701..3c2618fc 100644 --- a/test/re/re.traits/getloc.pass.cpp +++ b/test/re/re.traits/getloc.pass.cpp @@ -14,8 +14,21 @@ // locale_type getloc()const; #include +#include int main() { -#error getloc not implemented + { + std::regex_traits t1; + assert(t1.getloc().name() == "C"); + std::regex_traits t2; + assert(t2.getloc().name() == "C"); + } + { + std::locale::global(std::locale("en_US")); + std::regex_traits t1; + assert(t1.getloc().name() == "en_US"); + std::regex_traits t2; + assert(t2.getloc().name() == "en_US"); + } } diff --git a/test/re/re.traits/imbue.pass.cpp b/test/re/re.traits/imbue.pass.cpp index 687ff64b..3fd86afa 100644 --- a/test/re/re.traits/imbue.pass.cpp +++ b/test/re/re.traits/imbue.pass.cpp @@ -14,8 +14,15 @@ // locale_type imbue(locale_type l); #include +#include +#include int main() { -#error imbue not implemented + { + std::regex_traits t; + std::locale loc = t.imbue(std::locale("en_US")); + assert(loc.name() == "C"); + assert(t.getloc().name() == "en_US"); + } } diff --git a/test/re/re.traits/isctype.pass.cpp b/test/re/re.traits/isctype.pass.cpp index 7cb141e2..dddaa562 100644 --- a/test/re/re.traits/isctype.pass.cpp +++ b/test/re/re.traits/isctype.pass.cpp @@ -14,8 +14,266 @@ // bool isctype(charT c, char_class_type f) const; #include +#include int main() { -#error isctype not implemented + { + std::regex_traits t; + + std::string s("w"); + assert( t.isctype('_', t.lookup_classname(s.begin(), s.end()))); + assert( t.isctype('a', t.lookup_classname(s.begin(), s.end()))); + assert( t.isctype('Z', t.lookup_classname(s.begin(), s.end()))); + assert( t.isctype('5', t.lookup_classname(s.begin(), s.end()))); + assert(!t.isctype(' ', t.lookup_classname(s.begin(), s.end()))); + assert(!t.isctype('-', t.lookup_classname(s.begin(), s.end()))); + assert(!t.isctype('@', t.lookup_classname(s.begin(), s.end()))); + + s = "alnum"; + assert(!t.isctype('_', t.lookup_classname(s.begin(), s.end()))); + assert( t.isctype('a', t.lookup_classname(s.begin(), s.end()))); + assert( t.isctype('Z', t.lookup_classname(s.begin(), s.end()))); + assert( t.isctype('5', t.lookup_classname(s.begin(), s.end()))); + assert(!t.isctype(' ', t.lookup_classname(s.begin(), s.end()))); + assert(!t.isctype('-', t.lookup_classname(s.begin(), s.end()))); + assert(!t.isctype('@', t.lookup_classname(s.begin(), s.end()))); + + s = "alpha"; + assert(!t.isctype('_', t.lookup_classname(s.begin(), s.end()))); + assert( t.isctype('a', t.lookup_classname(s.begin(), s.end()))); + assert( t.isctype('Z', t.lookup_classname(s.begin(), s.end()))); + assert(!t.isctype('5', t.lookup_classname(s.begin(), s.end()))); + assert(!t.isctype(' ', t.lookup_classname(s.begin(), s.end()))); + assert(!t.isctype('-', t.lookup_classname(s.begin(), s.end()))); + assert(!t.isctype('@', t.lookup_classname(s.begin(), s.end()))); + + s = "blank"; + assert(!t.isctype('_', t.lookup_classname(s.begin(), s.end()))); + assert(!t.isctype('a', t.lookup_classname(s.begin(), s.end()))); + assert(!t.isctype('Z', t.lookup_classname(s.begin(), s.end()))); + assert(!t.isctype('5', t.lookup_classname(s.begin(), s.end()))); + assert( t.isctype(' ', t.lookup_classname(s.begin(), s.end()))); + assert(!t.isctype('-', t.lookup_classname(s.begin(), s.end()))); + assert(!t.isctype('@', t.lookup_classname(s.begin(), s.end()))); + + s = "cntrl"; + assert( t.isctype('\n', t.lookup_classname(s.begin(), s.end()))); + assert(!t.isctype('_', t.lookup_classname(s.begin(), s.end()))); + assert(!t.isctype('a', t.lookup_classname(s.begin(), s.end()))); + assert(!t.isctype('Z', t.lookup_classname(s.begin(), s.end()))); + assert(!t.isctype('5', t.lookup_classname(s.begin(), s.end()))); + assert(!t.isctype(' ', t.lookup_classname(s.begin(), s.end()))); + assert(!t.isctype('-', t.lookup_classname(s.begin(), s.end()))); + assert(!t.isctype('@', t.lookup_classname(s.begin(), s.end()))); + + s = "digit"; + assert(!t.isctype('\n', t.lookup_classname(s.begin(), s.end()))); + assert(!t.isctype('_', t.lookup_classname(s.begin(), s.end()))); + assert(!t.isctype('a', t.lookup_classname(s.begin(), s.end()))); + assert(!t.isctype('Z', t.lookup_classname(s.begin(), s.end()))); + assert( t.isctype('5', t.lookup_classname(s.begin(), s.end()))); + assert(!t.isctype(' ', t.lookup_classname(s.begin(), s.end()))); + assert(!t.isctype('-', t.lookup_classname(s.begin(), s.end()))); + assert(!t.isctype('@', t.lookup_classname(s.begin(), s.end()))); + + s = "graph"; + assert(!t.isctype('\n', t.lookup_classname(s.begin(), s.end()))); + assert( t.isctype('_', t.lookup_classname(s.begin(), s.end()))); + assert( t.isctype('a', t.lookup_classname(s.begin(), s.end()))); + assert( t.isctype('Z', t.lookup_classname(s.begin(), s.end()))); + assert( t.isctype('5', t.lookup_classname(s.begin(), s.end()))); + assert(!t.isctype(' ', t.lookup_classname(s.begin(), s.end()))); + assert( t.isctype('-', t.lookup_classname(s.begin(), s.end()))); + assert( t.isctype('@', t.lookup_classname(s.begin(), s.end()))); + + s = "lower"; + assert(!t.isctype('\n', t.lookup_classname(s.begin(), s.end()))); + assert(!t.isctype('_', t.lookup_classname(s.begin(), s.end()))); + assert( t.isctype('a', t.lookup_classname(s.begin(), s.end()))); + assert(!t.isctype('Z', t.lookup_classname(s.begin(), s.end()))); + assert(!t.isctype('5', t.lookup_classname(s.begin(), s.end()))); + assert(!t.isctype(' ', t.lookup_classname(s.begin(), s.end()))); + assert(!t.isctype('-', t.lookup_classname(s.begin(), s.end()))); + assert(!t.isctype('@', t.lookup_classname(s.begin(), s.end()))); + + s = "print"; + assert(!t.isctype('\n', t.lookup_classname(s.begin(), s.end()))); + assert( t.isctype('_', t.lookup_classname(s.begin(), s.end()))); + assert( t.isctype('a', t.lookup_classname(s.begin(), s.end()))); + assert( t.isctype('Z', t.lookup_classname(s.begin(), s.end()))); + assert( t.isctype('5', t.lookup_classname(s.begin(), s.end()))); + assert( t.isctype(' ', t.lookup_classname(s.begin(), s.end()))); + assert( t.isctype('-', t.lookup_classname(s.begin(), s.end()))); + assert( t.isctype('@', t.lookup_classname(s.begin(), s.end()))); + + s = "punct"; + assert(!t.isctype('\n', t.lookup_classname(s.begin(), s.end()))); + assert( t.isctype('_', t.lookup_classname(s.begin(), s.end()))); + assert(!t.isctype('a', t.lookup_classname(s.begin(), s.end()))); + assert(!t.isctype('Z', t.lookup_classname(s.begin(), s.end()))); + assert(!t.isctype('5', t.lookup_classname(s.begin(), s.end()))); + assert(!t.isctype(' ', t.lookup_classname(s.begin(), s.end()))); + assert( t.isctype('-', t.lookup_classname(s.begin(), s.end()))); + assert( t.isctype('@', t.lookup_classname(s.begin(), s.end()))); + + s = "space"; + assert( t.isctype('\n', t.lookup_classname(s.begin(), s.end()))); + assert(!t.isctype('_', t.lookup_classname(s.begin(), s.end()))); + assert(!t.isctype('a', t.lookup_classname(s.begin(), s.end()))); + assert(!t.isctype('Z', t.lookup_classname(s.begin(), s.end()))); + assert(!t.isctype('5', t.lookup_classname(s.begin(), s.end()))); + assert( t.isctype(' ', t.lookup_classname(s.begin(), s.end()))); + assert(!t.isctype('-', t.lookup_classname(s.begin(), s.end()))); + assert(!t.isctype('@', t.lookup_classname(s.begin(), s.end()))); + + s = "upper"; + assert(!t.isctype('\n', t.lookup_classname(s.begin(), s.end()))); + assert(!t.isctype('_', t.lookup_classname(s.begin(), s.end()))); + assert(!t.isctype('a', t.lookup_classname(s.begin(), s.end()))); + assert( t.isctype('Z', t.lookup_classname(s.begin(), s.end()))); + assert(!t.isctype('5', t.lookup_classname(s.begin(), s.end()))); + assert(!t.isctype(' ', t.lookup_classname(s.begin(), s.end()))); + assert(!t.isctype('-', t.lookup_classname(s.begin(), s.end()))); + assert(!t.isctype('@', t.lookup_classname(s.begin(), s.end()))); + + s = "xdigit"; + assert(!t.isctype('\n', t.lookup_classname(s.begin(), s.end()))); + assert(!t.isctype('_', t.lookup_classname(s.begin(), s.end()))); + assert( t.isctype('a', t.lookup_classname(s.begin(), s.end()))); + assert(!t.isctype('Z', t.lookup_classname(s.begin(), s.end()))); + assert( t.isctype('5', t.lookup_classname(s.begin(), s.end()))); + assert(!t.isctype(' ', t.lookup_classname(s.begin(), s.end()))); + assert(!t.isctype('-', t.lookup_classname(s.begin(), s.end()))); + assert(!t.isctype('@', t.lookup_classname(s.begin(), s.end()))); + } + { + std::regex_traits t; + + std::wstring s(L"w"); + assert( t.isctype(L'_', t.lookup_classname(s.begin(), s.end()))); + assert( t.isctype(L'a', t.lookup_classname(s.begin(), s.end()))); + assert( t.isctype(L'Z', t.lookup_classname(s.begin(), s.end()))); + assert( t.isctype(L'5', t.lookup_classname(s.begin(), s.end()))); + assert(!t.isctype(L' ', t.lookup_classname(s.begin(), s.end()))); + assert(!t.isctype(L'-', t.lookup_classname(s.begin(), s.end()))); + assert(!t.isctype(L'@', t.lookup_classname(s.begin(), s.end()))); + + s = L"alnum"; + assert(!t.isctype(L'_', t.lookup_classname(s.begin(), s.end()))); + assert( t.isctype(L'a', t.lookup_classname(s.begin(), s.end()))); + assert( t.isctype(L'Z', t.lookup_classname(s.begin(), s.end()))); + assert( t.isctype(L'5', t.lookup_classname(s.begin(), s.end()))); + assert(!t.isctype(L' ', t.lookup_classname(s.begin(), s.end()))); + assert(!t.isctype(L'-', t.lookup_classname(s.begin(), s.end()))); + assert(!t.isctype(L'@', t.lookup_classname(s.begin(), s.end()))); + + s = L"alpha"; + assert(!t.isctype(L'_', t.lookup_classname(s.begin(), s.end()))); + assert( t.isctype(L'a', t.lookup_classname(s.begin(), s.end()))); + assert( t.isctype(L'Z', t.lookup_classname(s.begin(), s.end()))); + assert(!t.isctype(L'5', t.lookup_classname(s.begin(), s.end()))); + assert(!t.isctype(L' ', t.lookup_classname(s.begin(), s.end()))); + assert(!t.isctype(L'-', t.lookup_classname(s.begin(), s.end()))); + assert(!t.isctype(L'@', t.lookup_classname(s.begin(), s.end()))); + + s = L"blank"; + assert(!t.isctype(L'_', t.lookup_classname(s.begin(), s.end()))); + assert(!t.isctype(L'a', t.lookup_classname(s.begin(), s.end()))); + assert(!t.isctype(L'Z', t.lookup_classname(s.begin(), s.end()))); + assert(!t.isctype(L'5', t.lookup_classname(s.begin(), s.end()))); + assert( t.isctype(L' ', t.lookup_classname(s.begin(), s.end()))); + assert(!t.isctype(L'-', t.lookup_classname(s.begin(), s.end()))); + assert(!t.isctype(L'@', t.lookup_classname(s.begin(), s.end()))); + + s = L"cntrl"; + assert( t.isctype(L'\n', t.lookup_classname(s.begin(), s.end()))); + assert(!t.isctype(L'_', t.lookup_classname(s.begin(), s.end()))); + assert(!t.isctype(L'a', t.lookup_classname(s.begin(), s.end()))); + assert(!t.isctype(L'Z', t.lookup_classname(s.begin(), s.end()))); + assert(!t.isctype(L'5', t.lookup_classname(s.begin(), s.end()))); + assert(!t.isctype(L' ', t.lookup_classname(s.begin(), s.end()))); + assert(!t.isctype(L'-', t.lookup_classname(s.begin(), s.end()))); + assert(!t.isctype(L'@', t.lookup_classname(s.begin(), s.end()))); + + s = L"digit"; + assert(!t.isctype(L'\n', t.lookup_classname(s.begin(), s.end()))); + assert(!t.isctype(L'_', t.lookup_classname(s.begin(), s.end()))); + assert(!t.isctype(L'a', t.lookup_classname(s.begin(), s.end()))); + assert(!t.isctype(L'Z', t.lookup_classname(s.begin(), s.end()))); + assert( t.isctype(L'5', t.lookup_classname(s.begin(), s.end()))); + assert(!t.isctype(L' ', t.lookup_classname(s.begin(), s.end()))); + assert(!t.isctype(L'-', t.lookup_classname(s.begin(), s.end()))); + assert(!t.isctype(L'@', t.lookup_classname(s.begin(), s.end()))); + + s = L"graph"; + assert(!t.isctype(L'\n', t.lookup_classname(s.begin(), s.end()))); + assert( t.isctype(L'_', t.lookup_classname(s.begin(), s.end()))); + assert( t.isctype(L'a', t.lookup_classname(s.begin(), s.end()))); + assert( t.isctype(L'Z', t.lookup_classname(s.begin(), s.end()))); + assert( t.isctype(L'5', t.lookup_classname(s.begin(), s.end()))); + assert(!t.isctype(L' ', t.lookup_classname(s.begin(), s.end()))); + assert( t.isctype(L'-', t.lookup_classname(s.begin(), s.end()))); + assert( t.isctype(L'@', t.lookup_classname(s.begin(), s.end()))); + + s = L"lower"; + assert(!t.isctype(L'\n', t.lookup_classname(s.begin(), s.end()))); + assert(!t.isctype(L'_', t.lookup_classname(s.begin(), s.end()))); + assert( t.isctype(L'a', t.lookup_classname(s.begin(), s.end()))); + assert(!t.isctype(L'Z', t.lookup_classname(s.begin(), s.end()))); + assert(!t.isctype(L'5', t.lookup_classname(s.begin(), s.end()))); + assert(!t.isctype(L' ', t.lookup_classname(s.begin(), s.end()))); + assert(!t.isctype(L'-', t.lookup_classname(s.begin(), s.end()))); + assert(!t.isctype(L'@', t.lookup_classname(s.begin(), s.end()))); + + s = L"print"; + assert(!t.isctype(L'\n', t.lookup_classname(s.begin(), s.end()))); + assert( t.isctype(L'_', t.lookup_classname(s.begin(), s.end()))); + assert( t.isctype(L'a', t.lookup_classname(s.begin(), s.end()))); + assert( t.isctype(L'Z', t.lookup_classname(s.begin(), s.end()))); + assert( t.isctype(L'5', t.lookup_classname(s.begin(), s.end()))); + assert( t.isctype(L' ', t.lookup_classname(s.begin(), s.end()))); + assert( t.isctype(L'-', t.lookup_classname(s.begin(), s.end()))); + assert( t.isctype(L'@', t.lookup_classname(s.begin(), s.end()))); + + s = L"punct"; + assert(!t.isctype(L'\n', t.lookup_classname(s.begin(), s.end()))); + assert( t.isctype(L'_', t.lookup_classname(s.begin(), s.end()))); + assert(!t.isctype(L'a', t.lookup_classname(s.begin(), s.end()))); + assert(!t.isctype(L'Z', t.lookup_classname(s.begin(), s.end()))); + assert(!t.isctype(L'5', t.lookup_classname(s.begin(), s.end()))); + assert(!t.isctype(L' ', t.lookup_classname(s.begin(), s.end()))); + assert( t.isctype(L'-', t.lookup_classname(s.begin(), s.end()))); + assert( t.isctype(L'@', t.lookup_classname(s.begin(), s.end()))); + + s = L"space"; + assert( t.isctype(L'\n', t.lookup_classname(s.begin(), s.end()))); + assert(!t.isctype(L'_', t.lookup_classname(s.begin(), s.end()))); + assert(!t.isctype(L'a', t.lookup_classname(s.begin(), s.end()))); + assert(!t.isctype(L'Z', t.lookup_classname(s.begin(), s.end()))); + assert(!t.isctype(L'5', t.lookup_classname(s.begin(), s.end()))); + assert( t.isctype(L' ', t.lookup_classname(s.begin(), s.end()))); + assert(!t.isctype(L'-', t.lookup_classname(s.begin(), s.end()))); + assert(!t.isctype(L'@', t.lookup_classname(s.begin(), s.end()))); + + s = L"upper"; + assert(!t.isctype(L'\n', t.lookup_classname(s.begin(), s.end()))); + assert(!t.isctype(L'_', t.lookup_classname(s.begin(), s.end()))); + assert(!t.isctype(L'a', t.lookup_classname(s.begin(), s.end()))); + assert( t.isctype(L'Z', t.lookup_classname(s.begin(), s.end()))); + assert(!t.isctype(L'5', t.lookup_classname(s.begin(), s.end()))); + assert(!t.isctype(L' ', t.lookup_classname(s.begin(), s.end()))); + assert(!t.isctype(L'-', t.lookup_classname(s.begin(), s.end()))); + assert(!t.isctype(L'@', t.lookup_classname(s.begin(), s.end()))); + + s = L"xdigit"; + assert(!t.isctype(L'\n', t.lookup_classname(s.begin(), s.end()))); + assert(!t.isctype(L'_', t.lookup_classname(s.begin(), s.end()))); + assert( t.isctype(L'a', t.lookup_classname(s.begin(), s.end()))); + assert(!t.isctype(L'Z', t.lookup_classname(s.begin(), s.end()))); + assert( t.isctype(L'5', t.lookup_classname(s.begin(), s.end()))); + assert(!t.isctype(L' ', t.lookup_classname(s.begin(), s.end()))); + assert(!t.isctype(L'-', t.lookup_classname(s.begin(), s.end()))); + assert(!t.isctype(L'@', t.lookup_classname(s.begin(), s.end()))); + } } diff --git a/test/re/re.traits/lookup_classname.pass.cpp b/test/re/re.traits/lookup_classname.pass.cpp index 80df4ce0..20baf01a 100644 --- a/test/re/re.traits/lookup_classname.pass.cpp +++ b/test/re/re.traits/lookup_classname.pass.cpp @@ -17,8 +17,193 @@ // bool icase = false) const; #include +#include +#include "iterators.h" + +template +void +test(const char_type* A, std::ctype_base::mask expected, bool icase = false) +{ + std::regex_traits t; + typedef forward_iterator F; + assert(t.lookup_classname(F(A), F(A + t.length(A)), icase) == expected); +} int main() { -#error lookup_classname not implemented + test("d", std::ctype_base::digit); + test("D", std::ctype_base::digit); + test("d", std::ctype_base::digit, true); + test("D", std::ctype_base::digit, true); + + test("w", std::regex_traits::__regex_word | std::ctype_base::alnum + | std::ctype_base::upper | std::ctype_base::lower); + test("W", std::regex_traits::__regex_word | std::ctype_base::alnum + | std::ctype_base::upper | std::ctype_base::lower); + test("w", std::regex_traits::__regex_word | std::ctype_base::alnum + | std::ctype_base::upper | std::ctype_base::lower, true); + test("W", std::regex_traits::__regex_word | std::ctype_base::alnum + | std::ctype_base::upper | std::ctype_base::lower, true); + + test("s", std::ctype_base::space); + test("S", std::ctype_base::space); + test("s", std::ctype_base::space, true); + test("S", std::ctype_base::space, true); + + test("alnum", std::ctype_base::alnum); + test("AlNum", std::ctype_base::alnum); + test("alnum", std::ctype_base::alnum, true); + test("AlNum", std::ctype_base::alnum, true); + + test("alpha", std::ctype_base::alpha); + test("Alpha", std::ctype_base::alpha); + test("alpha", std::ctype_base::alpha, true); + test("Alpha", std::ctype_base::alpha, true); + + test("blank", std::ctype_base::blank); + test("Blank", std::ctype_base::blank); + test("blank", std::ctype_base::blank, true); + test("Blank", std::ctype_base::blank, true); + + test("cntrl", std::ctype_base::cntrl); + test("Cntrl", std::ctype_base::cntrl); + test("cntrl", std::ctype_base::cntrl, true); + test("Cntrl", std::ctype_base::cntrl, true); + + test("digit", std::ctype_base::digit); + test("Digit", std::ctype_base::digit); + test("digit", std::ctype_base::digit, true); + test("Digit", std::ctype_base::digit, true); + + test("digit", std::ctype_base::digit); + test("DIGIT", std::ctype_base::digit); + test("digit", std::ctype_base::digit, true); + test("Digit", std::ctype_base::digit, true); + + test("graph", std::ctype_base::graph); + test("GRAPH", std::ctype_base::graph); + test("graph", std::ctype_base::graph, true); + test("Graph", std::ctype_base::graph, true); + + test("lower", std::ctype_base::lower); + test("LOWER", std::ctype_base::lower); + test("lower", std::ctype_base::lower | std::ctype_base::alpha, true); + test("Lower", std::ctype_base::lower | std::ctype_base::alpha, true); + + test("print", std::ctype_base::print); + test("PRINT", std::ctype_base::print); + test("print", std::ctype_base::print, true); + test("Print", std::ctype_base::print, true); + + test("punct", std::ctype_base::punct); + test("PUNCT", std::ctype_base::punct); + test("punct", std::ctype_base::punct, true); + test("Punct", std::ctype_base::punct, true); + + test("space", std::ctype_base::space); + test("SPACE", std::ctype_base::space); + test("space", std::ctype_base::space, true); + test("Space", std::ctype_base::space, true); + + test("upper", std::ctype_base::upper); + test("UPPER", std::ctype_base::upper); + test("upper", std::ctype_base::upper | std::ctype_base::alpha, true); + test("Upper", std::ctype_base::upper | std::ctype_base::alpha, true); + + test("xdigit", std::ctype_base::xdigit); + test("XDIGIT", std::ctype_base::xdigit); + test("xdigit", std::ctype_base::xdigit, true); + test("Xdigit", std::ctype_base::xdigit, true); + + test("dig", 0); + test("", 0); + test("digits", 0); + + test(L"d", std::ctype_base::digit); + test(L"D", std::ctype_base::digit); + test(L"d", std::ctype_base::digit, true); + test(L"D", std::ctype_base::digit, true); + + test(L"w", std::regex_traits::__regex_word | std::ctype_base::alnum + | std::ctype_base::upper | std::ctype_base::lower); + test(L"W", std::regex_traits::__regex_word | std::ctype_base::alnum + | std::ctype_base::upper | std::ctype_base::lower); + test(L"w", std::regex_traits::__regex_word | std::ctype_base::alnum + | std::ctype_base::upper | std::ctype_base::lower, true); + test(L"W", std::regex_traits::__regex_word | std::ctype_base::alnum + | std::ctype_base::upper | std::ctype_base::lower, true); + + test(L"s", std::ctype_base::space); + test(L"S", std::ctype_base::space); + test(L"s", std::ctype_base::space, true); + test(L"S", std::ctype_base::space, true); + + test(L"alnum", std::ctype_base::alnum); + test(L"AlNum", std::ctype_base::alnum); + test(L"alnum", std::ctype_base::alnum, true); + test(L"AlNum", std::ctype_base::alnum, true); + + test(L"alpha", std::ctype_base::alpha); + test(L"Alpha", std::ctype_base::alpha); + test(L"alpha", std::ctype_base::alpha, true); + test(L"Alpha", std::ctype_base::alpha, true); + + test(L"blank", std::ctype_base::blank); + test(L"Blank", std::ctype_base::blank); + test(L"blank", std::ctype_base::blank, true); + test(L"Blank", std::ctype_base::blank, true); + + test(L"cntrl", std::ctype_base::cntrl); + test(L"Cntrl", std::ctype_base::cntrl); + test(L"cntrl", std::ctype_base::cntrl, true); + test(L"Cntrl", std::ctype_base::cntrl, true); + + test(L"digit", std::ctype_base::digit); + test(L"Digit", std::ctype_base::digit); + test(L"digit", std::ctype_base::digit, true); + test(L"Digit", std::ctype_base::digit, true); + + test(L"digit", std::ctype_base::digit); + test(L"DIGIT", std::ctype_base::digit); + test(L"digit", std::ctype_base::digit, true); + test(L"Digit", std::ctype_base::digit, true); + + test(L"graph", std::ctype_base::graph); + test(L"GRAPH", std::ctype_base::graph); + test(L"graph", std::ctype_base::graph, true); + test(L"Graph", std::ctype_base::graph, true); + + test(L"lower", std::ctype_base::lower); + test(L"LOWER", std::ctype_base::lower); + test(L"lower", std::ctype_base::lower | std::ctype_base::alpha, true); + test(L"Lower", std::ctype_base::lower | std::ctype_base::alpha, true); + + test(L"print", std::ctype_base::print); + test(L"PRINT", std::ctype_base::print); + test(L"print", std::ctype_base::print, true); + test(L"Print", std::ctype_base::print, true); + + test(L"punct", std::ctype_base::punct); + test(L"PUNCT", std::ctype_base::punct); + test(L"punct", std::ctype_base::punct, true); + test(L"Punct", std::ctype_base::punct, true); + + test(L"space", std::ctype_base::space); + test(L"SPACE", std::ctype_base::space); + test(L"space", std::ctype_base::space, true); + test(L"Space", std::ctype_base::space, true); + + test(L"upper", std::ctype_base::upper); + test(L"UPPER", std::ctype_base::upper); + test(L"upper", std::ctype_base::upper | std::ctype_base::alpha, true); + test(L"Upper", std::ctype_base::upper | std::ctype_base::alpha, true); + + test(L"xdigit", std::ctype_base::xdigit); + test(L"XDIGIT", std::ctype_base::xdigit); + test(L"xdigit", std::ctype_base::xdigit, true); + test(L"Xdigit", std::ctype_base::xdigit, true); + + test(L"dig", 0); + test(L"", 0); + test(L"digits", 0); } diff --git a/test/re/re.traits/value.pass.cpp b/test/re/re.traits/value.pass.cpp index c2e8b0d6..4cbf924d 100644 --- a/test/re/re.traits/value.pass.cpp +++ b/test/re/re.traits/value.pass.cpp @@ -13,9 +13,115 @@ // int value(charT ch, int radix) const; +#include + #include +#include int main() { -#error value not implemented + { + std::regex_traits t; + + for (char c = 0; c < '0'; ++c) + { + assert(t.value(c, 8) == -1); + assert(t.value(c, 10) == -1); + assert(t.value(c, 16) == -1); + } + for (char c = '0'; c < '8'; ++c) + { + assert(t.value(c, 8) == c - '0'); + assert(t.value(c, 10) == c - '0'); + assert(t.value(c, 16) == c - '0'); + } + for (char c = '8'; c < ':'; ++c) + { + assert(t.value(c, 8) == -1); + assert(t.value(c, 10) == c - '0'); + assert(t.value(c, 16) == c - '0'); + } + for (char c = ':'; c < 'A'; ++c) + { + assert(t.value(c, 8) == -1); + assert(t.value(c, 10) == -1); + assert(t.value(c, 16) == -1); + } + for (char c = 'A'; c < 'G'; ++c) + { + assert(t.value(c, 8) == -1); + assert(t.value(c, 10) == -1); + assert(t.value(c, 16) == c - 'A' +10); + } + for (char c = 'G'; c < 'a'; ++c) + { + assert(t.value(c, 8) == -1); + assert(t.value(c, 10) == -1); + assert(t.value(c, 16) == -1); + } + for (char c = 'a'; c < 'g'; ++c) + { + assert(t.value(c, 8) == -1); + assert(t.value(c, 10) == -1); + assert(t.value(c, 16) == c - 'a' +10); + } + for (int c = 'g'; c < 256; ++c) + { + assert(t.value(char(c), 8) == -1); + assert(t.value(char(c), 10) == -1); + assert(t.value(char(c), 16) == -1); + } + } + { + std::regex_traits t; + + for (wchar_t c = 0; c < '0'; ++c) + { + assert(t.value(c, 8) == -1); + assert(t.value(c, 10) == -1); + assert(t.value(c, 16) == -1); + } + for (wchar_t c = '0'; c < '8'; ++c) + { + assert(t.value(c, 8) == c - '0'); + assert(t.value(c, 10) == c - '0'); + assert(t.value(c, 16) == c - '0'); + } + for (wchar_t c = '8'; c < ':'; ++c) + { + assert(t.value(c, 8) == -1); + assert(t.value(c, 10) == c - '0'); + assert(t.value(c, 16) == c - '0'); + } + for (wchar_t c = ':'; c < 'A'; ++c) + { + assert(t.value(c, 8) == -1); + assert(t.value(c, 10) == -1); + assert(t.value(c, 16) == -1); + } + for (wchar_t c = 'A'; c < 'G'; ++c) + { + assert(t.value(c, 8) == -1); + assert(t.value(c, 10) == -1); + assert(t.value(c, 16) == c - 'A' +10); + } + for (wchar_t c = 'G'; c < 'a'; ++c) + { + assert(t.value(c, 8) == -1); + assert(t.value(c, 10) == -1); + assert(t.value(c, 16) == -1); + } + for (wchar_t c = 'a'; c < 'g'; ++c) + { + assert(t.value(c, 8) == -1); + assert(t.value(c, 10) == -1); + assert(t.value(c, 16) == c - 'a' +10); + } + for (int c = 'g'; c < 0xFFFF; ++c) + { + assert(t.value(c, 8) == -1); + assert(t.value(c, 10) == -1); + assert(t.value(c, 16) == -1); + } + } }