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