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