libstdc++

regex.h

Go to the documentation of this file.
00001 // class template regex -*- C++ -*-
00002 
00003 // Copyright (C) 2010 Free Software Foundation, Inc.
00004 //
00005 // This file is part of the GNU ISO C++ Library.  This library is free
00006 // software; you can redistribute it and/or modify it under the
00007 // terms of the GNU General Public License as published by the
00008 // Free Software Foundation; either version 3, or (at your option)
00009 // any later version.
00010 
00011 // This library is distributed in the hope that it will be useful,
00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014 // GNU General Public License for more details.
00015 
00016 // Under Section 7 of GPL version 3, you are granted additional
00017 // permissions described in the GCC Runtime Library Exception, version
00018 // 3.1, as published by the Free Software Foundation.
00019 
00020 // You should have received a copy of the GNU General Public License and
00021 // a copy of the GCC Runtime Library Exception along with this program;
00022 // see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
00023 // <http://www.gnu.org/licenses/>.
00024 
00025 /**
00026  *  @file bits/regex.h
00027  *  This is an internal header file, included by other library headers.
00028  *  Do not attempt to use it directly. @headername{regex}
00029  */
00030 
00031 namespace std _GLIBCXX_VISIBILITY(default)
00032 {
00033 _GLIBCXX_BEGIN_NAMESPACE_VERSION
00034 
00035 /**
00036  * @defgroup regex Regular Expressions
00037  * A facility for performing regular expression pattern matching.
00038  */
00039  //@{
00040 
00041   // [7.7] Class regex_traits
00042   /**
00043    * @brief Describes aspects of a regular expression.
00044    *
00045    * A regular expression traits class that satisfies the requirements of 
00046    * section [28.7].
00047    *
00048    * The class %regex is parameterized around a set of related types and
00049    * functions used to complete the definition of its semantics.  This class
00050    * satisfies the requirements of such a traits class.
00051    */
00052   template<typename _Ch_type>
00053     struct regex_traits
00054     {
00055     public:
00056       typedef _Ch_type                     char_type;
00057       typedef std::basic_string<char_type> string_type;
00058       typedef std::locale                  locale_type;
00059       typedef std::ctype_base::mask        char_class_type;
00060 
00061     public:
00062       /**
00063        * @brief Constructs a default traits object.
00064        */
00065       regex_traits()
00066       { }
00067       
00068       /**
00069        * @brief Gives the length of a C-style string starting at @p __p.
00070        *
00071        * @param __p a pointer to the start of a character sequence.
00072        *
00073        * @returns the number of characters between @p *__p and the first
00074        * default-initialized value of type @p char_type.  In other words, uses
00075        * the C-string algorithm for determining the length of a sequence of
00076        * characters.
00077        */
00078       static std::size_t
00079       length(const char_type* __p)
00080       { return string_type::traits_type::length(__p); }
00081 
00082       /**
00083        * @brief Performs the identity translation.
00084        *
00085        * @param c A character to the locale-specific character set.
00086        *
00087        * @returns c.
00088        */
00089       char_type
00090       translate(char_type __c) const
00091       { return __c; }
00092       
00093       /**
00094        * @brief Translates a character into a case-insensitive equivalent.
00095        *
00096        * @param c A character to the locale-specific character set.
00097        *
00098        * @returns the locale-specific lower-case equivalent of c.
00099        * @throws std::bad_cast if the imbued locale does not support the ctype
00100        *         facet.
00101        */
00102       char_type
00103       translate_nocase(char_type __c) const
00104       {
00105     using std::ctype;
00106     using std::use_facet;
00107     return use_facet<ctype<char_type> >(_M_locale).tolower(__c);
00108       }
00109       
00110       /**
00111        * @brief Gets a sort key for a character sequence.
00112        *
00113        * @param first beginning of the character sequence.
00114        * @param last  one-past-the-end of the character sequence.
00115        *
00116        * Returns a sort key for the character sequence designated by the
00117        * iterator range [F1, F2) such that if the character sequence [G1, G2)
00118        * sorts before the character sequence [H1, H2) then
00119        * v.transform(G1, G2) < v.transform(H1, H2).
00120        *
00121        * What this really does is provide a more efficient way to compare a
00122        * string to multiple other strings in locales with fancy collation
00123        * rules and equivalence classes.
00124        *
00125        * @returns a locale-specific sort key equivalent to the input range.
00126        *
00127        * @throws std::bad_cast if the current locale does not have a collate
00128        *         facet.
00129        */
00130       template<typename _Fwd_iter>
00131         string_type
00132         transform(_Fwd_iter __first, _Fwd_iter __last) const
00133         {
00134       using std::collate;
00135       using std::use_facet;
00136       const collate<_Ch_type>& __c(use_facet<
00137                        collate<_Ch_type> >(_M_locale));
00138       string_type __s(__first, __last);
00139       return __c.transform(__s.data(), __s.data() + __s.size());
00140     }
00141 
00142       /**
00143        * @brief Gets a sort key for a character sequence, independant of case.
00144        *
00145        * @param first beginning of the character sequence.
00146        * @param last  one-past-the-end of the character sequence.
00147        *
00148        * Effects: if typeid(use_facet<collate<_Ch_type> >) ==
00149        * typeid(collate_byname<_Ch_type>) and the form of the sort key
00150        * returned by collate_byname<_Ch_type>::transform(first, last) is known
00151        * and can be converted into a primary sort key then returns that key,
00152        * otherwise returns an empty string.
00153        *
00154        * @todo Implement this function.
00155        */
00156       template<typename _Fwd_iter>
00157         string_type
00158         transform_primary(_Fwd_iter __first, _Fwd_iter __last) const
00159         { return string_type(); }
00160 
00161       /**
00162        * @brief Gets a collation element by name.
00163        *
00164        * @param first beginning of the collation element name.
00165        * @param last  one-past-the-end of the collation element name.
00166        * 
00167        * @returns a sequence of one or more characters that represents the
00168        * collating element consisting of the character sequence designated by
00169        * the iterator range [first, last). Returns an empty string if the
00170        * character sequence is not a valid collating element.
00171        *
00172        * @todo Implement this function.
00173        */
00174       template<typename _Fwd_iter>
00175         string_type
00176         lookup_collatename(_Fwd_iter __first, _Fwd_iter __last) const
00177         { return string_type(); }
00178 
00179       /**
00180        * @brief Maps one or more characters to a named character
00181        *        classification.
00182        *
00183        * @param first beginning of the character sequence.
00184        * @param last  one-past-the-end of the character sequence.
00185        * @param icase ignores the case of the classification name.
00186        *
00187        * @returns an unspecified value that represents the character
00188        * classification named by the character sequence designated by the
00189        * iterator range [first, last). If @p icase is true, the returned mask
00190        * identifies the classification regardless of the case of the characters
00191        * to be matched (for example, [[:lower:]] is the same as [[:alpha:]]),
00192        * otherwise a case-dependant classification is returned.  The value
00193        * returned shall be independent of the case of the characters in the
00194        * character sequence. If the name is not recognized then returns a value
00195        * that compares equal to 0.
00196        *
00197        * At least the following names (or their wide-character equivalent) are
00198        * supported.
00199        * - d
00200        * - w
00201        * - s
00202        * - alnum
00203        * - alpha
00204        * - blank
00205        * - cntrl
00206        * - digit
00207        * - graph
00208        * - lower
00209        * - print
00210        * - punct
00211        * - space
00212        * - upper
00213        * - xdigit
00214        *
00215        * @todo Implement this function.
00216        */
00217       template<typename _Fwd_iter>
00218         char_class_type
00219         lookup_classname(_Fwd_iter __first, _Fwd_iter __last,
00220                      bool __icase = false) const
00221     { return 0; }
00222 
00223       /**
00224        * @brief Determines if @p c is a member of an identified class.
00225        *
00226        * @param c a character.
00227        * @param f a class type (as returned from lookup_classname).
00228        *
00229        * @returns true if the character @p c is a member of the classification
00230        * represented by @p f, false otherwise.
00231        *
00232        * @throws std::bad_cast if the current locale does not have a ctype
00233        *         facet.
00234        */
00235       bool
00236       isctype(_Ch_type __c, char_class_type __f) const;
00237 
00238       /**
00239        * @brief Converts a digit to an int.
00240        *
00241        * @param ch    a character representing a digit.
00242        * @param radix the radix if the numeric conversion (limited to 8, 10,
00243        *              or 16).
00244        * 
00245        * @returns the value represented by the digit ch in base radix if the
00246        * character ch is a valid digit in base radix; otherwise returns -1.
00247        */
00248       int
00249       value(_Ch_type __ch, int __radix) const;
00250       
00251       /**
00252        * @brief Imbues the regex_traits object with a copy of a new locale.
00253        *
00254        * @param loc A locale.
00255        *
00256        * @returns a copy of the previous locale in use by the regex_traits
00257        *          object.
00258        *
00259        * @note Calling imbue with a different locale than the one currently in
00260        *       use invalidates all cached data held by *this.
00261        */
00262       locale_type
00263       imbue(locale_type __loc)
00264       {
00265     std::swap(_M_locale, __loc);
00266     return __loc;
00267       }
00268       
00269       /**
00270        * @brief Gets a copy of the current locale in use by the regex_traits
00271        * object.
00272        */
00273       locale_type
00274       getloc() const
00275       { return _M_locale; }
00276       
00277     protected:
00278       locale_type _M_locale;
00279     };
00280 
00281   template<typename _Ch_type>
00282     bool
00283     regex_traits<_Ch_type>::
00284     isctype(_Ch_type __c, char_class_type __f) const
00285     {
00286       using std::ctype;
00287       using std::use_facet;
00288       const ctype<_Ch_type>& __ctype(use_facet<
00289                      ctype<_Ch_type> >(_M_locale));
00290       
00291       if (__ctype.is(__f, __c))
00292     return true;
00293       
00294       // special case of underscore in [[:w:]]
00295       if (__c == __ctype.widen('_'))
00296     {
00297       const char __wb[] = "w";
00298       char_class_type __wt = this->lookup_classname(__wb,
00299                             __wb + sizeof(__wb));
00300       if (__f | __wt)
00301         return true;
00302     }
00303     
00304       // special case of [[:space:]] in [[:blank:]]
00305       if (__ctype.is(std::ctype_base::space, __c))
00306     {
00307       const char __bb[] = "blank";
00308       char_class_type __bt = this->lookup_classname(__bb,
00309                             __bb + sizeof(__bb));
00310       if (__f | __bt)
00311         return true;
00312     }
00313       
00314       return false;
00315     }
00316 
00317   template<typename _Ch_type>
00318     int
00319     regex_traits<_Ch_type>::
00320     value(_Ch_type __ch, int __radix) const
00321     {
00322       std::basic_istringstream<_Ch_type> __is(string_type(1, __ch));
00323       int __v;
00324       if (__radix == 8)
00325     __is >> std::oct;
00326       else if (__radix == 16)
00327     __is >> std::hex;
00328       __is >> __v;
00329       return __is.fail() ? -1 : __v;
00330     }
00331 
00332   // [7.8] Class basic_regex
00333   /**
00334    * Objects of specializations of this class represent regular expressions
00335    * constructed from sequences of character type @p _Ch_type.
00336    *
00337    * Storage for the regular expression is allocated and deallocated as
00338    * necessary by the member functions of this class.
00339    */
00340   template<typename _Ch_type, typename _Rx_traits = regex_traits<_Ch_type> >
00341     class basic_regex
00342     {
00343     public:
00344       // types:
00345       typedef _Ch_type                            value_type;
00346       typedef regex_constants::syntax_option_type flag_type;
00347       typedef typename _Rx_traits::locale_type    locale_type;
00348       typedef typename _Rx_traits::string_type    string_type;
00349 
00350       /**
00351        * @name Constants
00352        * std [28.8.1](1)
00353        */
00354       //@{
00355       static constexpr regex_constants::syntax_option_type icase
00356         = regex_constants::icase;
00357       static constexpr regex_constants::syntax_option_type nosubs
00358         = regex_constants::nosubs;
00359       static constexpr regex_constants::syntax_option_type optimize
00360         = regex_constants::optimize;
00361       static constexpr regex_constants::syntax_option_type collate
00362         = regex_constants::collate;
00363       static constexpr regex_constants::syntax_option_type ECMAScript
00364         = regex_constants::ECMAScript;
00365       static constexpr regex_constants::syntax_option_type basic
00366         = regex_constants::basic;
00367       static constexpr regex_constants::syntax_option_type extended
00368         = regex_constants::extended;
00369       static constexpr regex_constants::syntax_option_type awk
00370         = regex_constants::awk;
00371       static constexpr regex_constants::syntax_option_type grep
00372         = regex_constants::grep;
00373       static constexpr regex_constants::syntax_option_type egrep
00374         = regex_constants::egrep;
00375       //@}
00376 
00377       // [7.8.2] construct/copy/destroy
00378       /**
00379        * Constructs a basic regular expression that does not match any
00380        * character sequence.
00381        */
00382       basic_regex()
00383       : _M_flags(regex_constants::ECMAScript),
00384         _M_automaton(__regex::__compile<const _Ch_type*, _Rx_traits>(0, 0,
00385                      _M_traits, _M_flags))
00386       { }
00387 
00388       /**
00389        * @brief Constructs a basic regular expression from the sequence
00390        * [p, p + char_traits<_Ch_type>::length(p)) interpreted according to the
00391        * flags in @p f.
00392        *
00393        * @param p A pointer to the start of a C-style null-terminated string
00394        *          containing a regular expression.
00395        * @param f Flags indicating the syntax rules and options.
00396        *
00397        * @throws regex_error if @p p is not a valid regular expression.
00398        */
00399       explicit
00400       basic_regex(const _Ch_type* __p,
00401           flag_type __f = regex_constants::ECMAScript)
00402       : _M_flags(__f),
00403         _M_automaton(__regex::__compile(__p, __p + _Rx_traits::length(__p),
00404                         _M_traits, _M_flags))
00405       { }
00406 
00407       /**
00408        * @brief Constructs a basic regular expression from the sequence
00409        * [p, p + len) interpreted according to the flags in @p f.
00410        *
00411        * @param p   A pointer to the start of a string containing a regular
00412        *            expression.
00413        * @param len The length of the string containing the regular expression.
00414        * @param f   Flags indicating the syntax rules and options.
00415        *
00416        * @throws regex_error if @p p is not a valid regular expression.
00417        */
00418       basic_regex(const _Ch_type* __p, std::size_t __len, flag_type __f)
00419       : _M_flags(__f),
00420         _M_automaton(__regex::__compile(__p, __p + __len, _M_traits, _M_flags))
00421       { }
00422 
00423       /**
00424        * @brief Copy-constructs a basic regular expression.
00425        *
00426        * @param rhs A @p regex object.
00427        */
00428       basic_regex(const basic_regex& __rhs)
00429       : _M_flags(__rhs._M_flags), _M_traits(__rhs._M_traits),
00430         _M_automaton(__rhs._M_automaton)
00431       { }
00432 
00433       /**
00434        * @brief Move-constructs a basic regular expression.
00435        *
00436        * @param rhs A @p regex object.
00437        */
00438       basic_regex(const basic_regex&& __rhs)
00439       : _M_flags(__rhs._M_flags), _M_traits(__rhs._M_traits),
00440         _M_automaton(std::move(__rhs._M_automaton))
00441       { }
00442 
00443       /**
00444        * @brief Constructs a basic regular expression from the string
00445        * @p s interpreted according to the flags in @p f.
00446        *
00447        * @param s A string containing a regular expression.
00448        * @param f Flags indicating the syntax rules and options.
00449        *
00450        * @throws regex_error if @p s is not a valid regular expression.
00451        */
00452       template<typename _Ch_traits, typename _Ch_alloc>
00453         explicit
00454         basic_regex(const std::basic_string<_Ch_type, _Ch_traits,
00455             _Ch_alloc>& __s,
00456             flag_type __f = regex_constants::ECMAScript)
00457     : _M_flags(__f),
00458       _M_automaton(__regex::__compile(__s.begin(), __s.end(),
00459                       _M_traits, _M_flags))
00460         { }
00461 
00462       /**
00463        * @brief Constructs a basic regular expression from the range
00464        * [first, last) interpreted according to the flags in @p f.
00465        *
00466        * @param first The start of a range containing a valid regular
00467        *              expression.
00468        * @param last  The end of a range containing a valid regular
00469        *              expression.
00470        * @param f     The format flags of the regular expression.
00471        *
00472        * @throws regex_error if @p [first, last) is not a valid regular
00473        *         expression.
00474        */
00475       template<typename _InputIterator>
00476         basic_regex(_InputIterator __first, _InputIterator __last, 
00477             flag_type __f = regex_constants::ECMAScript)
00478     : _M_flags(__f),
00479       _M_automaton(__regex::__compile(__first, __last, _M_traits, _M_flags))
00480         { }
00481 
00482       /**
00483        * @brief Constructs a basic regular expression from an initializer list.
00484        *
00485        * @param l  The initializer list.
00486        * @param f  The format flags of the regular expression.
00487        *
00488        * @throws regex_error if @p l is not a valid regular expression.
00489        */
00490       basic_regex(initializer_list<_Ch_type> __l,
00491           flag_type __f = regex_constants::ECMAScript)
00492       : _M_flags(__f),
00493         _M_automaton(__regex::__compile(__l.begin(), __l.end(),
00494                         _M_traits, _M_flags))
00495       { }
00496 
00497       /**
00498        * @brief Destroys a basic regular expression.
00499        */
00500       ~basic_regex()
00501       { }
00502       
00503       /**
00504        * @brief Assigns one regular expression to another.
00505        */
00506       basic_regex&
00507       operator=(const basic_regex& __rhs)
00508       { return this->assign(__rhs); }
00509 
00510       /**
00511        * @brief Move-assigns one regular expression to another.
00512        */
00513       basic_regex&
00514       operator=(basic_regex&& __rhs)
00515       { return this->assign(std::move(__rhs)); }
00516 
00517       /**
00518        * @brief Replaces a regular expression with a new one constructed from
00519        * a C-style null-terminated string.
00520        *
00521        * @param A pointer to the start of a null-terminated C-style string
00522        *        containing a regular expression.
00523        */
00524       basic_regex&
00525       operator=(const _Ch_type* __p)
00526       { return this->assign(__p, flags()); }
00527       
00528       /**
00529        * @brief Replaces a regular expression with a new one constructed from
00530        * a string.
00531        *
00532        * @param A pointer to a string containing a regular expression.
00533        */
00534       template<typename _Ch_typeraits, typename _Allocator>
00535         basic_regex&
00536         operator=(const basic_string<_Ch_type, _Ch_typeraits, _Allocator>& __s)
00537         { return this->assign(__s, flags()); }
00538 
00539       // [7.8.3] assign
00540       /**
00541        * @brief the real assignment operator.
00542        *
00543        * @param rhs Another regular expression object.
00544        */
00545       basic_regex&
00546       assign(const basic_regex& __rhs)
00547       {
00548     basic_regex __tmp(__rhs);
00549     this->swap(__tmp);
00550     return *this;
00551       }
00552       
00553       /**
00554        * @brief The move-assignment operator.
00555        *
00556        * @param rhs Another regular expression object.
00557        */
00558       basic_regex&
00559       assign(basic_regex&& __rhs)
00560       {
00561     basic_regex __tmp(std::move(__rhs));
00562     this->swap(__tmp);
00563     return *this;
00564       }
00565 
00566       /**
00567        * @brief Assigns a new regular expression to a regex object from a
00568        * C-style null-terminated string containing a regular expression
00569        * pattern.
00570        *
00571        * @param p     A pointer to a C-style null-terminated string containing
00572        *              a regular expression pattern.
00573        * @param flags Syntax option flags.
00574        *
00575        * @throws regex_error if p does not contain a valid regular expression
00576        * pattern interpreted according to @p flags.  If regex_error is thrown,
00577        * *this remains unchanged.
00578        */
00579       basic_regex&
00580       assign(const _Ch_type* __p,
00581          flag_type __flags = regex_constants::ECMAScript)
00582       { return this->assign(string_type(__p), __flags); }
00583 
00584       /**
00585        * @brief Assigns a new regular expression to a regex object from a
00586        * C-style string containing a regular expression pattern.
00587        *
00588        * @param p     A pointer to a C-style string containing a
00589        *              regular expression pattern.
00590        * @param len   The length of the regular expression pattern string.
00591        * @param flags Syntax option flags.
00592        *
00593        * @throws regex_error if p does not contain a valid regular expression
00594        * pattern interpreted according to @p flags.  If regex_error is thrown,
00595        * *this remains unchanged.
00596        */
00597       basic_regex&
00598       assign(const _Ch_type* __p, std::size_t __len, flag_type __flags)
00599       { return this->assign(string_type(__p, __len), __flags); }
00600 
00601       /**
00602        * @brief Assigns a new regular expression to a regex object from a 
00603        * string containing a regular expression pattern.
00604        *
00605        * @param s     A string containing a regular expression pattern.
00606        * @param flags Syntax option flags.
00607        *
00608        * @throws regex_error if p does not contain a valid regular expression
00609        * pattern interpreted according to @p flags.  If regex_error is thrown,
00610        * *this remains unchanged.
00611        */
00612       template<typename _Ch_typeraits, typename _Allocator>
00613         basic_regex&
00614         assign(const basic_string<_Ch_type, _Ch_typeraits, _Allocator>& __s,
00615            flag_type __f = regex_constants::ECMAScript)
00616         { 
00617       basic_regex __tmp(__s, __f);
00618       this->swap(__tmp);
00619       return *this;
00620     }
00621 
00622       /**
00623        * @brief Assigns a new regular expression to a regex object.
00624        *
00625        * @param first The start of a range containing a valid regular
00626        *              expression.
00627        * @param last  The end of a range containing a valid regular
00628        *              expression.
00629        * @param flags Syntax option flags.
00630        *
00631        * @throws regex_error if p does not contain a valid regular expression
00632        * pattern interpreted according to @p flags.  If regex_error is thrown,
00633        * the object remains unchanged.
00634        */
00635       template<typename _InputIterator>
00636         basic_regex&
00637         assign(_InputIterator __first, _InputIterator __last,
00638            flag_type __flags = regex_constants::ECMAScript)
00639         { return this->assign(string_type(__first, __last), __flags); }
00640 
00641       /**
00642        * @brief Assigns a new regular expression to a regex object.
00643        *
00644        * @param l     An initializer list representing a regular expression.
00645        * @param flags Syntax option flags.
00646        *
00647        * @throws regex_error if @p l does not contain a valid regular
00648        * expression pattern interpreted according to @p flags.  If regex_error
00649        * is thrown, the object remains unchanged.
00650        */
00651       basic_regex&
00652       assign(initializer_list<_Ch_type> __l,
00653          flag_type __f = regex_constants::ECMAScript)
00654       { return this->assign(__l.begin(), __l.end(), __f); }
00655 
00656       // [7.8.4] const operations
00657       /**
00658        * @brief Gets the number of marked subexpressions within the regular
00659        * expression.
00660        */
00661       unsigned int
00662       mark_count() const
00663       { return _M_automaton->_M_sub_count() - 1; }
00664       
00665       /**
00666        * @brief Gets the flags used to construct the regular expression
00667        * or in the last call to assign().
00668        */
00669       flag_type
00670       flags() const
00671       { return _M_flags; }
00672       
00673       // [7.8.5] locale
00674       /**
00675        * @brief Imbues the regular expression object with the given locale.
00676        *
00677        * @param loc A locale.
00678        */
00679       locale_type
00680       imbue(locale_type __loc)
00681       { return _M_traits.imbue(__loc); }
00682       
00683       /**
00684        * @brief Gets the locale currently imbued in the regular expression
00685        *        object.
00686        */
00687       locale_type
00688       getloc() const
00689       { return _M_traits.getloc(); }
00690       
00691       // [7.8.6] swap
00692       /**
00693        * @brief Swaps the contents of two regular expression objects.
00694        *
00695        * @param rhs Another regular expression object.
00696        */
00697       void
00698       swap(basic_regex& __rhs)
00699       {
00700     std::swap(_M_flags,     __rhs._M_flags);
00701     std::swap(_M_traits,    __rhs._M_traits);
00702     std::swap(_M_automaton, __rhs._M_automaton);
00703       }
00704 
00705 #ifdef _GLIBCXX_DEBUG
00706       void
00707       _M_dot(std::ostream& __ostr)
00708       { _M_automaton->_M_dot(__ostr); }
00709 #endif
00710       
00711       const __regex::_AutomatonPtr&
00712       _M_get_automaton() const
00713       { return _M_automaton; }
00714 
00715     protected:
00716       flag_type              _M_flags;
00717       _Rx_traits             _M_traits;
00718       __regex::_AutomatonPtr _M_automaton;
00719     };
00720   
00721   /** @brief Standard regular expressions. */
00722   typedef basic_regex<char>    regex;
00723 #ifdef _GLIBCXX_USE_WCHAR_T
00724   /** @brief Standard wide-character regular expressions. */
00725   typedef basic_regex<wchar_t> wregex;
00726 #endif
00727 
00728 
00729   // [7.8.6] basic_regex swap
00730   /**
00731    * @brief Swaps the contents of two regular expression objects.
00732    * @param lhs First regular expression.
00733    * @param rhs Second regular expression.
00734    */
00735   template<typename _Ch_type, typename _Rx_traits>
00736     inline void
00737     swap(basic_regex<_Ch_type, _Rx_traits>& __lhs,
00738      basic_regex<_Ch_type, _Rx_traits>& __rhs)
00739     { __lhs.swap(__rhs); }
00740 
00741 
00742   // [7.9] Class template sub_match
00743   /**
00744    * A sequence of characters matched by a particular marked sub-expression.
00745    *
00746    * An object of this class is essentially a pair of iterators marking a
00747    * matched subexpression within a regular expression pattern match. Such
00748    * objects can be converted to and compared with std::basic_string objects
00749    * of a similar base character type as the pattern matched by the regular
00750    * expression.
00751    *
00752    * The iterators that make up the pair are the usual half-open interval
00753    * referencing the actual original pattern matched.
00754    */
00755   template<typename _BiIter>
00756     class sub_match : public std::pair<_BiIter, _BiIter>
00757     {
00758     public:
00759       typedef typename iterator_traits<_BiIter>::value_type      value_type;
00760       typedef typename iterator_traits<_BiIter>::difference_type
00761                                                             difference_type;
00762       typedef _BiIter                                              iterator;
00763       typedef std::basic_string<value_type>                     string_type;
00764 
00765     public:
00766       bool matched;
00767       
00768       /**
00769        * Gets the length of the matching sequence.
00770        */
00771       difference_type
00772       length() const
00773       { return this->matched ? std::distance(this->first, this->second) : 0; }
00774 
00775       /**
00776        * @brief Gets the matching sequence as a string.
00777        *
00778        * @returns the matching sequence as a string.
00779        *
00780        * This is the implicit conversion operator.  It is identical to the
00781        * str() member function except that it will want to pop up in
00782        * unexpected places and cause a great deal of confusion and cursing
00783        * from the unwary.
00784        */
00785       operator string_type() const
00786       {
00787     return this->matched
00788       ? string_type(this->first, this->second)
00789       : string_type();
00790       }
00791       
00792       /**
00793        * @brief Gets the matching sequence as a string.
00794        *
00795        * @returns the matching sequence as a string.
00796        */
00797       string_type
00798       str() const
00799       {
00800     return this->matched
00801       ? string_type(this->first, this->second)
00802       : string_type();
00803       }
00804       
00805       /**
00806        * @brief Compares this and another matched sequence.
00807        *
00808        * @param s Another matched sequence to compare to this one.
00809        *
00810        * @retval <0 this matched sequence will collate before @p s.
00811        * @retval =0 this matched sequence is equivalent to @p s.
00812        * @retval <0 this matched sequence will collate after @p s.
00813        */
00814       int
00815       compare(const sub_match& __s) const
00816       { return this->str().compare(__s.str()); }
00817 
00818       /**
00819        * @brief Compares this sub_match to a string.
00820        *
00821        * @param s A string to compare to this sub_match.
00822        *
00823        * @retval <0 this matched sequence will collate before @p s.
00824        * @retval =0 this matched sequence is equivalent to @p s.
00825        * @retval <0 this matched sequence will collate after @p s.
00826        */
00827       int
00828       compare(const string_type& __s) const
00829       { return this->str().compare(__s); }
00830       
00831       /**
00832        * @brief Compares this sub_match to a C-style string.
00833        *
00834        * @param s A C-style string to compare to this sub_match.
00835        *
00836        * @retval <0 this matched sequence will collate before @p s.
00837        * @retval =0 this matched sequence is equivalent to @p s.
00838        * @retval <0 this matched sequence will collate after @p s.
00839        */
00840       int
00841       compare(const value_type* __s) const
00842       { return this->str().compare(__s); }
00843     };
00844   
00845   
00846   /** @brief Standard regex submatch over a C-style null-terminated string. */
00847   typedef sub_match<const char*>             csub_match;
00848   /** @brief Standard regex submatch over a standard string. */
00849   typedef sub_match<string::const_iterator>  ssub_match;
00850 #ifdef _GLIBCXX_USE_WCHAR_T
00851   /** @brief Regex submatch over a C-style null-terminated wide string. */
00852   typedef sub_match<const wchar_t*>          wcsub_match;
00853   /** @brief Regex submatch over a standard wide string. */
00854   typedef sub_match<wstring::const_iterator> wssub_match;
00855 #endif
00856 
00857   // [7.9.2] sub_match non-member operators
00858   
00859   /**
00860    * @brief Tests the equivalence of two regular expression submatches.
00861    * @param lhs First regular expression submatch.
00862    * @param rhs Second regular expression submatch.
00863    * @returns true if @a lhs  is equivalent to @a rhs, false otherwise.
00864    */
00865   template<typename _BiIter>
00866     inline bool
00867     operator==(const sub_match<_BiIter>& __lhs,
00868            const sub_match<_BiIter>& __rhs)
00869     { return __lhs.compare(__rhs) == 0; }
00870 
00871   /**
00872    * @brief Tests the inequivalence of two regular expression submatches.
00873    * @param lhs First regular expression submatch.
00874    * @param rhs Second regular expression submatch.
00875    * @returns true if @a lhs  is not equivalent to @a rhs, false otherwise.
00876    */
00877   template<typename _BiIter>
00878     inline bool
00879     operator!=(const sub_match<_BiIter>& __lhs,
00880            const sub_match<_BiIter>& __rhs)
00881     { return __lhs.compare(__rhs) != 0; }
00882 
00883   /**
00884    * @brief Tests the ordering of two regular expression submatches.
00885    * @param lhs First regular expression submatch.
00886    * @param rhs Second regular expression submatch.
00887    * @returns true if @a lhs precedes @a rhs, false otherwise.
00888    */
00889   template<typename _BiIter>
00890     inline bool
00891     operator<(const sub_match<_BiIter>& __lhs,
00892           const sub_match<_BiIter>& __rhs)
00893     { return __lhs.compare(__rhs) < 0; }
00894 
00895   /**
00896    * @brief Tests the ordering of two regular expression submatches.
00897    * @param lhs First regular expression submatch.
00898    * @param rhs Second regular expression submatch.
00899    * @returns true if @a lhs does not succeed @a rhs, false otherwise.
00900    */
00901   template<typename _BiIter>
00902     inline bool
00903     operator<=(const sub_match<_BiIter>& __lhs,
00904            const sub_match<_BiIter>& __rhs)
00905     { return __lhs.compare(__rhs) <= 0; }
00906 
00907   /**
00908    * @brief Tests the ordering of two regular expression submatches.
00909    * @param lhs First regular expression submatch.
00910    * @param rhs Second regular expression submatch.
00911    * @returns true if @a lhs does not precede @a rhs, false otherwise.
00912    */
00913   template<typename _BiIter>
00914     inline bool
00915     operator>=(const sub_match<_BiIter>& __lhs,
00916            const sub_match<_BiIter>& __rhs)
00917     { return __lhs.compare(__rhs) >= 0; }
00918 
00919   /**
00920    * @brief Tests the ordering of two regular expression submatches.
00921    * @param lhs First regular expression submatch.
00922    * @param rhs Second regular expression submatch.
00923    * @returns true if @a lhs succeeds @a rhs, false otherwise.
00924    */
00925   template<typename _BiIter>
00926     inline bool
00927     operator>(const sub_match<_BiIter>& __lhs,
00928           const sub_match<_BiIter>& __rhs)
00929     { return __lhs.compare(__rhs) > 0; }
00930 
00931   /**
00932    * @brief Tests the equivalence of a string and a regular expression
00933    *        submatch.
00934    * @param lhs A string.
00935    * @param rhs A regular expression submatch.
00936    * @returns true if @a lhs  is equivalent to @a rhs, false otherwise.
00937    */
00938   template<typename _Bi_iter, typename _Ch_traits, typename _Ch_alloc>
00939     inline bool
00940     operator==(const basic_string<
00941            typename iterator_traits<_Bi_iter>::value_type,
00942            _Ch_traits, _Ch_alloc>& __lhs,
00943            const sub_match<_Bi_iter>& __rhs)
00944     { return __lhs == __rhs.str(); }
00945 
00946   /**
00947    * @brief Tests the inequivalence of a string and a regular expression
00948    *        submatch.
00949    * @param lhs A string.
00950    * @param rhs A regular expression submatch.
00951    * @returns true if @a lhs  is not equivalent to @a rhs, false otherwise.
00952    */
00953   template<typename _Bi_iter, typename _Ch_traits, typename _Ch_alloc>
00954     inline bool
00955     operator!=(const basic_string<
00956            typename iterator_traits<_Bi_iter>::value_type,
00957            _Ch_traits, _Ch_alloc>& __lhs, const sub_match<_Bi_iter>& __rhs)
00958     { return __lhs != __rhs.str(); }
00959 
00960   /**
00961    * @brief Tests the ordering of a string and a regular expression submatch.
00962    * @param lhs A string.
00963    * @param rhs A regular expression submatch.
00964    * @returns true if @a lhs precedes @a rhs, false otherwise.
00965    */
00966   template<typename _Bi_iter, typename _Ch_traits, typename _Ch_alloc>
00967     inline bool
00968     operator<(const basic_string<
00969           typename iterator_traits<_Bi_iter>::value_type,
00970           _Ch_traits, _Ch_alloc>& __lhs, const sub_match<_Bi_iter>& __rhs)
00971      { return __lhs < __rhs.str(); }
00972 
00973   /**
00974    * @brief Tests the ordering of a string and a regular expression submatch.
00975    * @param lhs A string.
00976    * @param rhs A regular expression submatch.
00977    * @returns true if @a lhs succeeds @a rhs, false otherwise.
00978    */
00979   template<typename _Bi_iter, typename _Ch_traits, typename _Ch_alloc>
00980     inline bool
00981     operator>(const basic_string<
00982           typename iterator_traits<_Bi_iter>::value_type, 
00983           _Ch_traits, _Ch_alloc>& __lhs, const sub_match<_Bi_iter>& __rhs)
00984     { return __lhs > __rhs.str(); }
00985 
00986   /**
00987    * @brief Tests the ordering of a string and a regular expression submatch.
00988    * @param lhs A string.
00989    * @param rhs A regular expression submatch.
00990    * @returns true if @a lhs does not precede @a rhs, false otherwise.
00991    */
00992   template<typename _Bi_iter, typename _Ch_traits, typename _Ch_alloc>
00993     inline bool
00994     operator>=(const basic_string<
00995            typename iterator_traits<_Bi_iter>::value_type,
00996            _Ch_traits, _Ch_alloc>& __lhs, const sub_match<_Bi_iter>& __rhs)
00997     { return __lhs >= __rhs.str(); }
00998 
00999   /**
01000    * @brief Tests the ordering of a string and a regular expression submatch.
01001    * @param lhs A string.
01002    * @param rhs A regular expression submatch.
01003    * @returns true if @a lhs does not succeed @a rhs, false otherwise.
01004    */
01005   template<typename _Bi_iter, typename _Ch_traits, typename _Ch_alloc>
01006     inline bool
01007     operator<=(const basic_string<
01008            typename iterator_traits<_Bi_iter>::value_type,
01009            _Ch_traits, _Ch_alloc>& __lhs, const sub_match<_Bi_iter>& __rhs)
01010     { return __lhs <= __rhs.str(); }
01011 
01012   /**
01013    * @brief Tests the equivalence of a regular expression submatch and a
01014    *        string.
01015    * @param lhs A regular expression submatch.
01016    * @param rhs A string.
01017    * @returns true if @a lhs is equivalent to @a rhs, false otherwise.
01018    */
01019   template<typename _Bi_iter, typename _Ch_traits, typename _Ch_alloc>
01020     inline bool
01021     operator==(const sub_match<_Bi_iter>& __lhs,
01022            const basic_string<
01023            typename iterator_traits<_Bi_iter>::value_type,
01024            _Ch_traits, _Ch_alloc>& __rhs)
01025     { return __lhs.str() == __rhs; }
01026 
01027   /**
01028    * @brief Tests the inequivalence of a regular expression submatch and a
01029    *        string.
01030    * @param lhs A regular expression submatch.
01031    * @param rhs A string.
01032    * @returns true if @a lhs is not equivalent to @a rhs, false otherwise.
01033    */
01034   template<typename _Bi_iter, typename _Ch_traits, typename _Ch_alloc>
01035     inline bool
01036     operator!=(const sub_match<_Bi_iter>& __lhs,
01037            const basic_string<
01038            typename iterator_traits<_Bi_iter>::value_type,
01039            _Ch_traits, _Ch_alloc>& __rhs)
01040     { return __lhs.str() != __rhs; }
01041 
01042   /**
01043    * @brief Tests the ordering of a regular expression submatch and a string.
01044    * @param lhs A regular expression submatch.
01045    * @param rhs A string.
01046    * @returns true if @a lhs precedes @a rhs, false otherwise.
01047    */
01048   template<typename _Bi_iter, class _Ch_traits, class _Ch_alloc>
01049     inline bool
01050     operator<(const sub_match<_Bi_iter>& __lhs,
01051           const basic_string<
01052           typename iterator_traits<_Bi_iter>::value_type,
01053           _Ch_traits, _Ch_alloc>& __rhs)
01054     { return __lhs.str() < __rhs; }
01055 
01056   /**
01057    * @brief Tests the ordering of a regular expression submatch and a string.
01058    * @param lhs A regular expression submatch.
01059    * @param rhs A string.
01060    * @returns true if @a lhs succeeds @a rhs, false otherwise.
01061    */
01062   template<typename _Bi_iter, class _Ch_traits, class _Ch_alloc>
01063     inline bool
01064     operator>(const sub_match<_Bi_iter>& __lhs,
01065           const basic_string<
01066           typename iterator_traits<_Bi_iter>::value_type,
01067           _Ch_traits, _Ch_alloc>& __rhs)
01068     { return __lhs.str() > __rhs; }
01069 
01070   /**
01071    * @brief Tests the ordering of a regular expression submatch and a string.
01072    * @param lhs A regular expression submatch.
01073    * @param rhs A string.
01074    * @returns true if @a lhs does not precede @a rhs, false otherwise.
01075    */
01076   template<typename _Bi_iter, class _Ch_traits, class _Ch_alloc>
01077     inline bool
01078     operator>=(const sub_match<_Bi_iter>& __lhs,
01079            const basic_string<
01080            typename iterator_traits<_Bi_iter>::value_type,
01081            _Ch_traits, _Ch_alloc>& __rhs)
01082     { return __lhs.str() >= __rhs; }
01083 
01084   /**
01085    * @brief Tests the ordering of a regular expression submatch and a string.
01086    * @param lhs A regular expression submatch.
01087    * @param rhs A string.
01088    * @returns true if @a lhs does not succeed @a rhs, false otherwise.
01089    */
01090   template<typename _Bi_iter, class _Ch_traits, class _Ch_alloc>
01091     inline bool
01092     operator<=(const sub_match<_Bi_iter>& __lhs,
01093            const basic_string<
01094            typename iterator_traits<_Bi_iter>::value_type,
01095            _Ch_traits, _Ch_alloc>& __rhs)
01096     { return __lhs.str() <= __rhs; }
01097 
01098   /**
01099    * @brief Tests the equivalence of a C string and a regular expression
01100    *        submatch.
01101    * @param lhs A C string.
01102    * @param rhs A regular expression submatch.
01103    * @returns true if @a lhs  is equivalent to @a rhs, false otherwise.
01104    */
01105   template<typename _Bi_iter>
01106     inline bool
01107     operator==(typename iterator_traits<_Bi_iter>::value_type const* __lhs,
01108            const sub_match<_Bi_iter>& __rhs)
01109     { return __lhs == __rhs.str(); }
01110 
01111   /**
01112    * @brief Tests the inequivalence of an iterator value and a regular
01113    *        expression submatch.
01114    * @param lhs A regular expression submatch.
01115    * @param rhs A string.
01116    * @returns true if @a lhs is not equivalent to @a rhs, false otherwise.
01117    */
01118   template<typename _Bi_iter>
01119     inline bool
01120     operator!=(typename iterator_traits<_Bi_iter>::value_type const* __lhs,
01121            const sub_match<_Bi_iter>& __rhs)
01122     { return __lhs != __rhs.str(); }
01123 
01124   /**
01125    * @brief Tests the ordering of a string and a regular expression submatch.
01126    * @param lhs A string.
01127    * @param rhs A regular expression submatch.
01128    * @returns true if @a lhs precedes @a rhs, false otherwise.
01129    */
01130   template<typename _Bi_iter>
01131     inline bool
01132     operator<(typename iterator_traits<_Bi_iter>::value_type const* __lhs,
01133           const sub_match<_Bi_iter>& __rhs)
01134     { return __lhs < __rhs.str(); }
01135 
01136   /**
01137    * @brief Tests the ordering of a string and a regular expression submatch.
01138    * @param lhs A string.
01139    * @param rhs A regular expression submatch.
01140    * @returns true if @a lhs succeeds @a rhs, false otherwise.
01141    */
01142   template<typename _Bi_iter>
01143     inline bool
01144     operator>(typename iterator_traits<_Bi_iter>::value_type const* __lhs,
01145           const sub_match<_Bi_iter>& __rhs)
01146     { return __lhs > __rhs.str(); }
01147 
01148   /**
01149    * @brief Tests the ordering of a string and a regular expression submatch.
01150    * @param lhs A string.
01151    * @param rhs A regular expression submatch.
01152    * @returns true if @a lhs does not precede @a rhs, false otherwise.
01153    */
01154   template<typename _Bi_iter>
01155     inline bool
01156     operator>=(typename iterator_traits<_Bi_iter>::value_type const* __lhs,
01157            const sub_match<_Bi_iter>& __rhs)
01158     { return __lhs >= __rhs.str(); }
01159 
01160   /**
01161    * @brief Tests the ordering of a string and a regular expression submatch.
01162    * @param lhs A string.
01163    * @param rhs A regular expression submatch.
01164    * @returns true if @a lhs does not succeed @a rhs, false otherwise.
01165    */
01166   template<typename _Bi_iter>
01167     inline bool
01168     operator<=(typename iterator_traits<_Bi_iter>::value_type const* __lhs,
01169            const sub_match<_Bi_iter>& __rhs)
01170     { return __lhs <= __rhs.str(); }
01171 
01172   /**
01173    * @brief Tests the equivalence of a regular expression submatch and a
01174    *        string.
01175    * @param lhs A regular expression submatch.
01176    * @param rhs A pointer to a string?
01177    * @returns true if @a lhs  is equivalent to @a rhs, false otherwise.
01178    */
01179   template<typename _Bi_iter>
01180     inline bool
01181     operator==(const sub_match<_Bi_iter>& __lhs,
01182            typename iterator_traits<_Bi_iter>::value_type const* __rhs)
01183     { return __lhs.str() == __rhs; }
01184 
01185   /**
01186    * @brief Tests the inequivalence of a regular expression submatch and a
01187    *        string.
01188    * @param lhs A regular expression submatch.
01189    * @param rhs A pointer to a string.
01190    * @returns true if @a lhs is not equivalent to @a rhs, false otherwise.
01191    */
01192   template<typename _Bi_iter>
01193     inline bool
01194     operator!=(const sub_match<_Bi_iter>& __lhs,
01195            typename iterator_traits<_Bi_iter>::value_type const* __rhs)
01196     { return __lhs.str() != __rhs; }
01197 
01198   /**
01199    * @brief Tests the ordering of a regular expression submatch and a string.
01200    * @param lhs A regular expression submatch.
01201    * @param rhs A string.
01202    * @returns true if @a lhs precedes @a rhs, false otherwise.
01203    */
01204   template<typename _Bi_iter>
01205     inline bool
01206     operator<(const sub_match<_Bi_iter>& __lhs,
01207           typename iterator_traits<_Bi_iter>::value_type const* __rhs)
01208     { return __lhs.str() < __rhs; }
01209 
01210   /**
01211    * @brief Tests the ordering of a regular expression submatch and a string.
01212    * @param lhs A regular expression submatch.
01213    * @param rhs A string.
01214    * @returns true if @a lhs succeeds @a rhs, false otherwise.
01215    */
01216   template<typename _Bi_iter>
01217     inline bool
01218     operator>(const sub_match<_Bi_iter>& __lhs,
01219           typename iterator_traits<_Bi_iter>::value_type const* __rhs)
01220     { return __lhs.str() > __rhs; }
01221 
01222   /**
01223    * @brief Tests the ordering of a regular expression submatch and a string.
01224    * @param lhs A regular expression submatch.
01225    * @param rhs A string.
01226    * @returns true if @a lhs does not precede @a rhs, false otherwise.
01227    */
01228   template<typename _Bi_iter>
01229     inline bool
01230     operator>=(const sub_match<_Bi_iter>& __lhs,
01231            typename iterator_traits<_Bi_iter>::value_type const* __rhs)
01232     { return __lhs.str() >= __rhs; }
01233 
01234   /**
01235    * @brief Tests the ordering of a regular expression submatch and a string.
01236    * @param lhs A regular expression submatch.
01237    * @param rhs A string.
01238    * @returns true if @a lhs does not succeed @a rhs, false otherwise.
01239    */
01240   template<typename _Bi_iter>
01241     inline bool
01242     operator<=(const sub_match<_Bi_iter>& __lhs,
01243            typename iterator_traits<_Bi_iter>::value_type const* __rhs)
01244     { return __lhs.str() <= __rhs; }
01245 
01246   /**
01247    * @brief Tests the equivalence of a string and a regular expression
01248    *        submatch.
01249    * @param lhs A string.
01250    * @param rhs A regular expression submatch.
01251    * @returns true if @a lhs is equivalent to @a rhs, false otherwise.
01252    */
01253   template<typename _Bi_iter>
01254     inline bool
01255     operator==(typename iterator_traits<_Bi_iter>::value_type const& __lhs,
01256            const sub_match<_Bi_iter>& __rhs)
01257     { return __lhs == __rhs.str(); }
01258 
01259   /**
01260    * @brief Tests the inequivalence of a string and a regular expression
01261    *        submatch.
01262    * @param lhs A string.
01263    * @param rhs A regular expression submatch.
01264    * @returns true if @a lhs is not equivalent to @a rhs, false otherwise.
01265    */
01266   template<typename _Bi_iter>
01267     inline bool
01268     operator!=(typename iterator_traits<_Bi_iter>::value_type const& __lhs,
01269            const sub_match<_Bi_iter>& __rhs)
01270     { return __lhs != __rhs.str(); }
01271 
01272   /**
01273    * @brief Tests the ordering of a string and a regular expression submatch.
01274    * @param lhs A string.
01275    * @param rhs A regular expression submatch.
01276    * @returns true if @a lhs precedes @a rhs, false otherwise.
01277    */
01278   template<typename _Bi_iter>
01279     inline bool
01280     operator<(typename iterator_traits<_Bi_iter>::value_type const& __lhs,
01281           const sub_match<_Bi_iter>& __rhs)
01282     { return __lhs < __rhs.str(); }
01283 
01284   /**
01285    * @brief Tests the ordering of a string and a regular expression submatch.
01286    * @param lhs A string.
01287    * @param rhs A regular expression submatch.
01288    * @returns true if @a lhs succeeds @a rhs, false otherwise.
01289    */
01290   template<typename _Bi_iter>
01291     inline bool
01292     operator>(typename iterator_traits<_Bi_iter>::value_type const& __lhs,
01293           const sub_match<_Bi_iter>& __rhs)
01294     { return __lhs > __rhs.str(); }
01295 
01296   /**
01297    * @brief Tests the ordering of a string and a regular expression submatch.
01298    * @param lhs A string.
01299    * @param rhs A regular expression submatch.
01300    * @returns true if @a lhs does not precede @a rhs, false otherwise.
01301    */
01302   template<typename _Bi_iter>
01303     inline bool
01304     operator>=(typename iterator_traits<_Bi_iter>::value_type const& __lhs,
01305            const sub_match<_Bi_iter>& __rhs)
01306     { return __lhs >= __rhs.str(); }
01307 
01308   /**
01309    * @brief Tests the ordering of a string and a regular expression submatch.
01310    * @param lhs A string.
01311    * @param rhs A regular expression submatch.
01312    * @returns true if @a lhs does not succeed @a rhs, false otherwise.
01313    */
01314   template<typename _Bi_iter>
01315     inline bool
01316     operator<=(typename iterator_traits<_Bi_iter>::value_type const& __lhs,
01317            const sub_match<_Bi_iter>& __rhs)
01318     { return __lhs <= __rhs.str(); }
01319 
01320   /**
01321    * @brief Tests the equivalence of a regular expression submatch and a
01322    *        string.
01323    * @param lhs A regular expression submatch.
01324    * @param rhs A const string reference.
01325    * @returns true if @a lhs  is equivalent to @a rhs, false otherwise.
01326    */
01327   template<typename _Bi_iter>
01328     inline bool
01329     operator==(const sub_match<_Bi_iter>& __lhs,
01330            typename iterator_traits<_Bi_iter>::value_type const& __rhs)
01331     { return __lhs.str() == __rhs; }
01332 
01333   /**
01334    * @brief Tests the inequivalence of a regular expression submatch and a
01335    *        string.
01336    * @param lhs A regular expression submatch.
01337    * @param rhs A const string reference.
01338    * @returns true if @a lhs is not equivalent to @a rhs, false otherwise.
01339    */
01340   template<typename _Bi_iter>
01341     inline bool
01342     operator!=(const sub_match<_Bi_iter>& __lhs,
01343            typename iterator_traits<_Bi_iter>::value_type const& __rhs)
01344     { return __lhs.str() != __rhs; }
01345 
01346   /**
01347    * @brief Tests the ordering of a regular expression submatch and a string.
01348    * @param lhs A regular expression submatch.
01349    * @param rhs A const string reference.
01350    * @returns true if @a lhs precedes @a rhs, false otherwise.
01351    */
01352   template<typename _Bi_iter>
01353     inline bool
01354     operator<(const sub_match<_Bi_iter>& __lhs,
01355           typename iterator_traits<_Bi_iter>::value_type const& __rhs)
01356     { return __lhs.str() < __rhs; }
01357 
01358   /**
01359    * @brief Tests the ordering of a regular expression submatch and a string.
01360    * @param lhs A regular expression submatch.
01361    * @param rhs A const string reference.
01362    * @returns true if @a lhs succeeds @a rhs, false otherwise.
01363    */
01364   template<typename _Bi_iter>
01365     inline bool
01366     operator>(const sub_match<_Bi_iter>& __lhs,
01367           typename iterator_traits<_Bi_iter>::value_type const& __rhs)
01368     { return __lhs.str() > __rhs; }
01369 
01370   /**
01371    * @brief Tests the ordering of a regular expression submatch and a string.
01372    * @param lhs A regular expression submatch.
01373    * @param rhs A const string reference.
01374    * @returns true if @a lhs does not precede @a rhs, false otherwise.
01375    */
01376   template<typename _Bi_iter>
01377     inline bool
01378     operator>=(const sub_match<_Bi_iter>& __lhs,
01379            typename iterator_traits<_Bi_iter>::value_type const& __rhs)
01380     { return __lhs.str() >= __rhs; }
01381 
01382   /**
01383    * @brief Tests the ordering of a regular expression submatch and a string.
01384    * @param lhs A regular expression submatch.
01385    * @param rhs A const string reference.
01386    * @returns true if @a lhs does not succeed @a rhs, false otherwise.
01387    */
01388   template<typename _Bi_iter>
01389     inline bool
01390     operator<=(const sub_match<_Bi_iter>& __lhs,
01391            typename iterator_traits<_Bi_iter>::value_type const& __rhs)
01392     { return __lhs.str() <= __rhs; }
01393 
01394   /**
01395    * @brief Inserts a matched string into an output stream.
01396    *
01397    * @param os The output stream.
01398    * @param m  A submatch string.
01399    *
01400    * @returns the output stream with the submatch string inserted.
01401    */
01402   template<typename _Ch_type, typename _Ch_traits, typename _Bi_iter>
01403     inline
01404     basic_ostream<_Ch_type, _Ch_traits>&
01405     operator<<(basic_ostream<_Ch_type, _Ch_traits>& __os,
01406            const sub_match<_Bi_iter>& __m)
01407     { return __os << __m.str(); }
01408 
01409   // [7.10] Class template match_results
01410 
01411   /*
01412    * Special sub_match object representing an unmatched sub-expression.
01413    */
01414   template<typename _Bi_iter>
01415     inline const sub_match<_Bi_iter>&
01416     __unmatched_sub()
01417     {
01418       static const sub_match<_Bi_iter> __unmatched = sub_match<_Bi_iter>();
01419       return __unmatched;
01420     }
01421 
01422   /**
01423    * @brief The results of a match or search operation.
01424    *
01425    * A collection of character sequences representing the result of a regular
01426    * expression match.  Storage for the collection is allocated and freed as
01427    * necessary by the member functions of class template match_results.
01428    *
01429    * This class satisfies the Sequence requirements, with the exception that
01430    * only the operations defined for a const-qualified Sequence are supported.
01431    *
01432    * The sub_match object stored at index 0 represents sub-expression 0, i.e.
01433    * the whole match. In this case the %sub_match member matched is always true.
01434    * The sub_match object stored at index n denotes what matched the marked
01435    * sub-expression n within the matched expression. If the sub-expression n
01436    * participated in a regular expression match then the %sub_match member
01437    * matched evaluates to true, and members first and second denote the range
01438    * of characters [first, second) which formed that match. Otherwise matched
01439    * is false, and members first and second point to the end of the sequence
01440    * that was searched.
01441    *
01442    * @nosubgrouping
01443    */
01444   template<typename _Bi_iter,
01445        typename _Allocator = allocator<sub_match<_Bi_iter> > >
01446     class match_results
01447     : private std::vector<std::sub_match<_Bi_iter>, _Allocator>
01448     {
01449     private:
01450       /*
01451        * The vector base is empty if this does not represent a successful match.
01452        * Otherwise it contains n+3 elements where n is the number of marked
01453        * sub-expressions:
01454        * [0] entire match
01455        * [1] 1st marked subexpression
01456        * ...
01457        * [n] nth marked subexpression
01458        * [n+1] prefix
01459        * [n+2] suffix
01460        */
01461       typedef std::vector<std::sub_match<_Bi_iter>, _Allocator>
01462                                                               _Base_type;
01463 
01464     public:
01465       /**
01466        * @name 10.? Public Types
01467        */
01468       //@{
01469       typedef sub_match<_Bi_iter>                             value_type;
01470       typedef const value_type&                               const_reference;
01471       typedef const_reference                                 reference;
01472       typedef typename _Base_type::const_iterator             const_iterator;
01473       typedef const_iterator                                  iterator;
01474       typedef typename std::iterator_traits<_Bi_iter>::difference_type
01475                                                               difference_type;
01476       /* TODO: needs allocator_traits */
01477       typedef typename _Allocator::size_type                  size_type;
01478       typedef _Allocator                                      allocator_type;
01479       typedef typename std::iterator_traits<_Bi_iter>::value_type
01480                                                               char_type;
01481       typedef std::basic_string<char_type>                    string_type;
01482       //@}
01483   
01484     public:
01485       /**
01486        * @name 10.1 Construction, Copying, and Destruction
01487        */
01488       //@{
01489 
01490       /**
01491        * @brief Constructs a default %match_results container.
01492        * @post size() returns 0 and str() returns an empty string.
01493        */
01494       explicit
01495       match_results(const _Allocator& __a = _Allocator())
01496       : _Base_type(__a)
01497       { }
01498 
01499       /**
01500        * @brief Copy constructs a %match_results.
01501        */
01502       match_results(const match_results& __rhs)
01503       : _Base_type(__rhs)
01504       { }
01505 
01506       /**
01507        * @brief Assigns rhs to *this.
01508        */
01509       match_results&
01510       operator=(const match_results __rhs)
01511       {
01512     match_results(__rhs).swap(*this);
01513     return *this;
01514       }
01515 
01516       /**
01517        * @brief Destroys a %match_results object.
01518        */
01519       ~match_results()
01520       { }
01521       
01522       //@}
01523 
01524       /**
01525        * @name 10.2 Size
01526        */
01527       //@{
01528 
01529       /**
01530        * @brief Gets the number of matches and submatches.
01531        *
01532        * The number of matches for a given regular expression will be either 0
01533        * if there was no match or mark_count() + 1 if a match was successful.
01534        * Some matches may be empty.
01535        *
01536        * @returns the number of matches found.
01537        */
01538       size_type
01539       size() const
01540       {
01541         size_type __size = _Base_type::size();
01542         return (__size && _Base_type::operator[](0).matched) ? __size - 2 : 0;
01543       }
01544       
01545       size_type
01546       max_size() const
01547       { return _Base_type::max_size(); }
01548 
01549       /**
01550        * @brief Indicates if the %match_results contains no results.
01551        * @retval true The %match_results object is empty.
01552        * @retval false The %match_results object is not empty.
01553        */
01554       bool
01555       empty() const
01556       { return _Base_type::empty(); }
01557       
01558       //@}
01559 
01560       /**
01561        * @name 10.3 Element Access
01562        */
01563       //@{
01564 
01565       /**
01566        * @brief Gets the length of the indicated submatch.
01567        * @param sub indicates the submatch.
01568        *
01569        * This function returns the length of the indicated submatch, or the
01570        * length of the entire match if @p sub is zero (the default).
01571        */
01572       difference_type
01573       length(size_type __sub = 0) const
01574       { return this[__sub].length(); }
01575 
01576       /**
01577        * @brief Gets the offset of the beginning of the indicated submatch.
01578        * @param sub indicates the submatch.
01579        *
01580        * This function returns the offset from the beginning of the target
01581        * sequence to the beginning of the submatch, unless the value of @p sub
01582        * is zero (the default), in which case this function returns the offset
01583        * from the beginning of the target sequence to the beginning of the
01584        * match.
01585        *
01586        * Returns -1 if @p sub is out of range.
01587        */
01588       difference_type
01589       position(size_type __sub = 0) const
01590       {
01591     return __sub < size() ? std::distance(this->prefix().first,
01592                           (*this)[__sub].first) : -1;
01593       }
01594 
01595       /**
01596        * @brief Gets the match or submatch converted to a string type.
01597        * @param sub indicates the submatch.
01598        *
01599        * This function gets the submatch (or match, if @p sub is zero) extracted
01600        * from the target range and converted to the associated string type.
01601        */
01602       string_type
01603       str(size_type __sub = 0) const
01604       { return (*this)[__sub].str(); }
01605       
01606       /**
01607        * @brief Gets a %sub_match reference for the match or submatch.
01608        * @param sub indicates the submatch.
01609        *
01610        * This function gets a reference to the indicated submatch, or the entire
01611        * match if @p sub is zero.
01612        *
01613        * If @p sub >= size() then this function returns a %sub_match with a
01614        * special value indicating no submatch.
01615        */
01616       const_reference
01617       operator[](size_type __sub) const
01618       { 
01619         return __sub < size()
01620            ?  _Base_type::operator[](__sub)
01621            : __unmatched_sub<_Bi_iter>();
01622       }
01623 
01624       /**
01625        * @brief Gets a %sub_match representing the match prefix.
01626        *
01627        * This function gets a reference to a %sub_match object representing the
01628        * part of the target range between the start of the target range and the
01629        * start of the match.
01630        */
01631       const_reference
01632       prefix() const
01633       {
01634         return !empty()
01635                ? _Base_type::operator[](_Base_type::size() - 2)
01636            : __unmatched_sub<_Bi_iter>();
01637       }
01638 
01639       /**
01640        * @brief Gets a %sub_match representing the match suffix.
01641        *
01642        * This function gets a reference to a %sub_match object representing the
01643        * part of the target range between the end of the match and the end of
01644        * the target range.
01645        */
01646       const_reference
01647       suffix() const
01648       {
01649         return !empty()
01650                ? _Base_type::operator[](_Base_type::size() - 1)
01651            : __unmatched_sub<_Bi_iter>();
01652       }
01653 
01654       /**
01655        * @brief Gets an iterator to the start of the %sub_match collection.
01656        */
01657       const_iterator
01658       begin() const
01659       { return _Base_type::begin(); }
01660       
01661       /**
01662        * @brief Gets an iterator to the start of the %sub_match collection.
01663        */
01664       const_iterator
01665       cbegin() const
01666       { return _Base_type::cbegin(); }
01667 
01668       /**
01669        * @brief Gets an iterator to one-past-the-end of the collection.
01670        */
01671       const_iterator
01672       end() const
01673       {
01674         return !empty()
01675                ? _Base_type::end() - 2
01676            : _Base_type::end();
01677       }
01678       
01679       /**
01680        * @brief Gets an iterator to one-past-the-end of the collection.
01681        */
01682       const_iterator
01683       cend() const
01684       {
01685         return !empty()
01686                ? _Base_type::cend() - 2
01687            : _Base_type::cend();
01688       }
01689 
01690       //@}
01691 
01692       /**
01693        * @name 10.4 Formatting
01694        *
01695        * These functions perform formatted substitution of the matched character
01696        * sequences into their target.  The format specifiers and escape sequences
01697        * accepted by these functions are determined by their @p flags parameter 
01698        * as documented above.
01699        */
01700        //@{
01701 
01702       /**
01703        * @todo Implement this function.
01704        */
01705       template<typename _Out_iter>
01706         _Out_iter
01707         format(_Out_iter __out, const string_type& __fmt,
01708            regex_constants::match_flag_type __flags
01709            = regex_constants::format_default) const
01710         { return __out; }
01711 
01712       /**
01713        * @todo Implement this function.
01714        */
01715       string_type
01716       format(const string_type& __fmt,
01717          regex_constants::match_flag_type __flags
01718          = regex_constants::format_default) const;
01719 
01720       //@} 
01721 
01722       /**
01723        * @name 10.5 Allocator
01724        */
01725       //@{ 
01726 
01727       /**
01728        * @brief Gets a copy of the allocator.
01729        */
01730       allocator_type
01731       get_allocator() const
01732       { return _Base_type::get_allocator(); }
01733       
01734       //@} 
01735 
01736       /**
01737        * @name 10.6 Swap
01738        */
01739        //@{ 
01740 
01741       /**
01742        * @brief Swaps the contents of two match_results.
01743        */
01744       void
01745       swap(match_results& __that)
01746       { _Base_type::swap(__that); }
01747       //@} 
01748       
01749     private:
01750       friend class __regex::_SpecializedResults<_Bi_iter, _Allocator>;
01751     };
01752   
01753   typedef match_results<const char*>             cmatch;
01754   typedef match_results<string::const_iterator>  smatch;
01755 #ifdef _GLIBCXX_USE_WCHAR_T
01756   typedef match_results<const wchar_t*>          wcmatch;
01757   typedef match_results<wstring::const_iterator> wsmatch;
01758 #endif
01759 
01760   // match_results comparisons
01761   /**
01762    * @brief Compares two match_results for equality.
01763    * @returns true if the two objects refer to the same match,
01764    * false otherwise.
01765    * @todo Implement this function.
01766    */
01767   template<typename _Bi_iter, typename _Allocator>
01768     inline bool
01769     operator==(const match_results<_Bi_iter, _Allocator>& __m1,
01770            const match_results<_Bi_iter, _Allocator>& __m2);
01771 
01772   /**
01773    * @brief Compares two match_results for inequality.
01774    * @returns true if the two objects do not refer to the same match,
01775    * false otherwise.
01776    */
01777   template<typename _Bi_iter, class _Allocator>
01778     inline bool
01779     operator!=(const match_results<_Bi_iter, _Allocator>& __m1,
01780            const match_results<_Bi_iter, _Allocator>& __m2)
01781     { return !(__m1 == __m2); }
01782 
01783   // [7.10.6] match_results swap
01784   /**
01785    * @brief Swaps two match results.
01786    * @param lhs A match result.
01787    * @param rhs A match result.
01788    *
01789    * The contents of the two match_results objects are swapped.
01790    */
01791   template<typename _Bi_iter, typename _Allocator>
01792     inline void
01793     swap(match_results<_Bi_iter, _Allocator>& __lhs,
01794      match_results<_Bi_iter, _Allocator>& __rhs)
01795     { __lhs.swap(__rhs); }
01796 
01797   // [7.11.2] Function template regex_match
01798   /**
01799    * @name Matching, Searching, and Replacing
01800    */
01801   //@{
01802 
01803   /**
01804    * @brief Determines if there is a match between the regular expression @p e
01805    * and all of the character sequence [first, last).
01806    *
01807    * @param s     Start of the character sequence to match.
01808    * @param e     One-past-the-end of the character sequence to match.
01809    * @param m     The match results.
01810    * @param re    The regular expression.
01811    * @param flags Controls how the regular expression is matched.
01812    *
01813    * @retval true  A match exists.
01814    * @retval false Otherwise.
01815    *
01816    * @throws an exception of type regex_error.
01817    *
01818    * @todo Implement this function.
01819    */
01820   template<typename _Bi_iter, typename _Allocator,
01821        typename _Ch_type, typename _Rx_traits>
01822     bool
01823     regex_match(_Bi_iter                                 __s,
01824                 _Bi_iter                                 __e,
01825                 match_results<_Bi_iter, _Allocator>&     __m,
01826                 const basic_regex<_Ch_type, _Rx_traits>& __re,
01827                 regex_constants::match_flag_type         __flags
01828                                = regex_constants::match_default)
01829     {
01830       __regex::_AutomatonPtr __a = __re._M_get_automaton();
01831       __regex::_Automaton::_SizeT __sz = __a->_M_sub_count();
01832       __regex::_SpecializedCursor<_Bi_iter> __cs(__s, __e);
01833       __regex::_SpecializedResults<_Bi_iter, _Allocator> __r(__sz, __cs, __m);
01834       __regex::_Grep_matcher __matcher(__cs, __r, __a, __flags);
01835       return __m[0].matched;
01836     }
01837 
01838   /**
01839    * @brief Indicates if there is a match between the regular expression @p e
01840    * and all of the character sequence [first, last).
01841    *
01842    * @param first Beginning of the character sequence to match.
01843    * @param last  One-past-the-end of the character sequence to match.
01844    * @param re    The regular expression.
01845    * @param flags Controls how the regular expression is matched.
01846    *
01847    * @retval true  A match exists.
01848    * @retval false Otherwise.
01849    *
01850    * @throws an exception of type regex_error.
01851    */
01852   template<typename _Bi_iter, typename _Ch_type, typename _Rx_traits>
01853     bool
01854     regex_match(_Bi_iter __first, _Bi_iter __last,
01855         const basic_regex<_Ch_type, _Rx_traits>& __re,
01856         regex_constants::match_flag_type __flags
01857         = regex_constants::match_default)
01858     { 
01859       match_results<_Bi_iter> __what;
01860       return regex_match(__first, __last, __what, __re, __flags);
01861     }
01862 
01863   /**
01864    * @brief Determines if there is a match between the regular expression @p e
01865    * and a C-style null-terminated string.
01866    *
01867    * @param s  The C-style null-terminated string to match.
01868    * @param m  The match results.
01869    * @param re The regular expression.
01870    * @param f  Controls how the regular expression is matched.
01871    *
01872    * @retval true  A match exists.
01873    * @retval false Otherwise.
01874    *
01875    * @throws an exception of type regex_error.
01876    */
01877   template<typename _Ch_type, typename _Allocator, typename _Rx_traits>
01878     inline bool
01879     regex_match(const _Ch_type* __s,
01880         match_results<const _Ch_type*, _Allocator>& __m,
01881         const basic_regex<_Ch_type, _Rx_traits>& __re,
01882         regex_constants::match_flag_type __f
01883         = regex_constants::match_default)
01884     { return regex_match(__s, __s + _Rx_traits::length(__s), __m, __re, __f); }
01885 
01886   /**
01887    * @brief Determines if there is a match between the regular expression @p e
01888    * and a string.
01889    *
01890    * @param s     The string to match.
01891    * @param m     The match results.
01892    * @param re    The regular expression.
01893    * @param flags Controls how the regular expression is matched.
01894    *
01895    * @retval true  A match exists.
01896    * @retval false Otherwise.
01897    *
01898    * @throws an exception of type regex_error.
01899    */
01900   template<typename _Ch_traits, typename _Ch_alloc,
01901        typename _Allocator, typename _Ch_type, typename _Rx_traits>
01902     inline bool
01903     regex_match(const basic_string<_Ch_type, _Ch_traits, _Ch_alloc>& __s,
01904         match_results<typename basic_string<_Ch_type, 
01905         _Ch_traits, _Ch_alloc>::const_iterator, _Allocator>& __m,
01906         const basic_regex<_Ch_type, _Rx_traits>& __re,
01907         regex_constants::match_flag_type __flags
01908         = regex_constants::match_default)
01909     { return regex_match(__s.begin(), __s.end(), __m, __re, __flags); }
01910 
01911   /**
01912    * @brief Indicates if there is a match between the regular expression @p e
01913    * and a C-style null-terminated string.
01914    *
01915    * @param s  The C-style null-terminated string to match.
01916    * @param re The regular expression.
01917    * @param f  Controls how the regular expression is matched.
01918    *
01919    * @retval true  A match exists.
01920    * @retval false Otherwise.
01921    *
01922    * @throws an exception of type regex_error.
01923    */
01924   template<typename _Ch_type, class _Rx_traits>
01925     inline bool
01926     regex_match(const _Ch_type* __s,
01927         const basic_regex<_Ch_type, _Rx_traits>& __re,
01928         regex_constants::match_flag_type __f
01929         = regex_constants::match_default)
01930     { return regex_match(__s, __s + _Rx_traits::length(__s), __re, __f); }
01931 
01932   /**
01933    * @brief Indicates if there is a match between the regular expression @p e
01934    * and a string.
01935    *
01936    * @param s     [IN] The string to match.
01937    * @param re    [IN] The regular expression.
01938    * @param flags [IN] Controls how the regular expression is matched.
01939    *
01940    * @retval true  A match exists.
01941    * @retval false Otherwise.
01942    *
01943    * @throws an exception of type regex_error.
01944    */
01945   template<typename _Ch_traits, typename _Str_allocator,
01946        typename _Ch_type, typename _Rx_traits>
01947     inline bool
01948     regex_match(const basic_string<_Ch_type, _Ch_traits, _Str_allocator>& __s,
01949         const basic_regex<_Ch_type, _Rx_traits>& __re,
01950         regex_constants::match_flag_type __flags
01951         = regex_constants::match_default)
01952     { return regex_match(__s.begin(), __s.end(), __re, __flags); }
01953 
01954   // [7.11.3] Function template regex_search
01955   /**
01956    * Searches for a regular expression within a range.
01957    * @param first [IN]  The start of the string to search.
01958    * @param last  [IN]  One-past-the-end of the string to search.
01959    * @param m     [OUT] The match results.
01960    * @param re    [IN]  The regular expression to search for.
01961    * @param flags [IN]  Search policy flags.
01962    * @retval true  A match was found within the string.
01963    * @retval false No match was found within the string, the content of %m is
01964    *               undefined.
01965    *
01966    * @throws an exception of type regex_error.
01967    *
01968    * @todo Implement this function.
01969    */
01970   template<typename _Bi_iter, typename _Allocator,
01971        typename _Ch_type, typename _Rx_traits>
01972     inline bool
01973     regex_search(_Bi_iter __first, _Bi_iter __last,
01974          match_results<_Bi_iter, _Allocator>& __m,
01975          const basic_regex<_Ch_type, _Rx_traits>& __re,
01976          regex_constants::match_flag_type __flags
01977          = regex_constants::match_default)
01978     { return false; }
01979 
01980   /**
01981    * Searches for a regular expression within a range.
01982    * @param first [IN]  The start of the string to search.
01983    * @param last  [IN]  One-past-the-end of the string to search.
01984    * @param re    [IN]  The regular expression to search for.
01985    * @param flags [IN]  Search policy flags.
01986    * @retval true  A match was found within the string.
01987    * @retval false No match was found within the string.
01988    * @doctodo
01989    *
01990    * @throws an exception of type regex_error.
01991    */
01992   template<typename _Bi_iter, typename _Ch_type, typename _Rx_traits>
01993     inline bool
01994     regex_search(_Bi_iter __first, _Bi_iter __last,
01995          const basic_regex<_Ch_type, _Rx_traits>& __re,
01996          regex_constants::match_flag_type __flags
01997          = regex_constants::match_default)
01998     {
01999       match_results<_Bi_iter> __what;
02000       return regex_search(__first, __last, __what, __re, __flags);
02001     }
02002 
02003   /**
02004    * @brief Searches for a regular expression within a C-string.
02005    * @param s [IN]  A C-string to search for the regex.
02006    * @param m [OUT] The set of regex matches.
02007    * @param e [IN]  The regex to search for in @p s.
02008    * @param f [IN]  The search flags.
02009    * @retval true  A match was found within the string.
02010    * @retval false No match was found within the string, the content of %m is
02011    *               undefined.
02012    * @doctodo
02013    *
02014    * @throws an exception of type regex_error.
02015    */
02016   template<typename _Ch_type, class _Allocator, class _Rx_traits>
02017     inline bool
02018     regex_search(const _Ch_type* __s,
02019          match_results<const _Ch_type*, _Allocator>& __m,
02020          const basic_regex<_Ch_type, _Rx_traits>& __e,
02021          regex_constants::match_flag_type __f
02022          = regex_constants::match_default)
02023     { return regex_search(__s, __s + _Rx_traits::length(__s), __m, __e, __f); }
02024 
02025   /**
02026    * @brief Searches for a regular expression within a C-string.
02027    * @param s [IN]  The C-string to search.
02028    * @param e [IN]  The regular expression to search for.
02029    * @param f [IN]  Search policy flags.
02030    * @retval true  A match was found within the string.
02031    * @retval false No match was found within the string.
02032    * @doctodo
02033    *
02034    * @throws an exception of type regex_error.
02035    */
02036   template<typename _Ch_type, typename _Rx_traits>
02037     inline bool
02038     regex_search(const _Ch_type* __s,
02039          const basic_regex<_Ch_type, _Rx_traits>& __e,
02040          regex_constants::match_flag_type __f
02041          = regex_constants::match_default)
02042     { return regex_search(__s, __s + _Rx_traits::length(__s), __e, __f); }
02043 
02044   /**
02045    * @brief Searches for a regular expression within a string.
02046    * @param s     [IN]  The string to search.
02047    * @param e     [IN]  The regular expression to search for.
02048    * @param flags [IN]  Search policy flags.
02049    * @retval true  A match was found within the string.
02050    * @retval false No match was found within the string.
02051    * @doctodo
02052    *
02053    * @throws an exception of type regex_error.
02054    */
02055   template<typename _Ch_traits, typename _String_allocator,
02056        typename _Ch_type, typename _Rx_traits>
02057     inline bool
02058     regex_search(const basic_string<_Ch_type, _Ch_traits,
02059          _String_allocator>& __s,
02060          const basic_regex<_Ch_type, _Rx_traits>& __e,
02061          regex_constants::match_flag_type __flags
02062          = regex_constants::match_default)
02063     { return regex_search(__s.begin(), __s.end(), __e, __flags); }
02064 
02065   /**
02066    * @brief Searches for a regular expression within a string.
02067    * @param s [IN]  A C++ string to search for the regex.
02068    * @param m [OUT] The set of regex matches.
02069    * @param e [IN]  The regex to search for in @p s.
02070    * @param f [IN]  The search flags.
02071    * @retval true  A match was found within the string.
02072    * @retval false No match was found within the string, the content of %m is
02073    *               undefined.
02074    *
02075    * @throws an exception of type regex_error.
02076    */
02077   template<typename _Ch_traits, typename _Ch_alloc,
02078        typename _Allocator, typename _Ch_type,
02079        typename _Rx_traits>
02080     inline bool
02081     regex_search(const basic_string<_Ch_type, _Ch_traits, _Ch_alloc>& __s,
02082          match_results<typename basic_string<_Ch_type,
02083          _Ch_traits, _Ch_alloc>::const_iterator, _Allocator>& __m,
02084          const basic_regex<_Ch_type, _Rx_traits>& __e,
02085          regex_constants::match_flag_type __f
02086          = regex_constants::match_default)
02087     { return regex_search(__s.begin(), __s.end(), __m, __e, __f); }
02088 
02089   // std [28.11.4] Function template regex_replace
02090   /**
02091    * @doctodo
02092    * @param out
02093    * @param first
02094    * @param last
02095    * @param e
02096    * @param fmt
02097    * @param flags
02098    *
02099    * @returns out
02100    * @throws an exception of type regex_error.
02101    *
02102    * @todo Implement this function.
02103    */
02104   template<typename _Out_iter, typename _Bi_iter,
02105        typename _Rx_traits, typename _Ch_type>
02106     inline _Out_iter
02107     regex_replace(_Out_iter __out, _Bi_iter __first, _Bi_iter __last,
02108           const basic_regex<_Ch_type, _Rx_traits>& __e,
02109           const basic_string<_Ch_type>& __fmt,
02110           regex_constants::match_flag_type __flags
02111           = regex_constants::match_default)
02112     { return __out; }
02113 
02114   /**
02115    * @doctodo
02116    * @param s
02117    * @param e
02118    * @param fmt
02119    * @param flags
02120    *
02121    * @returns a copy of string @p s with replacements.
02122    *
02123    * @throws an exception of type regex_error.
02124    */
02125   template<typename _Rx_traits, typename _Ch_type>
02126     inline basic_string<_Ch_type>
02127     regex_replace(const basic_string<_Ch_type>& __s,
02128           const basic_regex<_Ch_type, _Rx_traits>& __e,
02129           const basic_string<_Ch_type>& __fmt,
02130           regex_constants::match_flag_type __flags
02131           = regex_constants::match_default)
02132     {
02133       std::string __result;
02134       regex_replace(std::back_inserter(__result),
02135             __s.begin(), __s.end(), __e, __fmt, __flags);
02136       return __result;
02137     }
02138 
02139   //@}
02140 
02141   // std [28.12] Class template regex_iterator
02142   /**
02143    * An iterator adaptor that will provide repeated calls of regex_search over 
02144    * a range until no more matches remain.
02145    */
02146   template<typename _Bi_iter,
02147        typename _Ch_type = typename iterator_traits<_Bi_iter>::value_type,
02148        typename _Rx_traits = regex_traits<_Ch_type> >
02149     class regex_iterator
02150     {
02151     public:
02152       typedef basic_regex<_Ch_type, _Rx_traits>  regex_type;
02153       typedef match_results<_Bi_iter>            value_type;
02154       typedef std::ptrdiff_t                     difference_type;
02155       typedef const value_type*                  pointer;
02156       typedef const value_type&                  reference;
02157       typedef std::forward_iterator_tag          iterator_category;
02158 
02159     public:
02160       /**
02161        * @brief Provides a singular iterator, useful for indicating
02162        * one-past-the-end of a range.
02163        * @todo Implement this function.
02164        * @doctodo
02165        */
02166       regex_iterator();
02167       
02168       /**
02169        * Constructs a %regex_iterator...
02170        * @param a  [IN] The start of a text range to search.
02171        * @param b  [IN] One-past-the-end of the text range to search.
02172        * @param re [IN] The regular expression to match.
02173        * @param m  [IN] Policy flags for match rules.
02174        * @todo Implement this function.
02175        * @doctodo
02176        */
02177       regex_iterator(_Bi_iter __a, _Bi_iter __b, const regex_type& __re,
02178              regex_constants::match_flag_type __m
02179              = regex_constants::match_default);
02180 
02181       /**
02182        * Copy constructs a %regex_iterator.
02183        * @todo Implement this function.
02184        * @doctodo
02185        */
02186       regex_iterator(const regex_iterator& __rhs);
02187       
02188       /**
02189        * @todo Implement this function.
02190        * @doctodo
02191        */
02192       regex_iterator&
02193       operator=(const regex_iterator& __rhs);
02194       
02195       /**
02196        * @todo Implement this function.
02197        * @doctodo
02198        */
02199       bool
02200       operator==(const regex_iterator& __rhs);
02201       
02202       /**
02203        * @todo Implement this function.
02204        * @doctodo
02205        */
02206       bool
02207       operator!=(const regex_iterator& __rhs);
02208       
02209       /**
02210        * @todo Implement this function.
02211        * @doctodo
02212        */
02213       const value_type&
02214       operator*();
02215       
02216       /**
02217        * @todo Implement this function.
02218        * @doctodo
02219        */
02220       const value_type*
02221       operator->();
02222       
02223       /**
02224        * @todo Implement this function.
02225        * @doctodo
02226        */
02227       regex_iterator&
02228       operator++();
02229       
02230       /**
02231        * @todo Implement this function.
02232        * @doctodo
02233        */
02234       regex_iterator
02235       operator++(int);
02236       
02237     private:
02238       // these members are shown for exposition only:
02239       _Bi_iter                         begin;
02240       _Bi_iter                         end;
02241       const regex_type*                pregex;
02242       regex_constants::match_flag_type flags;
02243       match_results<_Bi_iter>          match;
02244     };
02245   
02246   typedef regex_iterator<const char*>             cregex_iterator;
02247   typedef regex_iterator<string::const_iterator>  sregex_iterator;
02248 #ifdef _GLIBCXX_USE_WCHAR_T
02249   typedef regex_iterator<const wchar_t*>          wcregex_iterator;
02250   typedef regex_iterator<wstring::const_iterator> wsregex_iterator;
02251 #endif
02252 
02253   // [7.12.2] Class template regex_token_iterator
02254   /**
02255    * Iterates over submatches in a range (or @a splits a text string).
02256    *
02257    * The purpose of this iterator is to enumerate all, or all specified,
02258    * matches of a regular expression within a text range.  The dereferenced
02259    * value of an iterator of this class is a std::sub_match object.
02260    */
02261   template<typename _Bi_iter,
02262        typename _Ch_type = typename iterator_traits<_Bi_iter>::value_type,
02263        typename _Rx_traits = regex_traits<_Ch_type> >
02264     class regex_token_iterator
02265     {
02266     public:
02267       typedef basic_regex<_Ch_type, _Rx_traits> regex_type;
02268       typedef sub_match<_Bi_iter>               value_type;
02269       typedef std::ptrdiff_t                    difference_type;
02270       typedef const value_type*                 pointer;
02271       typedef const value_type&                 reference;
02272       typedef std::forward_iterator_tag         iterator_category;
02273       
02274     public:
02275       /**
02276        * @brief Default constructs a %regex_token_iterator.
02277        * @todo Implement this function.
02278        * 
02279        * A default-constructed %regex_token_iterator is a singular iterator
02280        * that will compare equal to the one-past-the-end value for any
02281        * iterator of the same type.
02282        */
02283       regex_token_iterator();
02284       
02285       /**
02286        * Constructs a %regex_token_iterator...
02287        * @param a          [IN] The start of the text to search.
02288        * @param b          [IN] One-past-the-end of the text to search.
02289        * @param re         [IN] The regular expression to search for.
02290        * @param submatch   [IN] Which submatch to return.  There are some
02291        *                        special values for this parameter:
02292        *                        - -1 each enumerated subexpression does NOT
02293        *                          match the regular expression (aka field
02294        *                          splitting)
02295        *                        - 0 the entire string matching the
02296        *                          subexpression is returned for each match
02297        *                          within the text.
02298        *                        - >0 enumerates only the indicated
02299        *                          subexpression from a match within the text.
02300        * @param m          [IN] Policy flags for match rules.
02301        *
02302        * @todo Implement this function.
02303        * @doctodo
02304        */
02305       regex_token_iterator(_Bi_iter __a, _Bi_iter __b, const regex_type& __re,
02306                int __submatch = 0,
02307                regex_constants::match_flag_type __m
02308                = regex_constants::match_default);
02309 
02310       /**
02311        * Constructs a %regex_token_iterator...
02312        * @param a          [IN] The start of the text to search.
02313        * @param b          [IN] One-past-the-end of the text to search.
02314        * @param re         [IN] The regular expression to search for.
02315        * @param submatches [IN] A list of subexpressions to return for each
02316        *                        regular expression match within the text.
02317        * @param m          [IN] Policy flags for match rules.
02318        *
02319        * @todo Implement this function.
02320        * @doctodo
02321        */
02322       regex_token_iterator(_Bi_iter __a, _Bi_iter __b,
02323                const regex_type& __re,
02324                const std::vector<int>& __submatches,
02325                regex_constants::match_flag_type __m
02326                  = regex_constants::match_default);
02327 
02328       /**
02329        * Constructs a %regex_token_iterator...
02330        * @param a          [IN] The start of the text to search.
02331        * @param b          [IN] One-past-the-end of the text to search.
02332        * @param re         [IN] The regular expression to search for.
02333        * @param submatches [IN] A list of subexpressions to return for each
02334        *                        regular expression match within the text.
02335        * @param m          [IN] Policy flags for match rules.
02336        
02337        * @todo Implement this function.
02338        * @doctodo
02339        */
02340       template<std::size_t _Nm>
02341         regex_token_iterator(_Bi_iter __a, _Bi_iter __b,
02342                  const regex_type& __re,
02343                  const int (&__submatches)[_Nm],
02344                  regex_constants::match_flag_type __m
02345                  = regex_constants::match_default);
02346 
02347       /**
02348        * @brief Copy constructs a %regex_token_iterator.
02349        * @param rhs [IN] A %regex_token_iterator to copy.
02350        * @todo Implement this function.
02351        */
02352       regex_token_iterator(const regex_token_iterator& __rhs);
02353       
02354       /**
02355        * @brief Assigns a %regex_token_iterator to another.
02356        * @param rhs [IN] A %regex_token_iterator to copy.
02357        * @todo Implement this function.
02358        */
02359       regex_token_iterator&
02360       operator=(const regex_token_iterator& __rhs);
02361       
02362       /**
02363        * @brief Compares a %regex_token_iterator to another for equality.
02364        * @todo Implement this function.
02365        */
02366       bool
02367       operator==(const regex_token_iterator& __rhs);
02368       
02369       /**
02370        * @brief Compares a %regex_token_iterator to another for inequality.
02371        * @todo Implement this function.
02372        */
02373       bool
02374       operator!=(const regex_token_iterator& __rhs);
02375       
02376       /**
02377        * @brief Dereferences a %regex_token_iterator.
02378        * @todo Implement this function.
02379        */
02380       const value_type&
02381       operator*();
02382       
02383       /**
02384        * @brief Selects a %regex_token_iterator member.
02385        * @todo Implement this function.
02386        */
02387       const value_type*
02388       operator->();
02389       
02390       /**
02391        * @brief Increments a %regex_token_iterator.
02392        * @todo Implement this function.
02393        */
02394       regex_token_iterator&
02395       operator++();
02396       
02397       /**
02398        * @brief Postincrements a %regex_token_iterator.
02399        * @todo Implement this function.
02400        */
02401       regex_token_iterator
02402       operator++(int);
02403       
02404     private: // data members for exposition only:
02405       typedef regex_iterator<_Bi_iter, _Ch_type, _Rx_traits> position_iterator;
02406 
02407       position_iterator __position;
02408       const value_type* __result;
02409       value_type        __suffix;
02410       std::size_t       __n;
02411       std::vector<int>  __subs;
02412     };
02413 
02414   /** @brief Token iterator for C-style NULL-terminated strings. */
02415   typedef regex_token_iterator<const char*>             cregex_token_iterator;
02416   /** @brief Token iterator for standard strings. */
02417   typedef regex_token_iterator<string::const_iterator>  sregex_token_iterator;
02418 #ifdef _GLIBCXX_USE_WCHAR_T
02419   /** @brief Token iterator for C-style NULL-terminated wide strings. */
02420   typedef regex_token_iterator<const wchar_t*>          wcregex_token_iterator;
02421   /** @brief Token iterator for standard wide-character strings. */
02422   typedef regex_token_iterator<wstring::const_iterator> wsregex_token_iterator;
02423 #endif
02424   
02425   //@} // group regex
02426 _GLIBCXX_END_NAMESPACE_VERSION
02427 } // namespace
02428