libstdc++
regex_constants.h
Go to the documentation of this file.
00001 // class template regex -*- C++ -*-
00002 
00003 // Copyright (C) 2010-2014 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_constants.h
00027  *  @brief Constant definitions for the std regex library.
00028  *
00029  *  This is an internal header file, included by other library headers.
00030  *  Do not attempt to use it directly. @headername{regex}
00031  */
00032 
00033 namespace std _GLIBCXX_VISIBILITY(default)
00034 {
00035 /**
00036  * @defgroup regex Regular Expressions
00037  *
00038  * A facility for performing regular expression pattern matching.
00039  * @{
00040  */
00041 
00042 /**
00043  * @namespace std::regex_constants
00044  * @brief ISO C++-0x entities sub namespace for regex.
00045  */
00046 namespace regex_constants
00047 {
00048 _GLIBCXX_BEGIN_NAMESPACE_VERSION
00049 
00050   /**
00051    * @name 5.1 Regular Expression Syntax Options
00052    */
00053   //@{
00054   enum __syntax_option
00055   {
00056     _S_icase,
00057     _S_nosubs,
00058     _S_optimize,
00059     _S_collate,
00060     _S_ECMAScript,
00061     _S_basic,
00062     _S_extended,
00063     _S_awk,
00064     _S_grep,
00065     _S_egrep,
00066     _S_syntax_last
00067   };
00068 
00069   /**
00070    * @brief This is a bitmask type indicating how to interpret the regex.
00071    *
00072    * The @c syntax_option_type is implementation defined but it is valid to
00073    * perform bitwise operations on these values and expect the right thing to
00074    * happen.
00075    *
00076    * A valid value of type syntax_option_type shall have exactly one of the
00077    * elements @c ECMAScript, @c basic, @c extended, @c awk, @c grep, @c egrep
00078    * %set.
00079    */
00080   enum syntax_option_type : unsigned int
00081   {
00082     /**
00083      * Specifies that the matching of regular expressions against a character
00084      * sequence shall be performed without regard to case.
00085      */
00086     icase      = 1 << _S_icase,
00087 
00088     /**
00089      * Specifies that when a regular expression is matched against a character
00090      * container sequence, no sub-expression matches are to be stored in the
00091      * supplied match_results structure.
00092      */
00093     nosubs     = 1 << _S_nosubs,
00094 
00095     /**
00096      * Specifies that the regular expression engine should pay more attention to
00097      * the speed with which regular expressions are matched, and less to the
00098      * speed with which regular expression objects are constructed. Otherwise
00099      * it has no detectable effect on the program output.
00100      */
00101     optimize   = 1 << _S_optimize,
00102 
00103     /**
00104      * Specifies that character ranges of the form [a-b] should be locale
00105      * sensitive.
00106      */
00107     collate    = 1 << _S_collate,
00108 
00109     /**
00110      * Specifies that the grammar recognized by the regular expression engine is
00111      * that used by ECMAScript in ECMA-262 [Ecma International, ECMAScript
00112      * Language Specification, Standard Ecma-262, third edition, 1999], as
00113      * modified in section [28.13].  This grammar is similar to that defined
00114      * in the PERL scripting language but extended with elements found in the
00115      * POSIX regular expression grammar.
00116      */
00117     ECMAScript = 1 << _S_ECMAScript,
00118 
00119     /**
00120      * Specifies that the grammar recognized by the regular expression engine is
00121      * that used by POSIX basic regular expressions in IEEE Std 1003.1-2001,
00122      * Portable Operating System Interface (POSIX), Base Definitions and
00123      * Headers, Section 9, Regular Expressions [IEEE, Information Technology --
00124      * Portable Operating System Interface (POSIX), IEEE Standard 1003.1-2001].
00125      */
00126     basic      = 1 << _S_basic,
00127 
00128     /**
00129      * Specifies that the grammar recognized by the regular expression engine is
00130      * that used by POSIX extended regular expressions in IEEE Std 1003.1-2001,
00131      * Portable Operating System Interface (POSIX), Base Definitions and
00132      * Headers, Section 9, Regular Expressions.
00133      */
00134     extended   = 1 << _S_extended,
00135 
00136     /**
00137      * Specifies that the grammar recognized by the regular expression engine is
00138      * that used by POSIX utility awk in IEEE Std 1003.1-2001.  This option is
00139      * identical to syntax_option_type extended, except that C-style escape
00140      * sequences are supported.  These sequences are:
00141      * \\\\, \\a, \\b, \\f, \\n, \\r, \\t , \\v, \\&apos,, &apos,,
00142      * and \\ddd (where ddd is one, two, or three octal digits).
00143      */
00144     awk        = 1 << _S_awk,
00145 
00146     /**
00147      * Specifies that the grammar recognized by the regular expression engine is
00148      * that used by POSIX utility grep in IEEE Std 1003.1-2001.  This option is
00149      * identical to syntax_option_type basic, except that newlines are treated
00150      * as whitespace.
00151      */
00152     grep       = 1 << _S_grep,
00153 
00154     /**
00155      * Specifies that the grammar recognized by the regular expression engine is
00156      * that used by POSIX utility grep when given the -E option in
00157      * IEEE Std 1003.1-2001.  This option is identical to syntax_option_type
00158      * extended, except that newlines are treated as whitespace.
00159      */
00160     egrep      = 1 << _S_egrep,
00161   };
00162 
00163   constexpr inline syntax_option_type
00164   operator&(syntax_option_type __a, syntax_option_type __b)
00165   {
00166     return (syntax_option_type)(static_cast<unsigned int>(__a)
00167                 & static_cast<unsigned int>(__b));
00168   }
00169 
00170   constexpr inline syntax_option_type
00171   operator|(syntax_option_type __a, syntax_option_type __b)
00172   {
00173     return (syntax_option_type)(static_cast<unsigned int>(__a)
00174                 | static_cast<unsigned int>(__b));
00175   }
00176 
00177   constexpr inline syntax_option_type
00178   operator^(syntax_option_type __a, syntax_option_type __b)
00179   {
00180     return (syntax_option_type)(static_cast<unsigned int>(__a)
00181                 ^ static_cast<unsigned int>(__b));
00182   }
00183 
00184   constexpr inline syntax_option_type
00185   operator~(syntax_option_type __a)
00186   { return (syntax_option_type)(~static_cast<unsigned int>(__a)); }
00187 
00188   inline syntax_option_type&
00189   operator&=(syntax_option_type& __a, syntax_option_type __b)
00190   { return __a = __a & __b; }
00191 
00192   inline syntax_option_type&
00193   operator|=(syntax_option_type& __a, syntax_option_type __b)
00194   { return __a = __a | __b; }
00195 
00196   inline syntax_option_type&
00197   operator^=(syntax_option_type& __a, syntax_option_type __b)
00198   { return __a = __a ^ __b; }
00199 
00200   //@}
00201 
00202   /**
00203    * @name 5.2 Matching Rules
00204    *
00205    * Matching a regular expression against a sequence of characters [first,
00206    * last) proceeds according to the rules of the grammar specified for the
00207    * regular expression object, modified according to the effects listed
00208    * below for any bitmask elements set.
00209    *
00210    */
00211   //@{
00212 
00213   enum __match_flag
00214   {
00215     _S_not_bol,
00216     _S_not_eol,
00217     _S_not_bow,
00218     _S_not_eow,
00219     _S_any,
00220     _S_not_null,
00221     _S_continuous,
00222     _S_prev_avail,
00223     _S_sed,
00224     _S_no_copy,
00225     _S_first_only,
00226     _S_match_flag_last
00227   };
00228 
00229   /**
00230    * @brief This is a bitmask type indicating regex matching rules.
00231    *
00232    * The @c match_flag_type is implementation defined but it is valid to
00233    * perform bitwise operations on these values and expect the right thing to
00234    * happen.
00235    */
00236   enum match_flag_type : unsigned int
00237   {
00238     /**
00239      * The default matching rules.
00240      */
00241     match_default     = 0,
00242 
00243     /**
00244      * The first character in the sequence [first, last) is treated as though it
00245      * is not at the beginning of a line, so the character (^) in the regular
00246      * expression shall not match [first, first).
00247      */
00248     match_not_bol     = 1 << _S_not_bol,
00249 
00250     /**
00251      * The last character in the sequence [first, last) is treated as though it
00252      * is not at the end of a line, so the character ($) in the regular
00253      * expression shall not match [last, last).
00254      */
00255     match_not_eol     = 1 << _S_not_eol,
00256 
00257     /**
00258      * The expression \\b is not matched against the sub-sequence
00259      * [first,first).
00260      */
00261     match_not_bow     = 1 << _S_not_bow,
00262 
00263     /**
00264      * The expression \\b should not be matched against the sub-sequence
00265      * [last,last).
00266      */
00267     match_not_eow     = 1 << _S_not_eow,
00268 
00269     /**
00270      * If more than one match is possible then any match is an acceptable
00271      * result.
00272      */
00273     match_any         = 1 << _S_any,
00274 
00275     /**
00276      * The expression does not match an empty sequence.
00277      */
00278     match_not_null    = 1 << _S_not_null,
00279 
00280     /**
00281      * The expression only matches a sub-sequence that begins at first .
00282      */
00283     match_continuous  = 1 << _S_continuous,
00284 
00285     /**
00286      * --first is a valid iterator position.  When this flag is set then the
00287      * flags match_not_bol and match_not_bow are ignored by the regular
00288      * expression algorithms 28.11 and iterators 28.12.
00289      */
00290     match_prev_avail  = 1 << _S_prev_avail,
00291 
00292     /**
00293      * When a regular expression match is to be replaced by a new string, the
00294      * new string is constructed using the rules used by the ECMAScript replace
00295      * function in ECMA- 262 [Ecma International, ECMAScript Language
00296      * Specification, Standard Ecma-262, third edition, 1999], part 15.5.4.11
00297      * String.prototype.replace. In addition, during search and replace
00298      * operations all non-overlapping occurrences of the regular expression
00299      * are located and replaced, and sections of the input that did not match
00300      * the expression are copied unchanged to the output string.
00301      *
00302      * Format strings (from ECMA-262 [15.5.4.11]):
00303      * @li $$  The dollar-sign itself ($)
00304      * @li $&  The matched substring.
00305      * @li $`  The portion of @a string that precedes the matched substring.
00306      *         This would be match_results::prefix().
00307      * @li $'  The portion of @a string that follows the matched substring.
00308      *         This would be match_results::suffix().
00309      * @li $n  The nth capture, where n is in [1,9] and $n is not followed by a
00310      *         decimal digit.  If n <= match_results::size() and the nth capture
00311      *         is undefined, use the empty string instead.  If n >
00312      *         match_results::size(), the result is implementation-defined.
00313      * @li $nn The nnth capture, where nn is a two-digit decimal number on
00314      *         [01, 99].  If nn <= match_results::size() and the nth capture is
00315      *         undefined, use the empty string instead. If
00316      *         nn > match_results::size(), the result is implementation-defined.
00317      */
00318     format_default    = 0,
00319 
00320     /**
00321      * When a regular expression match is to be replaced by a new string, the
00322      * new string is constructed using the rules used by the POSIX sed utility
00323      * in IEEE Std 1003.1- 2001 [IEEE, Information Technology -- Portable
00324      * Operating System Interface (POSIX), IEEE Standard 1003.1-2001].
00325      */
00326     format_sed        = 1 << _S_sed,
00327 
00328     /**
00329      * During a search and replace operation, sections of the character
00330      * container sequence being searched that do not match the regular
00331      * expression shall not be copied to the output string.
00332      */
00333     format_no_copy    = 1 << _S_no_copy,
00334 
00335     /**
00336      * When specified during a search and replace operation, only the first
00337      * occurrence of the regular expression shall be replaced.
00338      */
00339     format_first_only = 1 << _S_first_only,
00340   };
00341 
00342   constexpr inline match_flag_type
00343   operator&(match_flag_type __a, match_flag_type __b)
00344   {
00345     return (match_flag_type)(static_cast<unsigned int>(__a)
00346                 & static_cast<unsigned int>(__b));
00347   }
00348 
00349   constexpr inline match_flag_type
00350   operator|(match_flag_type __a, match_flag_type __b)
00351   {
00352     return (match_flag_type)(static_cast<unsigned int>(__a)
00353                 | static_cast<unsigned int>(__b));
00354   }
00355 
00356   constexpr inline match_flag_type
00357   operator^(match_flag_type __a, match_flag_type __b)
00358   {
00359     return (match_flag_type)(static_cast<unsigned int>(__a)
00360                 ^ static_cast<unsigned int>(__b));
00361   }
00362 
00363   constexpr inline match_flag_type
00364   operator~(match_flag_type __a)
00365   { return (match_flag_type)(~static_cast<unsigned int>(__a)); }
00366 
00367   inline match_flag_type&
00368   operator&=(match_flag_type& __a, match_flag_type __b)
00369   { return __a = __a & __b; }
00370 
00371   inline match_flag_type&
00372   operator|=(match_flag_type& __a, match_flag_type __b)
00373   { return __a = __a | __b; }
00374 
00375   inline match_flag_type&
00376   operator^=(match_flag_type& __a, match_flag_type __b)
00377   { return __a = __a ^ __b; }
00378 
00379   //@}
00380 
00381 _GLIBCXX_END_NAMESPACE_VERSION
00382 } // namespace regex_constants
00383 
00384 /* @} */ // group regex
00385 } // namespace std
00386