diff --git a/include/regex b/include/regex new file mode 100644 index 00000000..eab475d6 --- /dev/null +++ b/include/regex @@ -0,0 +1,1121 @@ +// -*- C++ -*- +//===--------------------------- regex ------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCPP_REGEX +#define _LIBCPP_REGEX + +/* + regex synopsis + +#include + +namespace std +{ + +namespace regex_constants +{ + +emum syntax_option_type +{ + icase = unspecified, + nosubs = unspecified, + optimize = unspecified, + collate = unspecified, + ECMAScript = unspecified, + basic = unspecified, + extended = unspecified, + awk = unspecified, + grep = unspecified, + egrep = unspecified +}; + +constexpr syntax_option_type operator~(syntax_option_type f); +constexpr syntax_option_type operator&(syntax_option_type lhs, syntax_option_type rhs); +constexpr syntax_option_type operator|(syntax_option_type lhs, syntax_option_type rhs); + +enum match_flag_type +{ + match_default = 0, + match_not_bol = unspecified, + match_not_eol = unspecified, + match_not_bow = unspecified, + match_not_eow = unspecified, + match_any = unspecified, + match_not_null = unspecified, + match_continuous = unspecified, + match_prev_avail = unspecified, + format_default = 0, + format_sed = unspecified, + format_no_copy = unspecified, + format_first_only = unspecified +}; + +constexpr match_flag_type operator~(match_flag_type f); +constexpr match_flag_type operator&(match_flag_type lhs, match_flag_type rhs); +constexpr match_flag_type operator|(match_flag_type lhs, match_flag_type rhs); + +enum error_type +{ + error_collate = unspecified, + error_ctype = unspecified, + error_escape = unspecified, + error_backref = unspecified, + error_brack = unspecified, + error_paren = unspecified, + error_brace = unspecified, + error_badbrace = unspecified, + error_range = unspecified, + error_space = unspecified, + error_badrepeat = unspecified, + error_complexity = unspecified, + error_stack = unspecified +}; + +} // regex_constants + +class regex_error + : public runtime_error +{ +public: + explicit regex_error(regex_constants::error_type ecode); + regex_constants::error_type code() const; +}; + +template +struct regex_traits +{ +public: + typedef charT char_type; + typedef basic_string string_type; + typedef locale locale_type; + typedef /bitmask_type/ char_class_type; + + regex_traits(); + + static size_t length(const char_type* p); + charT translate(charT c) const; + charT translate_nocase(charT c) const; + template + string_type + transform(ForwardIterator first, ForwardIterator last) const; + template + string_type + transform_primary( ForwardIterator first, ForwardIterator last) const; + template + string_type + lookup_collatename(ForwardIterator first, ForwardIterator last) const; + template + char_class_type + lookup_classname(ForwardIterator first, ForwardIterator last, + bool icase = false) const; + bool isctype(charT c, char_class_type f) const; + int value(charT ch, int radix) const; + locale_type imbue(locale_type l); + locale_type getloc()const; +}; + +template > +class basic_regex +{ +public: + // types: + typedef charT value_type; + typedef regex_constants::syntax_option_type flag_type; + typedef typename traits::locale_type locale_type; + + // constants: + static constexpr regex_constants::syntax_option_type icase = regex_constants::icase; + static constexpr regex_constants::syntax_option_type nosubs = regex_constants::nosubs; + static constexpr regex_constants::syntax_option_type optimize = regex_constants::optimize; + static constexpr regex_constants::syntax_option_type collate = regex_constants::collate; + static constexpr regex_constants::syntax_option_type ECMAScript = regex_constants::ECMAScript; + static constexpr regex_constants::syntax_option_type basic = regex_constants::basic; + static constexpr regex_constants::syntax_option_type extended = regex_constants::extended; + static constexpr regex_constants::syntax_option_type awk = regex_constants::awk; + static constexpr regex_constants::syntax_option_type grep = regex_constants::grep; + static constexpr regex_constants::syntax_option_type egrep = regex_constants::egrep; + + // construct/copy/destroy: + basic_regex(); + explicit basic_regex(const charT* p, flag_type f = regex_constants::ECMAScript); + basic_regex(const charT* p, size_t len, flag_type f); + basic_regex(const basic_regex&); + basic_regex(basic_regex&&); + template + explicit basic_regex(const basic_string& p, + flag_type f = regex_constants::ECMAScript); + template + basic_regex(ForwardIterator first, ForwardIterator last, + flag_type f = regex_constants::ECMAScript); + basic_regex(initializer_list, flag_type = regex_constants::ECMAScript); + + ~basic_regex(); + + basic_regex& operator=(const basic_regex&); + basic_regex& operator=(basic_regex&&); + basic_regex& operator=(const charT* ptr); + basic_regex& operator=(initializer_list il); + template + basic_regex& operator=(const basic_string& p); + + // assign: + basic_regex& assign(const basic_regex& that); + basic_regex& assign(basic_regex&& that); + basic_regex& assign(const charT* ptr, flag_type f = regex_constants::ECMAScript); + basic_regex& assign(const charT* p, size_t len, flag_type f); + template + basic_regex& assign(const basic_string& s, + flag_type f = regex_constants::ECMAScript); + template + basic_regex& assign(InputIterator first, InputIterator last, + flag_type f = regex_constants::ECMAScript); + basic_regex& assign(initializer_list, flag_type = regex_constants::ECMAScript); + + // const operations: + unsigned mark_count() const; + flag_type flags() const; + + // locale: + locale_type imbue(locale_type loc); + locale_type getloc() const; + + // swap: + void swap(basic_regex&); +}; + +typedef basic_regex regex; +typedef basic_regex wregex; + +template + void swap(basic_regex& e1, basic_regex& e2); + +template +class sub_match + : public pair +{ +public: + typedef typename iterator_traits::value_type value_type; + typedef typename iterator_traits::difference_type difference_type; + typedef BidirectionalIterator iterator; + typedef basic_string string_type; + + bool matched; + + difference_type length() const; + operator string_type() const; + string_type str() const; + + int compare(const sub_match& s) const; + int compare(const string_type& s) const; + int compare(const value_type* s) const; +}; + +typedef sub_match csub_match; +typedef sub_match wcsub_match; +typedef sub_match ssub_match; +typedef sub_match wssub_match; + +template + bool + operator==(const sub_match& lhs, const sub_match& rhs); + +template + bool + operator!=(const sub_match& lhs, const sub_match& rhs); + +template + bool + operator<(const sub_match& lhs, const sub_match& rhs); + +template + bool + operator<=(const sub_match& lhs, const sub_match& rhs); + +template + bool + operator>=(const sub_match& lhs, const sub_match& rhs); + +template + bool + operator>(const sub_match& lhs, const sub_match& rhs); + +template + bool + operator==(const basic_string::value_type, ST, SA>& lhs, + const sub_match& rhs); + +template + bool + operator!=(const basic_string::value_type, ST, SA>& lhs, + const sub_match& rhs); + +template + bool + operator<(const basic_string::value_type, ST, SA>& lhs, + const sub_match& rhs); + +template + bool + operator>(const basic_string::value_type, ST, SA>& lhs, + const sub_match& rhs); + +template + bool operator>=(const basic_string::value_type, ST, SA>& lhs, + const sub_match& rhs); + +template + bool + operator<=(const basic_string::value_type, ST, SA>& lhs, + const sub_match& rhs); + +template + bool + operator==(const sub_match& lhs, + const basic_string::value_type, ST, SA>& rhs); + +template + bool + operator!=(const sub_match& lhs, + const basic_string::value_type, ST, SA>& rhs); + +template + bool + operator<(const sub_match& lhs, + const basic_string::value_type, ST, SA>& rhs); + +template + bool operator>(const sub_match& lhs, + const basic_string::value_type, ST, SA>& rhs); + +template + bool + operator>=(const sub_match& lhs, + const basic_string::value_type, ST, SA>& rhs); + +template + bool + operator<=(const sub_match& lhs, + const basic_string::value_type, ST, SA>& rhs); + +template + bool + operator==(typename iterator_traits::value_type const* lhs, + const sub_match& rhs); + +template + bool + operator!=(typename iterator_traits::value_type const* lhs, + const sub_match& rhs); + +template + bool + operator<(typename iterator_traits::value_type const* lhs, + const sub_match& rhs); + +template + bool + operator>(typename iterator_traits::value_type const* lhs, + const sub_match& rhs); + +template + bool + operator>=(typename iterator_traits::value_type const* lhs, + const sub_match& rhs); + +template + bool + operator<=(typename iterator_traits::value_type const* lhs, + const sub_match& rhs); + +template + bool + operator==(const sub_match& lhs, + typename iterator_traits::value_type const* rhs); + +template + bool + operator!=(const sub_match& lhs, + typename iterator_traits::value_type const* rhs); + +template + bool + operator<(const sub_match& lhs, + typename iterator_traits::value_type const* rhs); + +template + bool + operator>(const sub_match& lhs, + typename iterator_traits::value_type const* rhs); + +template + bool + operator>=(const sub_match& lhs, + typename iterator_traits::value_type const* rhs); + +template + bool + operator<=(const sub_match& lhs, + typename iterator_traits::value_type const* rhs); + +template + bool + operator==(typename iterator_traits::value_type const& lhs, + const sub_match& rhs); + +template + bool + operator!=(typename iterator_traits::value_type const& lhs, + const sub_match& rhs); + +template + bool + operator<(typename iterator_traits::value_type const& lhs, + const sub_match& rhs); + +template + bool + operator>(typename iterator_traits::value_type const& lhs, + const sub_match& rhs); + +template + bool + operator>=(typename iterator_traits::value_type const& lhs, + const sub_match& rhs); + +template + bool + operator<=(typename iterator_traits::value_type const& lhs, + const sub_match& rhs); + +template + bool + operator==(const sub_match& lhs, + typename iterator_traits::value_type const& rhs); + +template + bool + operator!=(const sub_match& lhs, + typename iterator_traits::value_type const& rhs); + +template + bool + operator<(const sub_match& lhs, + typename iterator_traits::value_type const& rhs); + +template + bool + operator>(const sub_match& lhs, + typename iterator_traits::value_type const& rhs); + +template + bool + operator>=(const sub_match& lhs, + typename iterator_traits::value_type const& rhs); + +template + bool + operator<=(const sub_match& lhs, + typename iterator_traits::value_type const& rhs); + +template + basic_ostream& + operator<<(basic_ostream& os, const sub_match& m); + +template >> +class match_results +{ +public: + typedef sub_match value_type; + typedef const value_type& const_reference; + typedef const_reference reference; + typedef /implementation-defined/ const_iterator; + typedef const_iterator iterator; + typedef typename iterator_traits::difference_type difference_type; + typedef typename allocator_traits::size_type size_type; + typedef Allocator allocator_type; + typedef typename iterator_traits::value_type char_type; + typedef basic_string string_type; + + // construct/copy/destroy: + explicit match_results(const Allocator& a = Allocator()); + match_results(const match_results& m); + match_results(match_results&& m); + match_results& operator=(const match_results& m); + match_results& operator=(match_results&& m); + ~match_results(); + + // size: + size_type size() const; + size_type max_size() const; + bool empty() const; + + // element access: + difference_type length(size_type sub = 0) const; + difference_type position(size_type sub = 0) const; + string_type str(size_type sub = 0) const; + const_reference operator[](size_type n) const; + + const_reference prefix() const; + const_reference suffix() const; + + const_iterator begin() const; + const_iterator end() const; + const_iterator cbegin() const; + const_iterator cend() const; + + // format: + template + OutputIter + format(OutputIter out, const char_type* fmt_first, + const char_type* fmt_last, + regex_constants::match_flag_type flags = regex_constants::format_default) const; + template + OutputIter + format(OutputIter out, const basic_string& fmt, + regex_constants::match_flag_type flags = regex_constants::format_default) const; + template + basic_string + format(const basic_string& fmt, + regex_constants::match_flag_type flags = regex_constants::format_default) const; + string_type + format(const char_type* fmt, + regex_constants::match_flag_type flags = regex_constants::format_default) const; + + // allocator: + allocator_type get_allocator() const; + + // swap: + void swap(match_results& that); +}; + +typedef match_results cmatch; +typedef match_results wcmatch; +typedef match_results smatch; +typedef match_results wsmatch; + +template + bool + operator==(const match_results& m1, + const match_results& m2); + +template + bool + operator!=(const match_results& m1, + const match_results& m2); + +template + void + swap(match_results& m1, + match_results& m2); + +template + bool + regex_match(BidirectionalIterator first, BidirectionalIterator last, + match_results& m, + const basic_regex& e, + regex_constants::match_flag_type flags = regex_constants::match_default); + +template + bool + regex_match(BidirectionalIterator first, BidirectionalIterator last, + const basic_regex& e, + regex_constants::match_flag_type flags = regex_constants::match_default); + +template + bool + regex_match(const charT* str, match_results& m, + const basic_regex& e, + regex_constants::match_flag_type flags = regex_constants::match_default); + +template + bool + regex_match(const basic_string& s, + match_results::const_iterator, Allocator>& m, + const basic_regex& e, + regex_constants::match_flag_type flags = regex_constants::match_default); + +template + bool + regex_match(const charT* str, const basic_regex& e, + regex_constants::match_flag_type flags = regex_constants::match_default); + +template + bool + regex_match(const basic_string& s, + const basic_regex& e, + regex_constants::match_flag_type flags = regex_constants::match_default); + +template + bool + regex_search(BidirectionalIterator first, BidirectionalIterator last, + match_results& m, + const basic_regex& e, + regex_constants::match_flag_type flags = regex_constants::match_default); + +template + bool + regex_search(BidirectionalIterator first, BidirectionalIterator last, + const basic_regex& e, + regex_constants::match_flag_type flags = regex_constants::match_default); + +template + bool + regex_search(const charT* str, match_results& m, + const basic_regex& e, + regex_constants::match_flag_type flags = regex_constants::match_default); + +template + bool + regex_search(const charT* str, const basic_regex& e, + regex_constants::match_flag_type flags = regex_constants::match_default); + +template + bool + regex_search(const basic_string& s, + const basic_regex& e, + regex_constants::match_flag_type flags = regex_constants::match_default); + +template + bool + regex_search(const basic_string& s, + match_results::const_iterator, Allocator>& m, + const basic_regex& e, + regex_constants::match_flag_type flags = regex_constants::match_default); + +template + OutputIterator + regex_replace(OutputIterator out, + BidirectionalIterator first, BidirectionalIterator last, + const basic_regex& e, + const basic_string& fmt, + regex_constants::match_flag_type flags = regex_constants::match_default); + +template + OutputIterator + regex_replace(OutputIterator out, + BidirectionalIterator first, BidirectionalIterator last, + const basic_regex& e, const charT* fmt, + regex_constants::match_flag_type flags = regex_constants::match_default); + +template > + basic_string + regex_replace(const basic_string& s, + const basic_regex& e, + const basic_string& fmt, + regex_constants::match_flag_type flags = regex_constants::match_default); + +template + basic_string + regex_replace(const basic_string& s, + const basic_regex& e, const charT* fmt, + regex_constants::match_flag_type flags = regex_constants::match_default); + +template + basic_string + regex_replace(const charT* s, + const basic_regex& e, + const basic_string& fmt, + regex_constants::match_flag_type flags = regex_constants::match_default); + +template + basic_string + regex_replace(const charT* s, + const basic_regex& e, + const charT* fmt, + regex_constants::match_flag_type flags = regex_constants::match_default); + +template ::value_type, + class traits = regex_traits> +class regex_iterator +{ +public: + typedef basic_regex regex_type; + typedef match_results value_type; + typedef ptrdiff_t difference_type; + typedef const value_type* pointer; + typedef const value_type& reference; + typedef forward_iterator_tag iterator_category; + + regex_iterator(); + regex_iterator(BidirectionalIterator a, BidirectionalIterator b, + const regex_type& re, + regex_constants::match_flag_type m = regex_constants::match_default); + regex_iterator(const regex_iterator&); + regex_iterator& operator=(const regex_iterator&); + + bool operator==(const regex_iterator&) const; + bool operator!=(const regex_iterator&) const; + + const value_type& operator*() const; + const value_type* operator->() const; + + regex_iterator& operator++(); + regex_iterator operator++(int); +}; + +typedef regex_iterator cregex_iterator; +typedef regex_iterator wcregex_iterator; +typedef regex_iterator sregex_iterator; +typedef regex_iterator wsregex_iterator; + +template ::value_type, + class traits = regex_traits> +class regex_token_iterator +{ +public: + typedef basic_regex regex_type; + typedef sub_match value_type; + typedef ptrdiff_t difference_type; + typedef const value_type* pointer; + typedef const value_type& reference; + typedef forward_iterator_tag iterator_category; + + regex_token_iterator(); + regex_token_iterator(BidirectionalIterator a, BidirectionalIterator b, + const regex_type& re, int submatch = 0, + regex_constants::match_flag_type m = regex_constants::match_default); + regex_token_iterator(BidirectionalIterator a, BidirectionalIterator b, + const regex_type& re, const vector& submatches, + regex_constants::match_flag_type m = regex_constants::match_default); + regex_token_iterator(BidirectionalIterator a, BidirectionalIterator b, + const regex_type& re, initializer_list submatches, + regex_constants::match_flag_type m = regex_constants::match_default); + template + regex_token_iterator(BidirectionalIterator a, BidirectionalIterator b, + const regex_type& re, const int (&submatches)[N], + regex_constants::match_flag_type m = regex_constants::match_default); + regex_token_iterator(const regex_token_iterator&); + regex_token_iterator& operator=(const regex_token_iterator&); + + bool operator==(const regex_token_iterator&) const; + bool operator!=(const regex_token_iterator&) const; + + const value_type& operator*() const; + const value_type* operator->() const; + + regex_token_iterator& operator++(); + regex_token_iterator operator++(int); +}; + +typedef regex_token_iterator cregex_token_iterator; +typedef regex_token_iterator wcregex_token_iterator; +typedef regex_token_iterator sregex_token_iterator; +typedef regex_token_iterator wsregex_token_iterator; + +} // std +*/ + +#include <__config> +#include +#include <__locale> + +#pragma GCC system_header + +_LIBCPP_BEGIN_NAMESPACE_STD + +namespace regex_constants +{ + +// syntax_option_type + +enum syntax_option_type +{ + icase = 1 << 0, + nosubs = 1 << 1, + optimize = 1 << 2, + collate = 1 << 3, + ECMAScript = 1 << 4, + basic = 1 << 5, + extended = 1 << 6, + awk = 1 << 7, + grep = 1 << 8, + egrep = 1 << 9 +}; + +inline +/*constexpr*/ +syntax_option_type +operator~(syntax_option_type __x) +{ + return syntax_option_type(~int(__x)); +} + +inline +/*constexpr*/ +syntax_option_type +operator&(syntax_option_type __x, syntax_option_type __y) +{ + return syntax_option_type(int(__x) & int(__y)); +} + +inline +/*constexpr*/ +syntax_option_type +operator|(syntax_option_type __x, syntax_option_type __y) +{ + return syntax_option_type(int(__x) | int(__y)); +} + +inline +/*constexpr*/ +syntax_option_type +operator^(syntax_option_type __x, syntax_option_type __y) +{ + return syntax_option_type(int(__x) ^ int(__y)); +} + +inline +/*constexpr*/ +syntax_option_type& +operator&=(syntax_option_type& __x, syntax_option_type __y) +{ + __x = __x & __y; + return __x; +} + +inline +/*constexpr*/ +syntax_option_type& +operator|=(syntax_option_type& __x, syntax_option_type __y) +{ + __x = __x | __y; + return __x; +} + +inline +/*constexpr*/ +syntax_option_type& +operator^=(syntax_option_type& __x, syntax_option_type __y) +{ + __x = __x ^ __y; + return __x; +} + +// match_flag_type + +enum match_flag_type +{ + match_default = 0, + match_not_bol = 1 << 0, + match_not_eol = 1 << 1, + match_not_bow = 1 << 2, + match_not_eow = 1 << 3, + match_any = 1 << 4, + match_not_null = 1 << 5, + match_continuous = 1 << 6, + match_prev_avail = 1 << 7, + format_default = 0, + format_sed = 1 << 8, + format_no_copy = 1 << 9, + format_first_only = 1 << 10 +}; + +inline +/*constexpr*/ +match_flag_type +operator~(match_flag_type __x) +{ + return match_flag_type(~int(__x)); +} + +inline +/*constexpr*/ +match_flag_type +operator&(match_flag_type __x, match_flag_type __y) +{ + return match_flag_type(int(__x) & int(__y)); +} + +inline +/*constexpr*/ +match_flag_type +operator|(match_flag_type __x, match_flag_type __y) +{ + return match_flag_type(int(__x) | int(__y)); +} + +inline +/*constexpr*/ +match_flag_type +operator^(match_flag_type __x, match_flag_type __y) +{ + return match_flag_type(int(__x) ^ int(__y)); +} + +inline +/*constexpr*/ +match_flag_type& +operator&=(match_flag_type& __x, match_flag_type __y) +{ + __x = __x & __y; + return __x; +} + +inline +/*constexpr*/ +match_flag_type& +operator|=(match_flag_type& __x, match_flag_type __y) +{ + __x = __x | __y; + return __x; +} + +inline +/*constexpr*/ +match_flag_type& +operator^=(match_flag_type& __x, match_flag_type __y) +{ + __x = __x ^ __y; + return __x; +} + +enum error_type +{ + error_collate = 1, + error_ctype, + error_escape, + error_backref, + error_brack, + error_paren, + error_brace, + error_badbrace, + error_range, + error_space, + error_badrepeat, + error_complexity, + error_stack +}; + +} // regex_constants + +class _LIBCPP_EXCEPTION_ABI regex_error + : public runtime_error +{ + regex_constants::error_type __code_; +public: + explicit regex_error(regex_constants::error_type __ecode); + virtual ~regex_error() throw(); + regex_constants::error_type code() const {return __code_;} +}; + +template +struct regex_traits +{ +public: + typedef _CharT char_type; + typedef basic_string string_type; + typedef locale locale_type; + typedef unsigned char_class_type; + +private: + locale __loc_; + const ctype* __ct_; + const collate* __col_; + +public: + regex_traits(); + + static size_t length(const char_type* __p) + {return char_traits::length(__p);} + char_type translate(char_type __c) const {return __c;} + char_type translate_nocase(char_type __c) const; + template + string_type + transform(_ForwardIterator __f, _ForwardIterator __l) const; + template + string_type + transform_primary( _ForwardIterator __f, _ForwardIterator __l) const + {return __transform_primary(__f, __l, char_type());} + template + string_type + lookup_collatename(_ForwardIterator __f, _ForwardIterator __l) const + {return __lookup_collatename(__f, __l, char_type());} + 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; + locale_type imbue(locale_type __l); + locale_type getloc()const {return __loc_;} + +private: + void __init(); + + template + string_type + __transform_primary(_ForwardIterator __f, _ForwardIterator __l, char) const; + template + string_type + __transform_primary(_ForwardIterator __f, _ForwardIterator __l, wchar_t) const; + + template + string_type + __lookup_collatename(_ForwardIterator __f, _ForwardIterator __l, char) const; + template + string_type + __lookup_collatename(_ForwardIterator __f, _ForwardIterator __l, wchar_t) const; +}; + +template +regex_traits<_CharT>::regex_traits() +{ + __init(); +} + +template +typename regex_traits<_CharT>::char_type +regex_traits<_CharT>::translate_nocase(char_type __c) const +{ + return __ct_->tolower(__c); +} + +template +template +typename regex_traits<_CharT>::string_type +regex_traits<_CharT>::transform(_ForwardIterator __f, _ForwardIterator __l) const +{ + string_type __s(__f, __l); + return __col_->transform(__s.data(), __s.data() + __s.size()); +} + +template +void +regex_traits<_CharT>::__init() +{ + __ct_ = &use_facet >(__loc_); + __col_ = &use_facet >(__loc_); +} + +template +typename regex_traits<_CharT>::locale_type +regex_traits<_CharT>::imbue(locale_type __l) +{ + locale __r = __loc_; + __loc_ = __l; + __init(); + return __r; +} + +// transform_primary is very FreeBSD-specific + +template +template +typename regex_traits<_CharT>::string_type +regex_traits<_CharT>::__transform_primary(_ForwardIterator __f, + _ForwardIterator __l, char) const +{ + const string_type __s(__f, __l); + string_type __d = __col_->transform(__s.data(), __s.data() + __s.size()); + switch (__d.size()) + { + case 1: + break; + case 12: + __d[11] = __d[3]; + break; + default: + __d.clear(); + break; + } + return __d; +} + +template +template +typename regex_traits<_CharT>::string_type +regex_traits<_CharT>::__transform_primary(_ForwardIterator __f, + _ForwardIterator __l, wchar_t) const +{ + const string_type __s(__f, __l); + string_type __d = __col_->transform(__s.data(), __s.data() + __s.size()); + switch (__d.size()) + { + case 1: + break; + case 3: + __d[2] = __d[0]; + break; + default: + __d.clear(); + break; + } + return __d; +} + +// lookup_collatename is very FreeBSD-specific + +string __get_collation_name(const char* s); + +template +template +typename regex_traits<_CharT>::string_type +regex_traits<_CharT>::__lookup_collatename(_ForwardIterator __f, + _ForwardIterator __l, char) const +{ + string_type __s(__f, __l); + string_type __r; + if (!__s.empty()) + { + __r = __get_collation_name(__s.c_str()); + if (__r.empty() && __s.size() <= 2) + { + __r = __col_->transform(__s.data(), __s.data() + __s.size()); + if (__r.size() == 1 || __r.size() == 12) + __r = __s; + else + __r.clear(); + } + } + return __r; +} + +template +template +typename regex_traits<_CharT>::string_type +regex_traits<_CharT>::__lookup_collatename(_ForwardIterator __f, + _ForwardIterator __l, wchar_t) const +{ + string_type __s(__f, __l); + 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 string_type(); + __n.push_back(char(*__i)); + } + string_type __r; + if (!__s.empty()) + { + __n = __get_collation_name(__n.c_str()); + if (!__n.empty()) + __r.assign(__n.begin(), __n.end()); + else if (__s.size() <= 2) + { + __r = __col_->transform(__s.data(), __s.data() + __s.size()); + if (__r.size() == 1 || __r.size() == 3) + __r = __s; + else + __r.clear(); + } + } + return __r; +} + +_LIBCPP_END_NAMESPACE_STD + +#endif // _LIBCPP_REGEX diff --git a/src/regex.cpp b/src/regex.cpp new file mode 100644 index 00000000..5dff3964 --- /dev/null +++ b/src/regex.cpp @@ -0,0 +1,203 @@ +//===-------------------------- regex.cpp ---------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#include "regex" +#include "algorithm" +#include "iterator" + + +_LIBCPP_BEGIN_NAMESPACE_STD + +static +const char* +make_error_type_string(regex_constants::error_type ecode) +{ + switch (ecode) + { + case regex_constants::error_collate: + return "error_collate"; + case regex_constants::error_ctype: + return "error_ctype"; + case regex_constants::error_escape: + return "error_escape"; + case regex_constants::error_backref: + return "error_backref"; + case regex_constants::error_brack: + return "error_brack"; + case regex_constants::error_paren: + return "error_paren"; + case regex_constants::error_brace: + return "error_brace"; + case regex_constants::error_badbrace: + return "error_badbrace"; + case regex_constants::error_range: + return "error_range"; + case regex_constants::error_space: + return "error_space"; + case regex_constants::error_badrepeat: + return "error_badrepeat"; + case regex_constants::error_complexity: + return "error_complexity"; + case regex_constants::error_stack: + return "error_stack"; + } + return "unknown error_type"; +} + +regex_error::regex_error(regex_constants::error_type ecode) + : runtime_error(make_error_type_string(ecode)), + __code_(ecode) +{} + +regex_error::~regex_error() throw() {} + +namespace { + +struct collationnames +{ + const char* elem_; + char char_; +}; + +const collationnames collatenames[] = +{ + {"A", 0x41}, + {"B", 0x42}, + {"C", 0x43}, + {"D", 0x44}, + {"E", 0x45}, + {"F", 0x46}, + {"G", 0x47}, + {"H", 0x48}, + {"I", 0x49}, + {"J", 0x4a}, + {"K", 0x4b}, + {"L", 0x4c}, + {"M", 0x4d}, + {"N", 0x4e}, + {"NUL", 0x00}, + {"O", 0x4f}, + {"P", 0x50}, + {"Q", 0x51}, + {"R", 0x52}, + {"S", 0x53}, + {"T", 0x54}, + {"U", 0x55}, + {"V", 0x56}, + {"W", 0x57}, + {"X", 0x58}, + {"Y", 0x59}, + {"Z", 0x5a}, + {"a", 0x61}, + {"alert", 0x07}, + {"ampersand", 0x26}, + {"apostrophe", 0x27}, + {"asterisk", 0x2a}, + {"b", 0x62}, + {"backslash", 0x5c}, + {"backspace", 0x08}, + {"c", 0x63}, + {"carriage-return", 0x0d}, + {"circumflex", 0x5e}, + {"circumflex-accent", 0x5e}, + {"colon", 0x3a}, + {"comma", 0x2c}, + {"commercial-at", 0x40}, + {"d", 0x64}, + {"dollar-sign", 0x24}, + {"e", 0x65}, + {"eight", 0x38}, + {"equals-sign", 0x3d}, + {"exclamation-mark", 0x21}, + {"f", 0x66}, + {"five", 0x35}, + {"form-feed", 0x0c}, + {"four", 0x34}, + {"full-stop", 0x2e}, + {"g", 0x67}, + {"grave-accent", 0x60}, + {"greater-than-sign", 0x3e}, + {"h", 0x68}, + {"hyphen", 0x2d}, + {"hyphen-minus", 0x2d}, + {"i", 0x69}, + {"j", 0x6a}, + {"k", 0x6b}, + {"l", 0x6c}, + {"left-brace", 0x7b}, + {"left-curly-bracket", 0x7b}, + {"left-parenthesis", 0x28}, + {"left-square-bracket", 0x5b}, + {"less-than-sign", 0x3c}, + {"low-line", 0x5f}, + {"m", 0x6d}, + {"n", 0x6e}, + {"newline", 0x0a}, + {"nine", 0x39}, + {"number-sign", 0x23}, + {"o", 0x6f}, + {"one", 0x31}, + {"p", 0x70}, + {"percent-sign", 0x25}, + {"period", 0x2e}, + {"plus-sign", 0x2b}, + {"q", 0x71}, + {"question-mark", 0x3f}, + {"quotation-mark", 0x22}, + {"r", 0x72}, + {"reverse-solidus", 0x5c}, + {"right-brace", 0x7d}, + {"right-curly-bracket", 0x7d}, + {"right-parenthesis", 0x29}, + {"right-square-bracket", 0x5d}, + {"s", 0x73}, + {"semicolon", 0x3b}, + {"seven", 0x37}, + {"six", 0x36}, + {"slash", 0x2f}, + {"solidus", 0x2f}, + {"space", 0x20}, + {"t", 0x74}, + {"tab", 0x09}, + {"three", 0x33}, + {"tilde", 0x7e}, + {"two", 0x32}, + {"u", 0x75}, + {"underscore", 0x5f}, + {"v", 0x76}, + {"vertical-line", 0x7c}, + {"vertical-tab", 0x0b}, + {"w", 0x77}, + {"x", 0x78}, + {"y", 0x79}, + {"z", 0x7a}, + {"zero", 0x30} +}; + +struct use_strcmp +{ + bool operator()(const collationnames& x, const char* y) + {return strcmp(x.elem_, y) < 0;} +}; + +} + +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; + if (i != end(collatenames) && strcmp(s, i->elem_) == 0) + r = char(i->char_); + return r; +} + +_LIBCPP_END_NAMESPACE_STD diff --git a/test/re/nothing_to_do.pass.cpp b/test/re/nothing_to_do.pass.cpp new file mode 100644 index 00000000..b85601fc --- /dev/null +++ b/test/re/nothing_to_do.pass.cpp @@ -0,0 +1,13 @@ +// -*- C++ -*- +//===-------------------------- algorithm ---------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +int main() +{ +} diff --git a/test/re/re.badexp/regex_error.pass.cpp b/test/re/re.badexp/regex_error.pass.cpp new file mode 100644 index 00000000..6145b8ea --- /dev/null +++ b/test/re/re.badexp/regex_error.pass.cpp @@ -0,0 +1,91 @@ +// -*- C++ -*- +//===-------------------------- algorithm ---------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// class regex_error +// : public runtime_error +// { +// public: +// explicit regex_error(regex_constants::error_type ecode); +// regex_constants::error_type code() const; +// }; + +#include +#include + +int main() +{ + { + std::regex_error e(std::regex_constants::error_collate); + assert(e.code() == std::regex_constants::error_collate); + assert(e.what() == std::string("error_collate")); + } + { + std::regex_error e(std::regex_constants::error_ctype); + assert(e.code() == std::regex_constants::error_ctype); + assert(e.what() == std::string("error_ctype")); + } + { + std::regex_error e(std::regex_constants::error_escape); + assert(e.code() == std::regex_constants::error_escape); + assert(e.what() == std::string("error_escape")); + } + { + std::regex_error e(std::regex_constants::error_backref); + assert(e.code() == std::regex_constants::error_backref); + assert(e.what() == std::string("error_backref")); + } + { + std::regex_error e(std::regex_constants::error_brack); + assert(e.code() == std::regex_constants::error_brack); + assert(e.what() == std::string("error_brack")); + } + { + std::regex_error e(std::regex_constants::error_paren); + assert(e.code() == std::regex_constants::error_paren); + assert(e.what() == std::string("error_paren")); + } + { + std::regex_error e(std::regex_constants::error_brace); + assert(e.code() == std::regex_constants::error_brace); + assert(e.what() == std::string("error_brace")); + } + { + std::regex_error e(std::regex_constants::error_badbrace); + assert(e.code() == std::regex_constants::error_badbrace); + assert(e.what() == std::string("error_badbrace")); + } + { + std::regex_error e(std::regex_constants::error_range); + assert(e.code() == std::regex_constants::error_range); + assert(e.what() == std::string("error_range")); + } + { + std::regex_error e(std::regex_constants::error_space); + assert(e.code() == std::regex_constants::error_space); + assert(e.what() == std::string("error_space")); + } + { + std::regex_error e(std::regex_constants::error_badrepeat); + assert(e.code() == std::regex_constants::error_badrepeat); + assert(e.what() == std::string("error_badrepeat")); + } + { + std::regex_error e(std::regex_constants::error_complexity); + assert(e.code() == std::regex_constants::error_complexity); + assert(e.what() == std::string("error_complexity")); + } + { + std::regex_error e(std::regex_constants::error_stack); + assert(e.code() == std::regex_constants::error_stack); + assert(e.what() == std::string("error_stack")); + } +} diff --git a/test/re/re.const/nothing_to_do.pass.cpp b/test/re/re.const/nothing_to_do.pass.cpp new file mode 100644 index 00000000..b85601fc --- /dev/null +++ b/test/re/re.const/nothing_to_do.pass.cpp @@ -0,0 +1,13 @@ +// -*- C++ -*- +//===-------------------------- algorithm ---------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +int main() +{ +} diff --git a/test/re/re.const/re.err/error_type.pass.cpp b/test/re/re.const/re.err/error_type.pass.cpp new file mode 100644 index 00000000..aab6d62c --- /dev/null +++ b/test/re/re.const/re.err/error_type.pass.cpp @@ -0,0 +1,143 @@ +// -*- C++ -*- +//===-------------------------- algorithm ---------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// namespace regex_constants +// { +// +// enum error_type +// { +// error_collate = unspecified, +// error_ctype = unspecified, +// error_escape = unspecified, +// error_backref = unspecified, +// error_brack = unspecified, +// error_paren = unspecified, +// error_brace = unspecified, +// error_badbrace = unspecified, +// error_range = unspecified, +// error_space = unspecified, +// error_badrepeat = unspecified, +// error_complexity = unspecified, +// error_stack = unspecified +// }; +// +// } + +#include +#include + +int main() +{ + assert(std::regex_constants::error_collate != 0); + assert(std::regex_constants::error_ctype != 0); + assert(std::regex_constants::error_escape != 0); + assert(std::regex_constants::error_backref != 0); + assert(std::regex_constants::error_brack != 0); + assert(std::regex_constants::error_paren != 0); + assert(std::regex_constants::error_brace != 0); + assert(std::regex_constants::error_badbrace != 0); + assert(std::regex_constants::error_range != 0); + assert(std::regex_constants::error_space != 0); + assert(std::regex_constants::error_badrepeat != 0); + assert(std::regex_constants::error_complexity != 0); + assert(std::regex_constants::error_stack != 0); + + assert(std::regex_constants::error_collate != std::regex_constants::error_ctype); + assert(std::regex_constants::error_collate != std::regex_constants::error_escape); + assert(std::regex_constants::error_collate != std::regex_constants::error_backref); + assert(std::regex_constants::error_collate != std::regex_constants::error_brack); + assert(std::regex_constants::error_collate != std::regex_constants::error_paren); + assert(std::regex_constants::error_collate != std::regex_constants::error_brace); + assert(std::regex_constants::error_collate != std::regex_constants::error_badbrace); + assert(std::regex_constants::error_collate != std::regex_constants::error_range); + assert(std::regex_constants::error_collate != std::regex_constants::error_space); + assert(std::regex_constants::error_collate != std::regex_constants::error_badrepeat); + assert(std::regex_constants::error_collate != std::regex_constants::error_complexity); + assert(std::regex_constants::error_collate != std::regex_constants::error_stack); + + assert(std::regex_constants::error_ctype != std::regex_constants::error_escape); + assert(std::regex_constants::error_ctype != std::regex_constants::error_backref); + assert(std::regex_constants::error_ctype != std::regex_constants::error_brack); + assert(std::regex_constants::error_ctype != std::regex_constants::error_paren); + assert(std::regex_constants::error_ctype != std::regex_constants::error_brace); + assert(std::regex_constants::error_ctype != std::regex_constants::error_badbrace); + assert(std::regex_constants::error_ctype != std::regex_constants::error_range); + assert(std::regex_constants::error_ctype != std::regex_constants::error_space); + assert(std::regex_constants::error_ctype != std::regex_constants::error_badrepeat); + assert(std::regex_constants::error_ctype != std::regex_constants::error_complexity); + assert(std::regex_constants::error_ctype != std::regex_constants::error_stack); + + assert(std::regex_constants::error_escape != std::regex_constants::error_backref); + assert(std::regex_constants::error_escape != std::regex_constants::error_brack); + assert(std::regex_constants::error_escape != std::regex_constants::error_paren); + assert(std::regex_constants::error_escape != std::regex_constants::error_brace); + assert(std::regex_constants::error_escape != std::regex_constants::error_badbrace); + assert(std::regex_constants::error_escape != std::regex_constants::error_range); + assert(std::regex_constants::error_escape != std::regex_constants::error_space); + assert(std::regex_constants::error_escape != std::regex_constants::error_badrepeat); + assert(std::regex_constants::error_escape != std::regex_constants::error_complexity); + assert(std::regex_constants::error_escape != std::regex_constants::error_stack); + + assert(std::regex_constants::error_backref != std::regex_constants::error_brack); + assert(std::regex_constants::error_backref != std::regex_constants::error_paren); + assert(std::regex_constants::error_backref != std::regex_constants::error_brace); + assert(std::regex_constants::error_backref != std::regex_constants::error_badbrace); + assert(std::regex_constants::error_backref != std::regex_constants::error_range); + assert(std::regex_constants::error_backref != std::regex_constants::error_space); + assert(std::regex_constants::error_backref != std::regex_constants::error_badrepeat); + assert(std::regex_constants::error_backref != std::regex_constants::error_complexity); + assert(std::regex_constants::error_backref != std::regex_constants::error_stack); + + assert(std::regex_constants::error_brack != std::regex_constants::error_paren); + assert(std::regex_constants::error_brack != std::regex_constants::error_brace); + assert(std::regex_constants::error_brack != std::regex_constants::error_badbrace); + assert(std::regex_constants::error_brack != std::regex_constants::error_range); + assert(std::regex_constants::error_brack != std::regex_constants::error_space); + assert(std::regex_constants::error_brack != std::regex_constants::error_badrepeat); + assert(std::regex_constants::error_brack != std::regex_constants::error_complexity); + assert(std::regex_constants::error_brack != std::regex_constants::error_stack); + + assert(std::regex_constants::error_paren != std::regex_constants::error_brace); + assert(std::regex_constants::error_paren != std::regex_constants::error_badbrace); + assert(std::regex_constants::error_paren != std::regex_constants::error_range); + assert(std::regex_constants::error_paren != std::regex_constants::error_space); + assert(std::regex_constants::error_paren != std::regex_constants::error_badrepeat); + assert(std::regex_constants::error_paren != std::regex_constants::error_complexity); + assert(std::regex_constants::error_paren != std::regex_constants::error_stack); + + assert(std::regex_constants::error_brace != std::regex_constants::error_badbrace); + assert(std::regex_constants::error_brace != std::regex_constants::error_range); + assert(std::regex_constants::error_brace != std::regex_constants::error_space); + assert(std::regex_constants::error_brace != std::regex_constants::error_badrepeat); + assert(std::regex_constants::error_brace != std::regex_constants::error_complexity); + assert(std::regex_constants::error_brace != std::regex_constants::error_stack); + + assert(std::regex_constants::error_badbrace != std::regex_constants::error_range); + assert(std::regex_constants::error_badbrace != std::regex_constants::error_space); + assert(std::regex_constants::error_badbrace != std::regex_constants::error_badrepeat); + assert(std::regex_constants::error_badbrace != std::regex_constants::error_complexity); + assert(std::regex_constants::error_badbrace != std::regex_constants::error_stack); + + assert(std::regex_constants::error_range != std::regex_constants::error_space); + assert(std::regex_constants::error_range != std::regex_constants::error_badrepeat); + assert(std::regex_constants::error_range != std::regex_constants::error_complexity); + assert(std::regex_constants::error_range != std::regex_constants::error_stack); + + assert(std::regex_constants::error_space != std::regex_constants::error_badrepeat); + assert(std::regex_constants::error_space != std::regex_constants::error_complexity); + assert(std::regex_constants::error_space != std::regex_constants::error_stack); + + assert(std::regex_constants::error_badrepeat != std::regex_constants::error_complexity); + assert(std::regex_constants::error_badrepeat != std::regex_constants::error_stack); + + assert(std::regex_constants::error_complexity != std::regex_constants::error_stack); +} diff --git a/test/re/re.const/re.matchflag/match_flag_type.pass.cpp b/test/re/re.const/re.matchflag/match_flag_type.pass.cpp new file mode 100644 index 00000000..cf9a7f49 --- /dev/null +++ b/test/re/re.const/re.matchflag/match_flag_type.pass.cpp @@ -0,0 +1,128 @@ +// -*- C++ -*- +//===-------------------------- algorithm ---------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// namespace regex_constants +// { +// +// emum match_flag_type // bitmask type +// { +// match_default = 0, +// match_not_bol = unspecified, +// match_not_eol = unspecified, +// match_not_bow = unspecified, +// match_not_eow = unspecified, +// match_any = unspecified, +// match_not_null = unspecified, +// match_continuous = unspecified, +// match_prev_avail = unspecified, +// format_default = 0, +// format_sed = unspecified, +// format_no_copy = unspecified, +// format_first_only = unspecified +// }; +// +// } + +#include +#include + +int main() +{ + assert(std::regex_constants::match_default == 0); + assert(std::regex_constants::match_not_bol != 0); + assert(std::regex_constants::match_not_eol != 0); + assert(std::regex_constants::match_not_bow != 0); + assert(std::regex_constants::match_not_eow != 0); + assert(std::regex_constants::match_any != 0); + assert(std::regex_constants::match_not_null != 0); + assert(std::regex_constants::match_continuous != 0); + assert(std::regex_constants::match_prev_avail != 0); + assert(std::regex_constants::format_default == 0); + assert(std::regex_constants::format_sed != 0); + assert(std::regex_constants::format_no_copy != 0); + assert(std::regex_constants::format_first_only != 0); + + assert((std::regex_constants::match_not_bol & std::regex_constants::match_not_eol) == 0); + assert((std::regex_constants::match_not_bol & std::regex_constants::match_not_bow) == 0); + assert((std::regex_constants::match_not_bol & std::regex_constants::match_not_eow) == 0); + assert((std::regex_constants::match_not_bol & std::regex_constants::match_any) == 0); + assert((std::regex_constants::match_not_bol & std::regex_constants::match_not_null) == 0); + assert((std::regex_constants::match_not_bol & std::regex_constants::match_continuous) == 0); + assert((std::regex_constants::match_not_bol & std::regex_constants::match_prev_avail) == 0); + assert((std::regex_constants::match_not_bol & std::regex_constants::format_sed) == 0); + assert((std::regex_constants::match_not_bol & std::regex_constants::format_no_copy) == 0); + assert((std::regex_constants::match_not_bol & std::regex_constants::format_first_only) == 0); + + assert((std::regex_constants::match_not_eol & std::regex_constants::match_not_bow) == 0); + assert((std::regex_constants::match_not_eol & std::regex_constants::match_not_eow) == 0); + assert((std::regex_constants::match_not_eol & std::regex_constants::match_any) == 0); + assert((std::regex_constants::match_not_eol & std::regex_constants::match_not_null) == 0); + assert((std::regex_constants::match_not_eol & std::regex_constants::match_continuous) == 0); + assert((std::regex_constants::match_not_eol & std::regex_constants::match_prev_avail) == 0); + assert((std::regex_constants::match_not_eol & std::regex_constants::format_sed) == 0); + assert((std::regex_constants::match_not_eol & std::regex_constants::format_no_copy) == 0); + assert((std::regex_constants::match_not_eol & std::regex_constants::format_first_only) == 0); + + assert((std::regex_constants::match_not_bow & std::regex_constants::match_not_eow) == 0); + assert((std::regex_constants::match_not_bow & std::regex_constants::match_any) == 0); + assert((std::regex_constants::match_not_bow & std::regex_constants::match_not_null) == 0); + assert((std::regex_constants::match_not_bow & std::regex_constants::match_continuous) == 0); + assert((std::regex_constants::match_not_bow & std::regex_constants::match_prev_avail) == 0); + assert((std::regex_constants::match_not_bow & std::regex_constants::format_sed) == 0); + assert((std::regex_constants::match_not_bow & std::regex_constants::format_no_copy) == 0); + assert((std::regex_constants::match_not_bow & std::regex_constants::format_first_only) == 0); + + assert((std::regex_constants::match_not_eow & std::regex_constants::match_any) == 0); + assert((std::regex_constants::match_not_eow & std::regex_constants::match_not_null) == 0); + assert((std::regex_constants::match_not_eow & std::regex_constants::match_continuous) == 0); + assert((std::regex_constants::match_not_eow & std::regex_constants::match_prev_avail) == 0); + assert((std::regex_constants::match_not_eow & std::regex_constants::format_sed) == 0); + assert((std::regex_constants::match_not_eow & std::regex_constants::format_no_copy) == 0); + assert((std::regex_constants::match_not_eow & std::regex_constants::format_first_only) == 0); + + assert((std::regex_constants::match_any & std::regex_constants::match_not_null) == 0); + assert((std::regex_constants::match_any & std::regex_constants::match_continuous) == 0); + assert((std::regex_constants::match_any & std::regex_constants::match_prev_avail) == 0); + assert((std::regex_constants::match_any & std::regex_constants::format_sed) == 0); + assert((std::regex_constants::match_any & std::regex_constants::format_no_copy) == 0); + assert((std::regex_constants::match_any & std::regex_constants::format_first_only) == 0); + + assert((std::regex_constants::match_not_null & std::regex_constants::match_continuous) == 0); + assert((std::regex_constants::match_not_null & std::regex_constants::match_prev_avail) == 0); + assert((std::regex_constants::match_not_null & std::regex_constants::format_sed) == 0); + assert((std::regex_constants::match_not_null & std::regex_constants::format_no_copy) == 0); + assert((std::regex_constants::match_not_null & std::regex_constants::format_first_only) == 0); + + assert((std::regex_constants::match_continuous & std::regex_constants::match_prev_avail) == 0); + assert((std::regex_constants::match_continuous & std::regex_constants::format_sed) == 0); + assert((std::regex_constants::match_continuous & std::regex_constants::format_no_copy) == 0); + assert((std::regex_constants::match_continuous & std::regex_constants::format_first_only) == 0); + + assert((std::regex_constants::match_prev_avail & std::regex_constants::format_sed) == 0); + assert((std::regex_constants::match_prev_avail & std::regex_constants::format_no_copy) == 0); + assert((std::regex_constants::match_prev_avail & std::regex_constants::format_first_only) == 0); + + assert((std::regex_constants::format_sed & std::regex_constants::format_no_copy) == 0); + assert((std::regex_constants::format_sed & std::regex_constants::format_first_only) == 0); + + assert((std::regex_constants::format_no_copy & std::regex_constants::format_first_only) == 0); + + std::regex_constants::match_flag_type e1 = std::regex_constants::match_not_bol; + std::regex_constants::match_flag_type e2 = std::regex_constants::match_not_eol; + e1 = ~e1; + e1 = e1 & e2; + e1 = e1 | e2; + e1 = e1 ^ e2; + e1 &= e2; + e1 |= e2; + e1 ^= e2; +} diff --git a/test/re/re.const/re.synopt/syntax_option_type.pass.cpp b/test/re/re.const/re.synopt/syntax_option_type.pass.cpp new file mode 100644 index 00000000..5d82ed82 --- /dev/null +++ b/test/re/re.const/re.synopt/syntax_option_type.pass.cpp @@ -0,0 +1,114 @@ +// -*- C++ -*- +//===-------------------------- algorithm ---------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// namespace regex_constants +// { +// +// emum syntax_option_type // bitmask type +// { +// icase = unspecified, +// nosubs = unspecified, +// optimize = unspecified, +// collate = unspecified, +// ECMAScript = unspecified, +// basic = unspecified, +// extended = unspecified, +// awk = unspecified, +// grep = unspecified, +// egrep = unspecified +// }; +// +// } + +#include +#include + +int main() +{ + assert(std::regex_constants::icase != 0); + assert(std::regex_constants::nosubs != 0); + assert(std::regex_constants::optimize != 0); + assert(std::regex_constants::collate != 0); + assert(std::regex_constants::ECMAScript != 0); + assert(std::regex_constants::basic != 0); + assert(std::regex_constants::extended != 0); + assert(std::regex_constants::awk != 0); + assert(std::regex_constants::grep != 0); + assert(std::regex_constants::egrep != 0); + + assert((std::regex_constants::icase & std::regex_constants::nosubs) == 0); + assert((std::regex_constants::icase & std::regex_constants::optimize) == 0); + assert((std::regex_constants::icase & std::regex_constants::collate) == 0); + assert((std::regex_constants::icase & std::regex_constants::ECMAScript) == 0); + assert((std::regex_constants::icase & std::regex_constants::basic) == 0); + assert((std::regex_constants::icase & std::regex_constants::extended) == 0); + assert((std::regex_constants::icase & std::regex_constants::awk) == 0); + assert((std::regex_constants::icase & std::regex_constants::grep) == 0); + assert((std::regex_constants::icase & std::regex_constants::egrep) == 0); + + assert((std::regex_constants::nosubs & std::regex_constants::optimize) == 0); + assert((std::regex_constants::nosubs & std::regex_constants::collate) == 0); + assert((std::regex_constants::nosubs & std::regex_constants::ECMAScript) == 0); + assert((std::regex_constants::nosubs & std::regex_constants::basic) == 0); + assert((std::regex_constants::nosubs & std::regex_constants::extended) == 0); + assert((std::regex_constants::nosubs & std::regex_constants::awk) == 0); + assert((std::regex_constants::nosubs & std::regex_constants::grep) == 0); + assert((std::regex_constants::nosubs & std::regex_constants::egrep) == 0); + + assert((std::regex_constants::optimize & std::regex_constants::collate) == 0); + assert((std::regex_constants::optimize & std::regex_constants::ECMAScript) == 0); + assert((std::regex_constants::optimize & std::regex_constants::basic) == 0); + assert((std::regex_constants::optimize & std::regex_constants::extended) == 0); + assert((std::regex_constants::optimize & std::regex_constants::awk) == 0); + assert((std::regex_constants::optimize & std::regex_constants::grep) == 0); + assert((std::regex_constants::optimize & std::regex_constants::egrep) == 0); + + assert((std::regex_constants::collate & std::regex_constants::ECMAScript) == 0); + assert((std::regex_constants::collate & std::regex_constants::basic) == 0); + assert((std::regex_constants::collate & std::regex_constants::extended) == 0); + assert((std::regex_constants::collate & std::regex_constants::awk) == 0); + assert((std::regex_constants::collate & std::regex_constants::grep) == 0); + assert((std::regex_constants::collate & std::regex_constants::egrep) == 0); + + assert((std::regex_constants::ECMAScript & std::regex_constants::basic) == 0); + assert((std::regex_constants::ECMAScript & std::regex_constants::extended) == 0); + assert((std::regex_constants::ECMAScript & std::regex_constants::awk) == 0); + assert((std::regex_constants::ECMAScript & std::regex_constants::grep) == 0); + assert((std::regex_constants::ECMAScript & std::regex_constants::egrep) == 0); + + assert((std::regex_constants::basic & std::regex_constants::extended) == 0); + assert((std::regex_constants::basic & std::regex_constants::awk) == 0); + assert((std::regex_constants::basic & std::regex_constants::grep) == 0); + assert((std::regex_constants::basic & std::regex_constants::egrep) == 0); + + assert((std::regex_constants::extended & std::regex_constants::awk) == 0); + assert((std::regex_constants::extended & std::regex_constants::grep) == 0); + assert((std::regex_constants::extended & std::regex_constants::egrep) == 0); + + assert((std::regex_constants::awk & std::regex_constants::grep) == 0); + assert((std::regex_constants::awk & std::regex_constants::egrep) == 0); + + assert((std::regex_constants::grep & std::regex_constants::egrep) == 0); + + assert((std::regex_constants::icase | std::regex_constants::nosubs) != 0); + assert((std::regex_constants::icase ^ std::regex_constants::nosubs) != 0); + + std::regex_constants::syntax_option_type e1 = std::regex_constants::icase; + std::regex_constants::syntax_option_type e2 = std::regex_constants::nosubs; + e1 = ~e1; + e1 = e1 & e2; + e1 = e1 | e2; + e1 = e1 ^ e2; + e1 &= e2; + e1 |= e2; + e1 ^= e2; +} diff --git a/test/re/re.def/defns.regex.collating.element/nothing_to_do.pass.cpp b/test/re/re.def/defns.regex.collating.element/nothing_to_do.pass.cpp new file mode 100644 index 00000000..b85601fc --- /dev/null +++ b/test/re/re.def/defns.regex.collating.element/nothing_to_do.pass.cpp @@ -0,0 +1,13 @@ +// -*- C++ -*- +//===-------------------------- algorithm ---------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +int main() +{ +} diff --git a/test/re/re.def/defns.regex.finite.state.machine/nothing_to_do.pass.cpp b/test/re/re.def/defns.regex.finite.state.machine/nothing_to_do.pass.cpp new file mode 100644 index 00000000..b85601fc --- /dev/null +++ b/test/re/re.def/defns.regex.finite.state.machine/nothing_to_do.pass.cpp @@ -0,0 +1,13 @@ +// -*- C++ -*- +//===-------------------------- algorithm ---------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +int main() +{ +} diff --git a/test/re/re.def/defns.regex.format.specifier/nothing_to_do.pass.cpp b/test/re/re.def/defns.regex.format.specifier/nothing_to_do.pass.cpp new file mode 100644 index 00000000..b85601fc --- /dev/null +++ b/test/re/re.def/defns.regex.format.specifier/nothing_to_do.pass.cpp @@ -0,0 +1,13 @@ +// -*- C++ -*- +//===-------------------------- algorithm ---------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +int main() +{ +} diff --git a/test/re/re.def/defns.regex.matched/nothing_to_do.pass.cpp b/test/re/re.def/defns.regex.matched/nothing_to_do.pass.cpp new file mode 100644 index 00000000..b85601fc --- /dev/null +++ b/test/re/re.def/defns.regex.matched/nothing_to_do.pass.cpp @@ -0,0 +1,13 @@ +// -*- C++ -*- +//===-------------------------- algorithm ---------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +int main() +{ +} diff --git a/test/re/re.def/defns.regex.primary.equivalence.class/nothing_to_do.pass.cpp b/test/re/re.def/defns.regex.primary.equivalence.class/nothing_to_do.pass.cpp new file mode 100644 index 00000000..b85601fc --- /dev/null +++ b/test/re/re.def/defns.regex.primary.equivalence.class/nothing_to_do.pass.cpp @@ -0,0 +1,13 @@ +// -*- C++ -*- +//===-------------------------- algorithm ---------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +int main() +{ +} diff --git a/test/re/re.def/defns.regex.regular.expression/nothing_to_do.pass.cpp b/test/re/re.def/defns.regex.regular.expression/nothing_to_do.pass.cpp new file mode 100644 index 00000000..b85601fc --- /dev/null +++ b/test/re/re.def/defns.regex.regular.expression/nothing_to_do.pass.cpp @@ -0,0 +1,13 @@ +// -*- C++ -*- +//===-------------------------- algorithm ---------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +int main() +{ +} diff --git a/test/re/re.def/defns.regex.subexpression/nothing_to_do.pass.cpp b/test/re/re.def/defns.regex.subexpression/nothing_to_do.pass.cpp new file mode 100644 index 00000000..b85601fc --- /dev/null +++ b/test/re/re.def/defns.regex.subexpression/nothing_to_do.pass.cpp @@ -0,0 +1,13 @@ +// -*- C++ -*- +//===-------------------------- algorithm ---------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +int main() +{ +} diff --git a/test/re/re.def/nothing_to_do.pass.cpp b/test/re/re.def/nothing_to_do.pass.cpp new file mode 100644 index 00000000..b85601fc --- /dev/null +++ b/test/re/re.def/nothing_to_do.pass.cpp @@ -0,0 +1,13 @@ +// -*- C++ -*- +//===-------------------------- algorithm ---------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +int main() +{ +} diff --git a/test/re/re.general/nothing_to_do.pass.cpp b/test/re/re.general/nothing_to_do.pass.cpp new file mode 100644 index 00000000..b85601fc --- /dev/null +++ b/test/re/re.general/nothing_to_do.pass.cpp @@ -0,0 +1,13 @@ +// -*- C++ -*- +//===-------------------------- algorithm ---------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +int main() +{ +} diff --git a/test/re/re.req/nothing_to_do.pass.cpp b/test/re/re.req/nothing_to_do.pass.cpp new file mode 100644 index 00000000..b85601fc --- /dev/null +++ b/test/re/re.req/nothing_to_do.pass.cpp @@ -0,0 +1,13 @@ +// -*- C++ -*- +//===-------------------------- algorithm ---------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +int main() +{ +} diff --git a/test/re/re.traits/default.pass.cpp b/test/re/re.traits/default.pass.cpp new file mode 100644 index 00000000..ebc3d80e --- /dev/null +++ b/test/re/re.traits/default.pass.cpp @@ -0,0 +1,23 @@ +// -*- C++ -*- +//===-------------------------- algorithm ---------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template struct regex_traits; + +// regex_traits(); + +#include + +int main() +{ + std::regex_traits t1(); + std::regex_traits t2(); +} diff --git a/test/re/re.traits/getloc.pass.cpp b/test/re/re.traits/getloc.pass.cpp new file mode 100644 index 00000000..b5d1b701 --- /dev/null +++ b/test/re/re.traits/getloc.pass.cpp @@ -0,0 +1,21 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template struct regex_traits; + +// locale_type getloc()const; + +#include + +int main() +{ +#error getloc not implemented +} diff --git a/test/re/re.traits/imbue.pass.cpp b/test/re/re.traits/imbue.pass.cpp new file mode 100644 index 00000000..687ff64b --- /dev/null +++ b/test/re/re.traits/imbue.pass.cpp @@ -0,0 +1,21 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template struct regex_traits; + +// locale_type imbue(locale_type l); + +#include + +int main() +{ +#error imbue not implemented +} diff --git a/test/re/re.traits/isctype.pass.cpp b/test/re/re.traits/isctype.pass.cpp new file mode 100644 index 00000000..7cb141e2 --- /dev/null +++ b/test/re/re.traits/isctype.pass.cpp @@ -0,0 +1,21 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template struct regex_traits; + +// bool isctype(charT c, char_class_type f) const; + +#include + +int main() +{ +#error isctype not implemented +} diff --git a/test/re/re.traits/iterators.h b/test/re/re.traits/iterators.h new file mode 100644 index 00000000..85332ac7 --- /dev/null +++ b/test/re/re.traits/iterators.h @@ -0,0 +1,251 @@ +#ifndef ITERATORS_H +#define ITERATORS_H + +#include + +template +class input_iterator +{ + It it_; + + template friend class input_iterator; +public: + typedef std::input_iterator_tag iterator_category; + typedef typename std::iterator_traits::value_type value_type; + typedef typename std::iterator_traits::difference_type difference_type; + typedef It pointer; + typedef typename std::iterator_traits::reference reference; + + It base() const {return it_;} + + input_iterator() : it_() {} + explicit input_iterator(It it) : it_(it) {} + template + input_iterator(const input_iterator& u) :it_(u.it_) {} + + reference operator*() const {return *it_;} + pointer operator->() const {return it_;} + + input_iterator& operator++() {++it_; return *this;} + input_iterator operator++(int) + {input_iterator tmp(*this); ++(*this); return tmp;} + + friend bool operator==(const input_iterator& x, const input_iterator& y) + {return x.it_ == y.it_;} + friend bool operator!=(const input_iterator& x, const input_iterator& y) + {return !(x == y);} +}; + +template +inline +bool +operator==(const input_iterator& x, const input_iterator& y) +{ + return x.base() == y.base(); +} + +template +inline +bool +operator!=(const input_iterator& x, const input_iterator& y) +{ + return !(x == y); +} + +template +class forward_iterator +{ + It it_; + + template friend class forward_iterator; +public: + typedef std::forward_iterator_tag iterator_category; + typedef typename std::iterator_traits::value_type value_type; + typedef typename std::iterator_traits::difference_type difference_type; + typedef It pointer; + typedef typename std::iterator_traits::reference reference; + + It base() const {return it_;} + + forward_iterator() : it_() {} + explicit forward_iterator(It it) : it_(it) {} + template + forward_iterator(const forward_iterator& u) :it_(u.it_) {} + + reference operator*() const {return *it_;} + pointer operator->() const {return it_;} + + forward_iterator& operator++() {++it_; return *this;} + forward_iterator operator++(int) + {forward_iterator tmp(*this); ++(*this); return tmp;} + + friend bool operator==(const forward_iterator& x, const forward_iterator& y) + {return x.it_ == y.it_;} + friend bool operator!=(const forward_iterator& x, const forward_iterator& y) + {return !(x == y);} +}; + +template +inline +bool +operator==(const forward_iterator& x, const forward_iterator& y) +{ + return x.base() == y.base(); +} + +template +inline +bool +operator!=(const forward_iterator& x, const forward_iterator& y) +{ + return !(x == y); +} + +template +class bidirectional_iterator +{ + It it_; + + template friend class bidirectional_iterator; +public: + typedef std::bidirectional_iterator_tag iterator_category; + typedef typename std::iterator_traits::value_type value_type; + typedef typename std::iterator_traits::difference_type difference_type; + typedef It pointer; + typedef typename std::iterator_traits::reference reference; + + It base() const {return it_;} + + bidirectional_iterator() : it_() {} + explicit bidirectional_iterator(It it) : it_(it) {} + template + bidirectional_iterator(const bidirectional_iterator& u) :it_(u.it_) {} + + reference operator*() const {return *it_;} + pointer operator->() const {return it_;} + + bidirectional_iterator& operator++() {++it_; return *this;} + bidirectional_iterator operator++(int) + {bidirectional_iterator tmp(*this); ++(*this); return tmp;} + + bidirectional_iterator& operator--() {--it_; return *this;} + bidirectional_iterator operator--(int) + {bidirectional_iterator tmp(*this); --(*this); return tmp;} +}; + +template +inline +bool +operator==(const bidirectional_iterator& x, const bidirectional_iterator& y) +{ + return x.base() == y.base(); +} + +template +inline +bool +operator!=(const bidirectional_iterator& x, const bidirectional_iterator& y) +{ + return !(x == y); +} + +template +class random_access_iterator +{ + It it_; + + template friend class random_access_iterator; +public: + typedef std::random_access_iterator_tag iterator_category; + typedef typename std::iterator_traits::value_type value_type; + typedef typename std::iterator_traits::difference_type difference_type; + typedef It pointer; + typedef typename std::iterator_traits::reference reference; + + It base() const {return it_;} + + random_access_iterator() : it_() {} + explicit random_access_iterator(It it) : it_(it) {} + template + random_access_iterator(const random_access_iterator& u) :it_(u.it_) {} + + reference operator*() const {return *it_;} + pointer operator->() const {return it_;} + + random_access_iterator& operator++() {++it_; return *this;} + random_access_iterator operator++(int) + {random_access_iterator tmp(*this); ++(*this); return tmp;} + + random_access_iterator& operator--() {--it_; return *this;} + random_access_iterator operator--(int) + {random_access_iterator tmp(*this); --(*this); return tmp;} + + random_access_iterator& operator+=(difference_type n) {it_ += n; return *this;} + random_access_iterator operator+(difference_type n) const + {random_access_iterator tmp(*this); tmp += n; return tmp;} + friend random_access_iterator operator+(difference_type n, random_access_iterator x) + {x += n; return x;} + random_access_iterator& operator-=(difference_type n) {return *this += -n;} + random_access_iterator operator-(difference_type n) const + {random_access_iterator tmp(*this); tmp -= n; return tmp;} + + reference operator[](difference_type n) const {return it_[n];} +}; + +template +inline +bool +operator==(const random_access_iterator& x, const random_access_iterator& y) +{ + return x.base() == y.base(); +} + +template +inline +bool +operator!=(const random_access_iterator& x, const random_access_iterator& y) +{ + return !(x == y); +} + +template +inline +bool +operator<(const random_access_iterator& x, const random_access_iterator& y) +{ + return x.base() < y.base(); +} + +template +inline +bool +operator<=(const random_access_iterator& x, const random_access_iterator& y) +{ + return !(y < x); +} + +template +inline +bool +operator>(const random_access_iterator& x, const random_access_iterator& y) +{ + return y < x; +} + +template +inline +bool +operator>=(const random_access_iterator& x, const random_access_iterator& y) +{ + return !(x < y); +} + +template +inline +typename std::iterator_traits::difference_type +operator-(const random_access_iterator& x, const random_access_iterator& y) +{ + return x.base() - y.base(); +} + +#endif diff --git a/test/re/re.traits/length.pass.cpp b/test/re/re.traits/length.pass.cpp new file mode 100644 index 00000000..7a30708c --- /dev/null +++ b/test/re/re.traits/length.pass.cpp @@ -0,0 +1,31 @@ +// -*- C++ -*- +//===-------------------------- algorithm ---------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template struct regex_traits; + +// static std::size_t length(const char_type* p); + +#include +#include + +int main() +{ + assert(std::regex_traits::length("") == 0); + assert(std::regex_traits::length("1") == 1); + assert(std::regex_traits::length("12") == 2); + assert(std::regex_traits::length("123") == 3); + + assert(std::regex_traits::length(L"") == 0); + assert(std::regex_traits::length(L"1") == 1); + assert(std::regex_traits::length(L"12") == 2); + assert(std::regex_traits::length(L"123") == 3); +} diff --git a/test/re/re.traits/lookup_classname.pass.cpp b/test/re/re.traits/lookup_classname.pass.cpp new file mode 100644 index 00000000..80df4ce0 --- /dev/null +++ b/test/re/re.traits/lookup_classname.pass.cpp @@ -0,0 +1,24 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template struct regex_traits; + +// template +// char_class_type +// lookup_classname(ForwardIterator first, ForwardIterator last, +// bool icase = false) const; + +#include + +int main() +{ +#error lookup_classname not implemented +} diff --git a/test/re/re.traits/lookup_collatename.pass.cpp b/test/re/re.traits/lookup_collatename.pass.cpp new file mode 100644 index 00000000..e2ce3d51 --- /dev/null +++ b/test/re/re.traits/lookup_collatename.pass.cpp @@ -0,0 +1,187 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template struct regex_traits; + +// template +// string_type +// lookup_collatename(ForwardIterator first, ForwardIterator last) const; + +#include + +#include +#include +#include +#include "iterators.h" + +template +void +test(const char_type* A, const char_type* expected) +{ + std::regex_traits t; + typedef forward_iterator F; + assert(t.lookup_collatename(F(A), F(A + t.length(A))) == expected); +} + +int main() +{ + test("NUL", "\x00"); + test("alert", "\x07"); + test("backspace", "\x08"); + test("tab", "\x09"); + test("carriage-return", "\x0D"); + test("newline", "\x0A"); + test("vertical-tab", "\x0B"); + test("form-feed", "\x0C"); + test("space", " "); + test("exclamation-mark", "!"); + test("quotation-mark", "\""); + test("number-sign", "#"); + test("dollar-sign", "$"); + test("percent-sign", "%"); + test("ampersand", "&"); + test("apostrophe", "\'"); + test("left-parenthesis", "("); + test("right-parenthesis", ")"); + test("asterisk", "*"); + test("plus-sign", "+"); + test("comma", ","); + test("hyphen-minus", "-"); + test("hyphen", "-"); + test("full-stop", "."); + test("period", "."); + test("slash", "/"); + test("solidus", "/"); + test("zero", "0"); + test("one", "1"); + test("two", "2"); + test("three", "3"); + test("four", "4"); + test("five", "5"); + test("six", "6"); + test("seven", "7"); + test("eight", "8"); + test("nine", "9"); + test("colon", ":"); + test("semicolon", ";"); + test("less-than-sign", "<"); + test("equals-sign", "="); + test("greater-than-sign", ">"); + test("question-mark", "?"); + test("commercial-at", "@"); + for (char c = 'A'; c <= 'Z'; ++c) + { + const char a[2] = {c}; + test(a, a); + } + test("left-square-bracket", "["); + test("backslash", "\\"); + test("reverse-solidus", "\\"); + test("right-square-bracket", "]"); + test("circumflex-accent", "^"); + test("circumflex", "^"); + test("low-line", "_"); + test("underscore", "_"); + test("grave-accent", "`"); + for (char c = 'a'; c <= 'z'; ++c) + { + const char a[2] = {c}; + test(a, a); + } + test("left-brace", "{"); + test("left-curly-bracket", "{"); + test("vertical-line", "|"); + test("right-brace", "}"); + test("right-curly-bracket", "}"); + test("tilde", "~"); + + test("tild", ""); + test("ch", ""); + std::locale::global(std::locale("cs_CZ.ISO8859-2")); + test("ch", "ch"); + std::locale::global(std::locale("C")); + + test(L"NUL", L"\x00"); + test(L"alert", L"\x07"); + test(L"backspace", L"\x08"); + test(L"tab", L"\x09"); + test(L"carriage-return", L"\x0D"); + test(L"newline", L"\x0A"); + test(L"vertical-tab", L"\x0B"); + test(L"form-feed", L"\x0C"); + test(L"space", L" "); + test(L"exclamation-mark", L"!"); + test(L"quotation-mark", L"\""); + test(L"number-sign", L"#"); + test(L"dollar-sign", L"$"); + test(L"percent-sign", L"%"); + test(L"ampersand", L"&"); + test(L"apostrophe", L"\'"); + test(L"left-parenthesis", L"("); + test(L"right-parenthesis", L")"); + test(L"asterisk", L"*"); + test(L"plus-sign", L"+"); + test(L"comma", L","); + test(L"hyphen-minus", L"-"); + test(L"hyphen", L"-"); + test(L"full-stop", L"."); + test(L"period", L"."); + test(L"slash", L"/"); + test(L"solidus", L"/"); + test(L"zero", L"0"); + test(L"one", L"1"); + test(L"two", L"2"); + test(L"three", L"3"); + test(L"four", L"4"); + test(L"five", L"5"); + test(L"six", L"6"); + test(L"seven", L"7"); + test(L"eight", L"8"); + test(L"nine", L"9"); + test(L"colon", L":"); + test(L"semicolon", L";"); + test(L"less-than-sign", L"<"); + test(L"equals-sign", L"="); + test(L"greater-than-sign", L">"); + test(L"question-mark", L"?"); + test(L"commercial-at", L"@"); + for (wchar_t c = L'A'; c <= L'Z'; ++c) + { + const wchar_t a[2] = {c}; + test(a, a); + } + test(L"left-square-bracket", L"["); + test(L"backslash", L"\\"); + test(L"reverse-solidus", L"\\"); + test(L"right-square-bracket", L"]"); + test(L"circumflex-accent", L"^"); + test(L"circumflex", L"^"); + test(L"low-line", L"_"); + test(L"underscore", L"_"); + test(L"grave-accent", L"`"); + for (wchar_t c = L'a'; c <= L'z'; ++c) + { + const wchar_t a[2] = {c}; + test(a, a); + } + test(L"left-brace", L"{"); + test(L"left-curly-bracket", L"{"); + test(L"vertical-line", L"|"); + test(L"right-brace", L"}"); + test(L"right-curly-bracket", L"}"); + test(L"tilde", L"~"); + + test(L"tild", L""); + test(L"ch", L""); + std::locale::global(std::locale("cs_CZ.ISO8859-2")); + test(L"ch", L"ch"); + std::locale::global(std::locale("C")); +} diff --git a/test/re/re.traits/transform.pass.cpp b/test/re/re.traits/transform.pass.cpp new file mode 100644 index 00000000..25281129 --- /dev/null +++ b/test/re/re.traits/transform.pass.cpp @@ -0,0 +1,42 @@ +// -*- C++ -*- +//===-------------------------- algorithm ---------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template struct regex_traits; + +// template +// string_type transform(ForwardIterator first, ForwardIterator last) const; + +#include +#include +#include "iterators.h" + +int main() +{ + { + std::regex_traits t; + const char a[] = "a"; + const char B[] = "B"; + typedef forward_iterator F; + assert(t.transform(F(a), F(a+1)) > t.transform(F(B), F(B+1))); + t.imbue(std::locale("cs_CZ.ISO8859-2")); + assert(t.transform(F(a), F(a+1)) < t.transform(F(B), F(B+1))); + } + { + std::regex_traits t; + const wchar_t a[] = L"a"; + const wchar_t B[] = L"B"; + typedef forward_iterator F; + assert(t.transform(F(a), F(a+1)) > t.transform(F(B), F(B+1))); + t.imbue(std::locale("cs_CZ.ISO8859-2")); + assert(t.transform(F(a), F(a+1)) < t.transform(F(B), F(B+1))); + } +} diff --git a/test/re/re.traits/transform_primary.pass.cpp b/test/re/re.traits/transform_primary.pass.cpp new file mode 100644 index 00000000..d29c7785 --- /dev/null +++ b/test/re/re.traits/transform_primary.pass.cpp @@ -0,0 +1,49 @@ +// -*- C++ -*- +//===-------------------------- algorithm ---------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template struct regex_traits; + +// template +// string_type +// transform_primary(ForwardIterator first, ForwardIterator last) const; + +#include + +#include +#include +#include "iterators.h" + +int main() +{ + { + std::regex_traits t; + const char A[] = "A"; + const char Aacute[] = "\xC1"; + typedef forward_iterator F; + assert(t.transform_primary(F(A), F(A+1)) != + t.transform_primary(F(Aacute), F(Aacute+1))); + t.imbue(std::locale("cs_CZ.ISO8859-2")); + assert(t.transform_primary(F(A), F(A+1)) == + t.transform_primary(F(Aacute), F(Aacute+1))); + } + { + std::regex_traits t; + const wchar_t A[] = L"A"; + const wchar_t Aacute[] = L"\xC1"; + typedef forward_iterator F; + assert(t.transform_primary(F(A), F(A+1)) != + t.transform_primary(F(Aacute), F(Aacute+1))); + t.imbue(std::locale("cs_CZ.ISO8859-2")); + assert(t.transform_primary(F(A), F(A+1)) == + t.transform_primary(F(Aacute), F(Aacute+1))); + } +} diff --git a/test/re/re.traits/translate.pass.cpp b/test/re/re.traits/translate.pass.cpp new file mode 100644 index 00000000..c584e1a7 --- /dev/null +++ b/test/re/re.traits/translate.pass.cpp @@ -0,0 +1,34 @@ +// -*- C++ -*- +//===-------------------------- algorithm ---------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template struct regex_traits; + +// charT translate(charT c) const; + +#include +#include + +int main() +{ + { + std::regex_traits t; + assert(t.translate('a') == 'a'); + assert(t.translate('B') == 'B'); + assert(t.translate('c') == 'c'); + } + { + std::regex_traits t; + assert(t.translate(L'a') == L'a'); + assert(t.translate(L'B') == L'B'); + assert(t.translate(L'c') == L'c'); + } +} diff --git a/test/re/re.traits/translate_nocase.pass.cpp b/test/re/re.traits/translate_nocase.pass.cpp new file mode 100644 index 00000000..cc0079f6 --- /dev/null +++ b/test/re/re.traits/translate_nocase.pass.cpp @@ -0,0 +1,62 @@ +// -*- C++ -*- +//===-------------------------- algorithm ---------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template struct regex_traits; + +// charT translate_nocase(charT c) const; + +#include +#include + +int main() +{ + { + std::regex_traits t; + assert(t.translate_nocase(' ') == ' '); + assert(t.translate_nocase('A') == 'a'); + assert(t.translate_nocase('\x07') == '\x07'); + assert(t.translate_nocase('.') == '.'); + assert(t.translate_nocase('a') == 'a'); + assert(t.translate_nocase('1') == '1'); + assert(t.translate_nocase('\xDA') == '\xDA'); + assert(t.translate_nocase('\xFA') == '\xFA'); + t.imbue(std::locale("en_US")); + assert(t.translate_nocase(' ') == ' '); + assert(t.translate_nocase('A') == 'a'); + assert(t.translate_nocase('\x07') == '\x07'); + assert(t.translate_nocase('.') == '.'); + assert(t.translate_nocase('a') == 'a'); + assert(t.translate_nocase('1') == '1'); + assert(t.translate_nocase('\xDA') == '\xDA'); + assert(t.translate_nocase('\xFA') == '\xFA'); + } + { + std::regex_traits t; + assert(t.translate_nocase(L' ') == L' '); + assert(t.translate_nocase(L'A') == L'a'); + assert(t.translate_nocase(L'\x07') == L'\x07'); + assert(t.translate_nocase(L'.') == L'.'); + assert(t.translate_nocase(L'a') == L'a'); + assert(t.translate_nocase(L'1') == L'1'); + assert(t.translate_nocase(L'\xDA') == L'\xDA'); + assert(t.translate_nocase(L'\xFA') == L'\xFA'); + t.imbue(std::locale("en_US")); + assert(t.translate_nocase(L' ') == L' '); + assert(t.translate_nocase(L'A') == L'a'); + assert(t.translate_nocase(L'\x07') == L'\x07'); + assert(t.translate_nocase(L'.') == L'.'); + assert(t.translate_nocase(L'a') == L'a'); + assert(t.translate_nocase(L'1') == L'1'); + assert(t.translate_nocase(L'\xDA') == L'\xFA'); + assert(t.translate_nocase(L'\xFA') == L'\xFA'); + } +} diff --git a/test/re/re.traits/types.pass.cpp b/test/re/re.traits/types.pass.cpp new file mode 100644 index 00000000..c3972cd5 --- /dev/null +++ b/test/re/re.traits/types.pass.cpp @@ -0,0 +1,32 @@ +// -*- C++ -*- +//===-------------------------- algorithm ---------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template +// struct regex_traits +// { +// public: +// typedef charT char_type; +// typedef basic_string string_type; +// typedef locale locale_type; + +#include +#include + +int main() +{ + static_assert((std::is_same::char_type, char>::value), ""); + static_assert((std::is_same::string_type, std::string>::value), ""); + static_assert((std::is_same::locale_type, std::locale>::value), ""); + static_assert((std::is_same::char_type, wchar_t>::value), ""); + static_assert((std::is_same::string_type, std::wstring>::value), ""); + static_assert((std::is_same::locale_type, std::locale>::value), ""); +} diff --git a/test/re/re.traits/value.pass.cpp b/test/re/re.traits/value.pass.cpp new file mode 100644 index 00000000..c2e8b0d6 --- /dev/null +++ b/test/re/re.traits/value.pass.cpp @@ -0,0 +1,21 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template struct regex_traits; + +// int value(charT ch, int radix) const; + +#include + +int main() +{ +#error value not implemented +}