diff options
author | Howard Hinnant <hhinnant@apple.com> | 2010-06-21 21:01:43 +0000 |
---|---|---|
committer | Howard Hinnant <hhinnant@apple.com> | 2010-06-21 21:01:43 +0000 |
commit | 24757ff75e5f1af2405ad45280bcadd6d344762c (patch) | |
tree | 13019a4e8e39a3a3b4294e8159d83ce5b69d56cc /libcxx/src/regex.cpp | |
parent | 280e61f148d66ba5a5352e7d9dfa70ce64f1fa29 (diff) | |
download | bcm5719-llvm-24757ff75e5f1af2405ad45280bcadd6d344762c.tar.gz bcm5719-llvm-24757ff75e5f1af2405ad45280bcadd6d344762c.zip |
Finished [re.traits]. I'd like to acknowledge the help of Bjorn Reese with <regex>.
llvm-svn: 106478
Diffstat (limited to 'libcxx/src/regex.cpp')
-rw-r--r-- | libcxx/src/regex.cpp | 49 |
1 files changed, 47 insertions, 2 deletions
diff --git a/libcxx/src/regex.cpp b/libcxx/src/regex.cpp index 5dff39648ad..abb1b66853c 100644 --- a/libcxx/src/regex.cpp +++ b/libcxx/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<char>::__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<collationnames*, collationnames*> 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<char>::__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 |