diff --git a/build/Jamfile.v2 b/build/Jamfile.v2
index ca7f801f..8943a3f9 100644
--- a/build/Jamfile.v2
+++ b/build/Jamfile.v2
@@ -22,7 +22,7 @@ rule check-icu-config ( )
if ! $(gICU_CONFIG_CHECKED)
{
- if $(HAVE_ICU)
+ if $(HAVE_ICU) && ! $(ICU_PATH)
{
gHAS_ICU = true ;
gICU_CORE_LIB = icuuc ;
@@ -79,6 +79,10 @@ rule check-icu-config ( )
{
gICU_IN_LIB = icuin ;
}
+ else if [ GLOB $(dir)/lib : icui18n.* ]
+ {
+ gICU_IN_LIB = icui18n ;
+ }
else if [ GLOB $(dir)/lib64 : libicui18n.* ]
{
gICU_IN_LIB = icui18n ;
diff --git a/doc/format_boost_syntax.qbk b/doc/format_boost_syntax.qbk
index cba57dd8..c3871041 100644
--- a/doc/format_boost_syntax.qbk
+++ b/doc/format_boost_syntax.qbk
@@ -33,6 +33,15 @@ order to prevent ambiguities.
For example, the format string "(?1foo:bar)" will replace each match found with "foo" if
the sub-expression $1 was matched, and with "bar" otherwise.
+For sub-expressions with an index greater than 9, or for access to named sub-expressions use:
+
+?{INDEX}true-expression:false-expression
+
+or
+
+?{NAME}true-expression:false-expression
+
+
[h4 Placeholder Sequences]
Placeholder sequences specify that some part of what matched the regular expression
@@ -41,12 +50,24 @@ should be sent to output as follows:
[table
[[Placeholder][Meaning]]
[[$&][Outputs what matched the whole expression.]]
-[[$`][Outputs the text between the end of the last match found (or the
- start of the text if no previous match was found), and the start
- of the current match.]]
+[[$MATCH][As $&]]
+[[${^MATCH}][As $&]]
+[[$\`][Outputs the text between the end of the last match found (or the
+ start of the text if no previous match was found), and the start
+ of the current match.]]
+[[$PREMATCH][As $\`]]
+[[${^PREMATCH}][As $\`]]
[[$'][Outputs all the text following the end of the current match.]]
+[[$POSTMATCH][As $']]
+[[${^POSTMATCH}][As $']]
+[[$+][Outputs what matched the last marked sub-expression in the regular expression.]]
+[[$LAST_PAREN_MATCH][As $+]]
+[[$LAST_SUBMATCH_RESULT][Outputs what matched the last sub-expression to be actually matched.]]
+[[$^N][As $LAST_SUBMATCH_RESULT]]
[[$$][Outputs a literal '$']]
[[$n][Outputs what matched the n'th sub-expression.]]
+[[${n}][Outputs what matched the n'th sub-expression.]]
+[[$+{NAME}][Outputs whatever matched the sub-expression named "NAME".]]
]
Any $-placeholder sequence not listed above, results in '$' being treated as a literal.
diff --git a/doc/format_perl_syntax.qbk b/doc/format_perl_syntax.qbk
index cfd57500..63cdbab2 100644
--- a/doc/format_perl_syntax.qbk
+++ b/doc/format_perl_syntax.qbk
@@ -17,13 +17,24 @@ should be sent to output as follows:
[table
[[Placeholder][Meaning]]
[[$&][Outputs what matched the whole expression.]]
-[[$`][Outputs the text between the end of the last match found (or the
+[[$MATCH][As $&]]
+[[${^MATCH}][As $&]]
+[[$\`][Outputs the text between the end of the last match found (or the
start of the text if no previous match was found), and the start
of the current match.]]
+[[$PREMATCH][As $\`]]
+[[${^PREMATCH}][As $\`]]
[[$'][Outputs all the text following the end of the current match.]]
+[[$POSTMATCH][As $']]
+[[${^POSTMATCH}][As $']]
+[[$+][Outputs what matched the last marked sub-expression in the regular expression.]]
+[[$LAST_PAREN_MATCH][As $+]]
+[[$LAST_SUBMATCH_RESULT][Outputs what matched the last sub-expression to be actually matched.]]
+[[$^N][As $LAST_SUBMATCH_RESULT]]
[[$$][Outputs a literal '$']]
[[$n][Outputs what matched the n'th sub-expression.]]
[[${n}][Outputs what matched the n'th sub-expression.]]
+[[$+{NAME}][Outputs whatever matched the sub-expression named "NAME".]]
]
Any $-placeholder sequence not listed above, results in '$' being treated
diff --git a/doc/history.qbk b/doc/history.qbk
index 05a9710e..360f8922 100644
--- a/doc/history.qbk
+++ b/doc/history.qbk
@@ -8,6 +8,11 @@
[section:history History]
+[h4 Boost 1.40]
+
+* Added support for many Perl 5.10 syntax elements including named
+sub-expressions, branch resets and recursive regular expressions.
+
[h4 Boost 1.38]
* [*Breaking change]: empty expressions, and empty alternatives are now
diff --git a/doc/html/boost_regex/background_information.html b/doc/html/boost_regex/background_information.html
index db5c0165..76048eed 100644
--- a/doc/html/boost_regex/background_information.html
+++ b/doc/html/boost_regex/background_information.html
@@ -3,7 +3,7 @@
Background Information
-
+
diff --git a/doc/html/boost_regex/background_information/acknowledgements.html b/doc/html/boost_regex/background_information/acknowledgements.html
index 71f5252f..68565667 100644
--- a/doc/html/boost_regex/background_information/acknowledgements.html
+++ b/doc/html/boost_regex/background_information/acknowledgements.html
@@ -3,7 +3,7 @@
Acknowledgements
-
+
diff --git a/doc/html/boost_regex/background_information/examples.html b/doc/html/boost_regex/background_information/examples.html
index 9f9dcc6c..39bd0df1 100644
--- a/doc/html/boost_regex/background_information/examples.html
+++ b/doc/html/boost_regex/background_information/examples.html
@@ -3,7 +3,7 @@
Test and Example Programs
-
+
@@ -28,7 +28,7 @@
Example Programs
@@ -36,7 +45,7 @@
empty alternatives are now allowed when using the Perl regular expression
syntax. This change has been added for Perl compatibility, when the new
syntax_option_typeno_empty_expressions is set then the old behaviour
- is preserved and empty expressions are prohibited.
+ is preserved and empty expressions are prohibited. This is issue #1081.
Added support for Perl style ${n} expressions in format strings (issue
@@ -53,7 +62,7 @@
Sed Format String Syntax
-
+
diff --git a/doc/html/boost_regex/install.html b/doc/html/boost_regex/install.html
index d325791c..3f61840d 100644
--- a/doc/html/boost_regex/install.html
+++ b/doc/html/boost_regex/install.html
@@ -3,7 +3,7 @@
Building and Installing the Library
-
+
@@ -49,7 +49,7 @@
file before you can use it, instructions for specific platforms are as follows:
Effects: Returns the length of sub-expression
sub, that is to say: (*this)[sub].length().
+
+ The overloads that accept a string refer to a named sub-expression n.
+ In the event that there is no such named sub-expression then returns an empty
+ string.
+
+
+ The template overloads of this function, allow the string and/or character
+ type to be different from the character type of the underlying sequence and/or
+ regular expression: in this case the characters will be widened to the underlying
+ character type of the original regular expression. A compiler error will
+ occur if the argument passes a wider character type than the underlying sequence.
+ These overloads allow a normal narrow character C string literal to be used
+ as an argument, even when the underlying character type of the expression
+ being matched may be something more exotic such as a Unicode character type.
+
Effects: Returns the starting location of
@@ -391,17 +440,61 @@
will return the location of the partial match even though (*this)[0].matched
is false.
+
+ The overloads that accept a string refer to a named sub-expression n.
+ In the event that there is no such named sub-expression then returns an empty
+ string.
+
+
+ The template overloads of this function, allow the string and/or character
+ type to be different from the character type of the underlying sequence and/or
+ regular expression: in this case the characters will be widened to the underlying
+ character type of the original regular expression. A compiler error will
+ occur if the argument passes a wider character type than the underlying sequence.
+ These overloads allow a normal narrow character C string literal to be used
+ as an argument, even when the underlying character type of the expression
+ being matched may be something more exotic such as a Unicode character type.
+
Effects: Returns sub-expression sub
as a string: string_type((*this)[sub]).
+
+ The overloads that accept a string, return the string that matched the named
+ sub-expression n. In the event that there is no such
+ named sub-expression then returns an empty string.
+
+
+ The template overloads of this function, allow the string and/or character
+ type to be different from the character type of the underlying sequence and/or
+ regular expression: in this case the characters will be widened to the underlying
+ character type of the original regular expression. A compiler error will
+ occur if the argument passes a wider character type than the underlying sequence.
+ These overloads allow a normal narrow character C string literal to be used
+ as an argument, even when the underlying character type of the expression
+ being matched may be something more exotic such as a Unicode character type.
+
Effects: Returns a reference to the sub_match
@@ -413,6 +506,22 @@
then returns a sub_match
object whose matched member is false.
+
+ The overloads that accept a string, return a reference to the sub_match object representing the
+ character sequence that matched the named sub-expression n.
+ In the event that there is no such named sub-expression then returns a sub_match
+ object whose matched member is false.
+
+
+ The template overloads of this function, allow the string and/or character
+ type to be different from the character type of the underlying sequence and/or
+ regular expression: in this case the characters will be widened to the underlying
+ character type of the original regular expression. A compiler error will
+ occur if the argument passes a wider character type than the underlying sequence.
+ These overloads allow a normal narrow character C string literal to be used
+ as an argument, even when the underlying character type of the expression
+ being matched may be something more exotic such as a Unicode character type.
+
const_referenceprefix()const;
diff --git a/doc/html/boost_regex/ref/non_std_strings.html b/doc/html/boost_regex/ref/non_std_strings.html
index 5f38cc26..4681e22b 100644
--- a/doc/html/boost_regex/ref/non_std_strings.html
+++ b/doc/html/boost_regex/ref/non_std_strings.html
@@ -3,7 +3,7 @@
Interfacing With Non-Standard String Types
-
+
diff --git a/doc/html/boost_regex/ref/non_std_strings/icu.html b/doc/html/boost_regex/ref/non_std_strings/icu.html
index 2e7fdaf3..c369d563 100644
--- a/doc/html/boost_regex/ref/non_std_strings/icu.html
+++ b/doc/html/boost_regex/ref/non_std_strings/icu.html
@@ -3,7 +3,7 @@
Working With Unicode and ICU String Types
-
+
diff --git a/doc/html/boost_regex/ref/non_std_strings/icu/intro.html b/doc/html/boost_regex/ref/non_std_strings/icu/intro.html
index 0f426829..69b659bf 100644
--- a/doc/html/boost_regex/ref/non_std_strings/icu/intro.html
+++ b/doc/html/boost_regex/ref/non_std_strings/icu/intro.html
@@ -3,7 +3,7 @@
Introduction to using Regex with ICU
-
+
diff --git a/doc/html/boost_regex/ref/non_std_strings/icu/unicode_algo.html b/doc/html/boost_regex/ref/non_std_strings/icu/unicode_algo.html
index e636e849..4ea31468 100644
--- a/doc/html/boost_regex/ref/non_std_strings/icu/unicode_algo.html
+++ b/doc/html/boost_regex/ref/non_std_strings/icu/unicode_algo.html
@@ -3,7 +3,7 @@
Unicode Regular Expression Algorithms
-
+
@@ -43,7 +43,7 @@
on to the "real" algorithm.
Introduction to Boost.Regex and MFC Strings
-
+
diff --git a/doc/html/boost_regex/ref/non_std_strings/mfc_strings/mfc_iter.html b/doc/html/boost_regex/ref/non_std_strings/mfc_strings/mfc_iter.html
index 1cae51e5..54858bc8 100644
--- a/doc/html/boost_regex/ref/non_std_strings/mfc_strings/mfc_iter.html
+++ b/doc/html/boost_regex/ref/non_std_strings/mfc_strings/mfc_iter.html
@@ -3,7 +3,7 @@
Iterating Over the Matches Within An MFC String
-
+
@@ -32,7 +32,7 @@
an MFC/ATL string to a regex_iterator or regex_token_iterator:
template<classBidirectionalIterator,classAllocator,classcharT,classtraits>
@@ -360,7 +360,7 @@
Effects: Returns the result of regex_match(s.begin(),s.end(),e,flags).
template<classBidirectionalIterator,classAllocator,classcharT,classtraits>
@@ -355,7 +355,7 @@
Effects: Returns the result of regex_search(s.begin(),s.end(),e,flags).
The Perl regular expression syntax is based on that used by the programming
language Perl . Perl regular expressions are the default behavior in Boost.Regex
- or you can pass the flag perl
- to the basic_regex
- constructor, for example:
+ or you can pass the flag perl to the basic_regex constructor, for example:
// e1 is a case sensitive Perl regular expression:
// since Perl is the default option there's no need to explicitly specify the syntax used here:
@@ -45,7 +43,7 @@
boost::regexe2(my_expression,boost::regex::perl|boost::regex::icase);
The NULL character when the flag
- match_not_dot_null
- is passed to the matching algorithms.
+ match_not_dot_null is passed to the matching
+ algorithms.
The newline character when the flag
- match_not_dot_newline
- is passed to the matching algorithms.
+ match_not_dot_newline is passed to the matching
+ algorithms.
- A section beginning ( and ending
- ) acts as a marked sub-expression.
- Whatever matched the sub-expression is split out in a separate field by the
- matching algorithms. Marked sub-expressions can also repeated, or referred
- to by a back-reference.
+ A section beginning ( and ending )
+ acts as a marked sub-expression. Whatever matched the sub-expression is split
+ out in a separate field by the matching algorithms. Marked sub-expressions
+ can also repeated, or referred to by a back-reference.
@@ -105,34 +102,32 @@
A marked sub-expression is useful to lexically group part of a regular expression,
but has the side-effect of spitting out an extra field in the result. As
an alternative you can lexically group part of a regular expression, without
- generating a marked sub-expression by using (?:
- and ) , for example (?:ab)+
- will repeat ab without splitting
- out any separate sub-expressions.
+ generating a marked sub-expression by using (?: and )
+ , for example (?:ab)+ will repeat ab
+ without splitting out any separate sub-expressions.
Any atom (a single character, a marked sub-expression, or a character class)
- can be repeated with the *,
- +, ?,
- and {} operators.
+ can be repeated with the *, +, ?,
+ and {} operators.
- The * operator will match the
- preceding atom zero or more times, for example the expression a*b
- will match any of the following:
+ The * operator will match the preceding atom zero or more
+ times, for example the expression a*b will match any of
+ the following:
babaaaaaaaab
- The + operator will match the
- preceding atom one or more times, for example the expression a+b
- will match any of the following:
+ The + operator will match the preceding atom one or more
+ times, for example the expression a+b will match any of
+ the following:
abaaaaaaaab
@@ -143,9 +138,8 @@
b
- The ? operator will match the
- preceding atom zero or one times, for example the expression ca?b will match
- any of the following:
+ The ? operator will match the preceding atom zero or one
+ times, for example the expression ca?b will match any of the following:
cbcab
@@ -159,16 +153,13 @@
An atom can also be repeated with a bounded repeat:
- a{n} Matches
- 'a' repeated exactly n times.
+ a{n} Matches 'a' repeated exactly n times.
- a{n,} Matches
- 'a' repeated n or more times.
+ a{n,} Matches 'a' repeated n or more times.
- a{n,m} Matches 'a' repeated between n and m times
- inclusive.
+ a{n, m} Matches 'a' repeated between n and m times inclusive.
For example:
@@ -193,11 +184,11 @@
a(*)
- Will raise an error, as there is nothing for the *
- operator to be applied to.
+ Will raise an error, as there is nothing for the * operator
+ to be applied to.
@@ -207,28 +198,59 @@
that will consume as little input as possible while still producing a match.
- *? Matches the previous atom
- zero or more times, while consuming as little input as possible.
+ *? Matches the previous atom zero or more times, while
+ consuming as little input as possible.
- +? Matches the previous atom
- one or more times, while consuming as little input as possible.
+ +? Matches the previous atom one or more times, while
+ consuming as little input as possible.
- ?? Matches the previous atom
- zero or one times, while consuming as little input as possible.
+ ?? Matches the previous atom zero or one times, while
+ consuming as little input as possible.
- {n,}? Matches the previous atom n or more times,
+ {n,}? Matches the previous atom n or more times, while
+ consuming as little input as possible.
+
+
+ {n,m}? Matches the previous atom between n and m times,
while consuming as little input as possible.
- {n,m}?
- Matches the previous atom between n and m times, while consuming as little
- input as possible.
+ By default when a repeated patten does not match then the engine will backtrack
+ until a match is found. However, this behaviour can sometime be undesireable
+ so there are also "pocessive" repeats: these match as much as possible
+ and do not then allow backtracking if the rest of the expression fails to
+ match.
+
+
+ *+ Matches the previous atom zero or more times, while
+ giving nothing back.
+
+
+ ++ Matches the previous atom one or more times, while
+ giving nothing back.
+
+
+ ?+ Matches the previous atom zero or one times, while
+ giving nothing back.
+
+
+ {n,}+ Matches the previous atom n or more times, while
+ giving nothing back.
+
+
+ {n,m}+ Matches the previous atom between n and m times,
+ while giving nothing back.
+ You can also use the \g escape for the same function, for example:
+
+
+
+
+
+
+
+
+
+ Escape
+
+
+
+
+ Meaning
+
+
+
+
+
+
+
+ \g1
+
+
+
+
+ Match whatever matched sub-expression 1
+
+
+
+
+
+
+ \g{1}
+
+
+
+
+ Match whatever matched sub-expression 1: this form allows for safer
+ parsing of the expression in cases like \g{1}2
+ or for indexes higher than 9 as in \g{1234}
+
+
+
+
+
+
+ \g-1
+
+
+
+
+ Match whatever matched the last opened sub-expression
+
+
+
+
+
+
+ \g{-2}
+
+
+
+
+ Match whatever matched the last but one opened sub-expression
+
+
+
+
+
+
+ \g{one}
+
+
+
+
+ Match whatever matched the sub-expression named "one"
+
+
+
+
+
+
+ Finally the \k escape can be used to refer to named subexpressions, for example
+ \k<two> will match whatever matched the subexpression
+ named "two".
+
- The | operator will match either
- of its arguments, so for example: abc|def will
- match either "abc" or "def".
+ The | operator will match either of its arguments, so
+ for example: abc|def will match either "abc"
+ or "def".
- Parenthesis can be used to group alternations, for example: ab(d|ef)
+ Parenthesis can be used to group alternations, for example: ab(d|ef)
will match either of "abd" or "abef".
Empty alternatives are not allowed (these are almost always a mistake), but
- if you really want an empty alternative use (?:)
- as a placeholder, for example:
+ if you really want an empty alternative use (?:) as a
+ placeholder, for example:
- |abc
- is not a valid expression, but
+ |abc is not a valid expression, but
- (?:)|abc
- is and is equivalent, also the expression:
+ (?:)|abc is and is equivalent, also the expression:
- (?:abc)?? has exactly the same effect.
+ (?:abc)?? has exactly the same effect.
- A character set is a bracket-expression starting with [
- and ending with ], it defines
- a set of characters, and matches any single character that is a member of
- that set.
+ A character set is a bracket-expression starting with [
+ and ending with ], it defines a set of characters, and
+ matches any single character that is a member of that set.
A bracket expression may contain any combination of the following:
- For example [a-c]
- will match any single character in the range 'a' to 'c'. By default, for
- Perl regular expressions, a character x is within the range y to z, if the
- code point of the character lies within the codepoints of the endpoints of
- the range. Alternatively, if you set the collate flag when constructing the
- regular expression, then ranges are locale sensitive.
+ For example [a-c] will match any single character in the
+ range 'a' to 'c'. By default, for Perl regular expressions, a character x
+ is within the range y to z, if the code point of the character lies within
+ the codepoints of the endpoints of the range. Alternatively, if you set the
+ collate
+ flag when constructing the regular expression, then ranges are locale
+ sensitive.
If the bracket-expression begins with the ^ character, then it matches the
- complement of the characters it contains, for example [^a-c] matches any character that is not in the
- range a-c.
+ complement of the characters it contains, for example [^a-c]
+ matches any character that is not in the range a-c.
- An expression of the form [[:name:]]
- matches the named character class "name", for example [[:lower:]] matches any lower case character. See
- character class names.
+ An expression of the form [[:name:]] matches the named
+ character class "name", for example [[:lower:]]
+ matches any lower case character. See character
+ class names.
- An expression of the form [[.col.] matches
- the collating element col. A collating element is any
- single character, or any sequence of characters that collates as a single
- unit. Collating elements may also be used as the end point of a range, for
- example: [[.ae.]-c]
+ An expression of the form [[.col.]] matches the collating
+ element col. A collating element is any single character,
+ or any sequence of characters that collates as a single unit. Collating elements
+ may also be used as the end point of a range, for example: [[.ae.]-c]
matches the character sequence "ae", plus any single character
in the range "ae"-c, assuming that "ae" is treated as
a single collating element in the current locale.
@@ -350,28 +460,27 @@
[[.NUL.]]
- matches a \0
- character.
+ matches a \0 character.
- An expression of the form [[=col=]],
- matches any character or collating element whose primary sort key is the
- same as that for collating element col, as with collating
- elements the name col may be a symbolic
- name. A primary sort key is one that ignores case, accentation, or
- locale-specific tailorings; so for example [[=a=]] matches
+ An expression of the form [[=col=]], matches any character
+ or collating element whose primary sort key is the same as that for collating
+ element col, as with collating elements the name col
+ may be a symbolic name.
+ A primary sort key is one that ignores case, accentation, or locale-specific
+ tailorings; so for example [[=a=]] matches
any of the characters: a, À, Á, Â, Ã, Ä, Å, A, à, á, â, ã, ä and å. Unfortunately implementation
of this is reliant on the platform's collation and localisation support;
this feature can not be relied upon to work portably across all platforms,
or even all locales on one platform.
- \b
- (but only inside a character class declaration).
+ \b (but only inside a character class declaration).
- \cX
+ \cX
@@ -532,7 +639,7 @@
- \xdd
+ \xdd
@@ -545,7 +652,7 @@
- \x{dddd}
+ \x{dddd}
@@ -558,7 +665,7 @@
- \0ddd
+ \0ddd
@@ -571,20 +678,21 @@
- \N{name}
+ \N{name}
Matches the single character which has the symbolic
- namename. For example \N{newline} matches the single character \n.
+ name name. For example \N{newline}
+ matches the single character \n.
- The sequence \G
- matches only at the end of the last match found, or at the start of the text
- being matched if no previous match was found. This escape useful if you're
- iterating over the matches contained within a text, and you want each subsequence
- match to start where the last one ended.
+ The sequence \G matches only at the end of the last match
+ found, or at the start of the text being matched if no previous match was
+ found. This escape useful if you're iterating over the matches contained
+ within a text, and you want each subsequence match to start where the last
+ one ended.
- The escape sequence \Q
- begins a "quoted sequence": all the subsequent characters are treated
- as literals, until either the end of the regular expression or \E is found.
- For example the expression: \Q\*+\Ea+ would match either of:
+ The escape sequence \Q begins a "quoted sequence":
+ all the subsequent characters are treated as literals, until either the end
+ of the regular expression or \E is found. For example the expression: \Q\*+\Ea+
+ would match either of:
- \C
- Matches a single code point: in Boost regex this has exactly the same effect
- as a "." operator. \X Matches a combining character sequence:
- that is any non-combining character followed by a sequence of zero or more
- combining characters.
+ \C Matches a single code point: in Boost regex this has
+ exactly the same effect as a "." operator. \X
+ Matches a combining character sequence: that is any non-combining character
+ followed by a sequence of zero or more combining characters.
+
+ The escape sequence \R matches any line ending character
+ sequence, specifically it is identical to the expression (?>\x0D\x0A?|[\x0A-\x0C\x85\x{2028}\x{2029}]).
+
+ \K Resets the start location of $0 to the current text
+ position: in other words everything to the left of \K is "kept back"
+ and does not form part of the regular expression match. $` is updated accordingly.
+
+
+ For example foo\Kbar matched against the text "foobar"
+ would return the match "bar" for $0 and "foo" for $`.
+ This can be used to simulate variable width lookbehind assertions.
+ Which can be then be refered to by the name NAME. Alternatively
+ you can delimit the name using 'NAME' as in:
+
+
(?'NAME'expression)
+
+
+ These named subexpressions can be refered to in a backreference using either
+ \g{NAME} or \k<NAME> and can
+ also be refered to by name in a Perl
+ format string for search and replace operations, or in the match_results member functions.
- (?imsx-imsx...) alters
- which of the perl modifiers are in effect within the pattern, changes take
- effect from the point that the block is first seen and extend to any enclosing
- ). Letters before a '-' turn
- that perl modifier on, letters afterward, turn it off.
+ (?imsx-imsx ... ) alters which of the perl modifiers are
+ in effect within the pattern, changes take effect from the point that the
+ block is first seen and extend to any enclosing ). Letters
+ before a '-' turn that perl modifier on, letters afterward, turn it off.
- (?imsx-imsx:pattern)
- applies the specified modifiers to pattern only.
+ (?imsx-imsx:pattern) applies the specified modifiers to
+ pattern only.
+ (?|pattern) resets the subexpression count at the start
+ of each "|" alternative within pattern.
+
+
+ The sub-expression count following this construct is that of whichever branch
+ had the largest number of sub-expressions. This construct is useful when
+ you want to capture one of a number of alternative matches in a single sub-expression
+ index.
+
+
+ In the following example the index of each sub-expression is shown below
+ the expression:
+
+
# before ---------------branch-reset----------- after
+/ ( a ) (?| x ( y ) z | (p (q) r) | (t) u (v) ) ( z ) /x
+# 1 2 2 3 2 3 4
+
- (?<=pattern) consumes zero characters, only if pattern
+ (?<=pattern) consumes zero characters, only if pattern
could be matched against the characters preceding the current position (pattern
must be of fixed length).
- (?<!pattern) consumes zero characters, only if pattern
+ (?<!pattern) consumes zero characters, only if pattern
could not be matched against the characters preceding the current position
(pattern must be of fixed length).
- (?>pattern)pattern is matched
+ (?>pattern)pattern is matched
independently of the surrounding patterns, the expression will never backtrack
into pattern. Independent sub-expressions are typically
used to improve performance; only the best possible match for pattern will
be considered, if this doesn't allow the expression as a whole to match then
no match is found at all.
+ (?R) and (?0) recurse to the start
+ of the entire pattern.
+
+
+ (?N) executes sub-expression N
+ recursively, for example (?2) will recurse to sub-expression
+ 2.
+
+
+ (?-N) and (?+N)
+ are relative recursions, so for example (?-1) recurses
+ to the last sub-expression to be declared, and (?+1) recurses
+ to the next sub-expression to be declared.
+
- (?(condition)yes-pattern|no-pattern) attempts to match yes-pattern
- if the condition is true, otherwise attempts to match
- no-pattern.
+ (?(condition)yes-pattern|no-pattern) attempts to match
+ yes-pattern if the condition is
+ true, otherwise attempts to match no-pattern.
- (?(condition)yes-pattern)
- attempts to match yes-pattern if the condition
- is true, otherwise fails.
+ (?(condition)yes-pattern) attempts to match yes-pattern
+ if the condition is true, otherwise fails.
- condition may be either a forward lookahead assert,
- or the index of a marked sub-expression (the condition becomes true if the
- sub-expression has been matched).
+ condition may be either: a forward lookahead assert,
+ the index of a marked sub-expression (the condition becomes true if the sub-expression
+ has been matched), or an index of a recursion (the condition become true
+ if we are executing directly inside the specified recursion).
+
+ Here is a summary of the possible predicates:
+
+
+
+(?(?=assert)yes-pattern|no-pattern) Executes yes-pattern
+ if the forward look-ahead assert matches, otherwise executes no-pattern.
+
+
+(?(?!assert)yes-pattern|no-pattern) Executes yes-pattern
+ if the forward look-ahead assert does not match, otherwise executes no-pattern.
+
+
+(?(R)yes-pattern|no-pattern) Executes yes-pattern
+ if we are executing inside a recursion, otherwise executes no-pattern.
+
+
+(?(RN)yes-pattern|no-pattern) Executes
+ yes-pattern if we are executing inside a recursion
+ to sub-expression N, otherwise executes no-pattern.
+
+
+(?(DEFINE)never-exectuted-pattern) Defines a block of
+ code that is never executed and matches no characters: this is usually
+ used to define one or more named sub-expressions which are refered to from
+ elsewhere in the pattern.
+
There are a variety
- of flags that may be combined with the perl
- option when constructing the regular expression, in particular note that
- the newline_alt option alters
- the syntax, while the collate,
- nosubs and icase options modify how the case and locale
- sensitivity are to be applied.
+ of flags that may be combined with the perl option
+ when constructing the regular expression, in particular note that the newline_alt
+ option alters the syntax, while the collate, nosubs
+ and icase options modify how the case and locale sensitivity
+ are to be applied.
- The perl smix modifiers can
- either be applied using a (?smix-smix) prefix to the regular expression, or with
+ The perl smix modifiers can either be applied using a
+ (?smix-smix) prefix to the regular expression, or with
one of the regex-compile
- time flags no_mod_m, mod_x, mod_s,
- and no_mod_s.
+ time flags no_mod_m, mod_x, mod_s,
+ and no_mod_s.
Distributed under the Boost Software License, Version 1.0. (See accompanying
file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
@@ -196,7 +196,7 @@
-
Last revised: December 23, 2008 at 17:35:37 GMT
+
Last revised: July 29, 2009 at 15:59:46 GMT
diff --git a/doc/match_result.qbk b/doc/match_result.qbk
index eb3861fd..8e1ae788 100644
--- a/doc/match_result.qbk
+++ b/doc/match_result.qbk
@@ -71,9 +71,33 @@ Class template `match_results` is most commonly used as one of the typedefs
bool ``[link boost_regex.match_results.empty empty]``() const;
// element access:
difference_type ``[link boost_regex.match_results.length length]``(int sub = 0) const;
+ difference_type ``[link boost_regex.match_results.length length]``(const char_type* sub) const;
+ template
+ difference_type ``[link boost_regex.match_results.length length]``(const charT* sub) const;
+ template
+ difference_type ``[link boost_regex.match_results.length length]``(const std::basic_string& sub) const;
difference_type ``[link boost_regex.match_results.position position]``(unsigned int sub = 0) const;
+ difference_type ``[link boost_regex.match_results.position position]``(const char_type* sub) const;
+ template
+ difference_type ``[link boost_regex.match_results.position position]``(const charT* sub) const;
+ template
+ difference_type ``[link boost_regex.match_results.position position]``(const std::basic_string& sub) const;
string_type ``[link boost_regex.match_results.str str]``(int sub = 0) const;
+ string_type ``[link boost_regex.match_results.str str]``(const char_type* sub)const;
+ template
+ string_type ``[link boost_regex.match_results.str str]``(const std::basic_string& sub)const;
+ template
+ string_type ``[link boost_regex.match_results.str str]``(const charT* sub)const;
+ template
+ string_type ``[link boost_regex.match_results.str str]``(const std::basic_string& sub)const;
const_reference ``[link boost_regex.match_results.subscript operator\[\]]``(int n) const;
+ const_reference ``[link boost_regex.match_results.subscript operator\[\]]``(const char_type* n) const;
+ template
+ const_reference ``[link boost_regex.match_results.subscript operator\[\]]``(const std::basic_string& n) const;
+ template
+ const_reference ``[link boost_regex.match_results.subscript operator\[\]]``(const charT* n) const;
+ template
+ const_reference ``[link boost_regex.match_results.subscript operator\[\]]``(const std::basic_string& n) const;
const_reference ``[link boost_regex.match_results.prefix prefix]``() const;
@@ -190,30 +214,86 @@ stored in *this.
[#boost_regex.match_results.length]
difference_type length(int sub = 0)const;
+ difference_type length(const char_type* sub)const;
+ template
+ difference_type length(const charT* sub)const;
+ template
+ difference_type length(const std::basic_string&)const;
[*Effects]: Returns the length of sub-expression /sub/, that is to say:
`(*this)[sub].length()`.
+The overloads that accept a string refer to a named sub-expression /n/.
+In the event that there is no such named sub-expression then returns an empty string.
+
+The template overloads of this function, allow the string and\/or character type
+to be different from the character type of the underlying sequence and\/or regular expression:
+in this case the characters will be widened to the underlying character type of the original regular expression.
+A compiler error will occur if the argument passes a wider character type than the underlying sequence.
+These overloads allow a normal narrow character C string literal to be used as an argument, even when
+the underlying character type of the expression being matched may be something more exotic such as a
+Unicode character type.
[#boost_regex.match_results.position]
difference_type position(unsigned int sub = 0)const;
+ difference_type position(const char_type* sub)const;
+ template
+ difference_type position(const charT* sub)const;
+ template
+ difference_type position(const std::basic_string&)const;
[*Effects]: Returns the starting location of sub-expression /sub/, or -1 if /sub/ was
not matched. Note that if this represents a partial match , then `position()`
will return the location of the partial match even though `(*this)[0].matched` is false.
+The overloads that accept a string refer to a named sub-expression /n/.
+In the event that there is no such named sub-expression then returns an empty string.
+
+The template overloads of this function, allow the string and\/or character type
+to be different from the character type of the underlying sequence and\/or regular expression:
+in this case the characters will be widened to the underlying character type of the original regular expression.
+A compiler error will occur if the argument passes a wider character type than the underlying sequence.
+These overloads allow a normal narrow character C string literal to be used as an argument, even when
+the underlying character type of the expression being matched may be something more exotic such as a
+Unicode character type.
+
[#boost_regex.match_results.str]
string_type str(int sub = 0)const;
+ string_type str(const char_type* sub)const;
+ template
+ string_type str(const std::basic_string& sub)const;
+ template
+ string_type str(const charT* sub)const;
+ template
+ string_type str(const std::basic_string& sub)const;
[*Effects]: Returns sub-expression /sub/ as a string: `string_type((*this)[sub])`.
+The overloads that accept a string, return the string that matched the named sub-expression /n/.
+In the event that there is no such named sub-expression then returns an empty string.
+
+The template overloads of this function, allow the string and\/or character type
+to be different from the character type of the underlying sequence and\/or regular expression:
+in this case the characters will be widened to the underlying character type of the original regular expression.
+A compiler error will occur if the argument passes a wider character type than the underlying sequence.
+These overloads allow a normal narrow character C string literal to be used as an argument, even when
+the underlying character type of the expression being matched may be something more exotic such as a
+Unicode character type.
+
[#boost_regex.match_results.subscript]
- const_reference operator[](int n) const;
+ const_reference operator[](int n) const;
+ const_reference operator[](const char_type* n) const;
+ template
+ const_reference operator[](const std::basic_string& n) const;
+ template
+ const_reference operator[](const charT* n) const;
+ template
+ const_reference operator[](const std::basic_string& n) const;
[*Effects]: Returns a reference to the [sub_match] object representing the character
sequence that matched marked sub-expression /n/. If `n == 0` then returns a
@@ -222,6 +302,19 @@ matched the whole regular expression. If /n/ is out of range, or if /n/ is an
unmatched sub-expression, then returns a [sub_match] object whose matched
member is false.
+The overloads that accept a string, return a reference to the [sub_match]
+object representing the character sequence that matched the named sub-expression /n/.
+In the event that there is no such named sub-expression then returns a [sub_match] object whose matched
+member is false.
+
+The template overloads of this function, allow the string and\/or character type
+to be different from the character type of the underlying sequence and\/or regular expression:
+in this case the characters will be widened to the underlying character type of the original regular expression.
+A compiler error will occur if the argument passes a wider character type than the underlying sequence.
+These overloads allow a normal narrow character C string literal to be used as an argument, even when
+the underlying character type of the expression being matched may be something more exotic such as a
+Unicode character type.
+
[#boost_regex.match_results.prefix]
diff --git a/doc/syntax_perl.qbk b/doc/syntax_perl.qbk
index 9a76276d..716df83c 100644
--- a/doc/syntax_perl.qbk
+++ b/doc/syntax_perl.qbk
@@ -12,7 +12,7 @@
The Perl regular expression syntax is based on that used by the
programming language Perl . Perl regular expressions are the
-default behavior in Boost.Regex or you can pass the flag `perl` to the
+default behavior in Boost.Regex or you can pass the flag =perl= to the
[basic_regex] constructor, for example:
// e1 is a case sensitive Perl regular expression:
@@ -34,9 +34,9 @@ The single character '.' when used outside of a character set will match
any single character except:
* The NULL character when the [link boost_regex.ref.match_flag_type flag
- `match_not_dot_null`] is passed to the matching algorithms.
+ =match_not_dot_null=] is passed to the matching algorithms.
* The newline character when the [link boost_regex.ref.match_flag_type
- flag `match_not_dot_newline`] is passed to
+ flag =match_not_dot_newline=] is passed to
the matching algorithms.
[h4 Anchors]
@@ -47,7 +47,7 @@ A '$' character shall match the end of a line.
[h4 Marked sub-expressions]
-A section beginning `(` and ending `)` acts as a marked sub-expression.
+A section beginning =(= and ending =)= acts as a marked sub-expression.
Whatever matched the sub-expression is split out in a separate field by
the matching algorithms. Marked sub-expressions can also repeated, or
referred to by a back-reference.
@@ -58,23 +58,23 @@ A marked sub-expression is useful to lexically group part of a regular
expression, but has the side-effect of spitting out an extra field in
the result. As an alternative you can lexically group part of a
regular expression, without generating a marked sub-expression by using
-`(?:` and `)` , for example `(?:ab)+` will repeat `ab` without splitting
+=(?:= and =)= , for example =(?:ab)+= will repeat =ab= without splitting
out any separate sub-expressions.
[h4 Repeats]
Any atom (a single character, a marked sub-expression, or a character class)
-can be repeated with the `*`, `+`, `?`, and `{}` operators.
+can be repeated with the =*=, =+=, =?=, and ={}= operators.
-The `*` operator will match the preceding atom zero or more times,
-for example the expression `a*b` will match any of the following:
+The =*= operator will match the preceding atom zero or more times,
+for example the expression =a*b= will match any of the following:
b
ab
aaaaaaaab
-The `+` operator will match the preceding atom one or more times, for
-example the expression `a+b` will match any of the following:
+The =+= operator will match the preceding atom one or more times, for
+example the expression =a+b= will match any of the following:
ab
aaaaaaaab
@@ -83,7 +83,7 @@ But will not match:
b
-The `?` operator will match the preceding atom zero or one times, for
+The =?= operator will match the preceding atom zero or one times, for
example the expression ca?b will match any of the following:
cb
@@ -95,11 +95,11 @@ But will not match:
An atom can also be repeated with a bounded repeat:
-`a{n}` Matches 'a' repeated exactly n times.
+=a{n}= Matches 'a' repeated exactly n times.
-`a{n,}` Matches 'a' repeated n or more times.
+=a{n,}= Matches 'a' repeated n or more times.
-`a{n, m}` Matches 'a' repeated between n and m times inclusive.
+=a{n, m}= Matches 'a' repeated between n and m times inclusive.
For example:
@@ -120,7 +120,7 @@ be repeated, for example:
a(*)
-Will raise an error, as there is nothing for the `*` operator to be applied to.
+Will raise an error, as there is nothing for the =*= operator to be applied to.
[h4 Non greedy repeats]
@@ -128,21 +128,38 @@ The normal repeat operators are "greedy", that is to say they will consume as
much input as possible. There are non-greedy versions available that will
consume as little input as possible while still producing a match.
-`*?` Matches the previous atom zero or more times, while consuming as little
+=*?= Matches the previous atom zero or more times, while consuming as little
input as possible.
-`+?` Matches the previous atom one or more times, while consuming as
+=+?= Matches the previous atom one or more times, while consuming as
little input as possible.
-`??` Matches the previous atom zero or one times, while consuming
+=??= Matches the previous atom zero or one times, while consuming
as little input as possible.
-`{n,}?` Matches the previous atom n or more times, while consuming as
+={n,}?= Matches the previous atom n or more times, while consuming as
little input as possible.
-`{n,m}?` Matches the previous atom between n and m times, while
+={n,m}?= Matches the previous atom between n and m times, while
consuming as little input as possible.
+[h4 Pocessive repeats]
+
+By default when a repeated patten does not match then the engine will backtrack until
+a match is found. However, this behaviour can sometime be undesireable so there are
+also "pocessive" repeats: these match as much as possible and do not then allow
+backtracking if the rest of the expression fails to match.
+
+=*+= Matches the previous atom zero or more times, while giving nothing back.
+
+=++= Matches the previous atom one or more times, while giving nothing back.
+
+=?+= Matches the previous atom zero or one times, while giving nothing back.
+
+={n,}+= Matches the previous atom n or more times, while giving nothing back.
+
+={n,m}+= Matches the previous atom between n and m times, while giving nothing back.
+
[h4 Back references]
An escape character followed by a digit /n/, where /n/ is in the range 1-9,
@@ -158,27 +175,42 @@ Will match the string:
But not the string:
aaabba
+
+You can also use the \g escape for the same function, for example:
+
+[table
+[[Escape][Meaning]]
+[[=\g1=][Match whatever matched sub-expression 1]]
+[[=\g{1}=][Match whatever matched sub-expression 1: this form allows for safer
+ parsing of the expression in cases like =\g{1}2= or for indexes higher than 9 as in =\g{1234}=]]
+[[=\g-1=][Match whatever matched the last opened sub-expression]]
+[[=\g{-2}=][Match whatever matched the last but one opened sub-expression]]
+[[=\g{one}=][Match whatever matched the sub-expression named "one"]]
+]
+
+Finally the \k escape can be used to refer to named subexpressions, for example [^\k] will match
+whatever matched the subexpression named "two".
[h4 Alternation]
-The `|` operator will match either of its arguments, so for example:
-`abc|def` will match either "abc" or "def".
+The =|= operator will match either of its arguments, so for example:
+=abc|def= will match either "abc" or "def".
-Parenthesis can be used to group alternations, for example: `ab(d|ef)`
+Parenthesis can be used to group alternations, for example: =ab(d|ef)=
will match either of "abd" or "abef".
Empty alternatives are not allowed (these are almost always a mistake), but
-if you really want an empty alternative use `(?:)` as a placeholder, for example:
+if you really want an empty alternative use =(?:)= as a placeholder, for example:
-`|abc` is not a valid expression, but
+=|abc= is not a valid expression, but
-`(?:)|abc` is and is equivalent, also the expression:
+=(?:)|abc= is and is equivalent, also the expression:
-`(?:abc)??` has exactly the same effect.
+=(?:abc)??= has exactly the same effect.
[h4 Character sets]
-A character set is a bracket-expression starting with `[` and ending with `]`,
+A character set is a bracket-expression starting with =[= and ending with =]=,
it defines a set of characters, and matches any single character that is a
member of that set.
@@ -186,35 +218,35 @@ A bracket expression may contain any combination of the following:
[h5 Single characters]
-For example `[abc]`, will match any of the characters 'a', 'b', or 'c'.
+For example =[abc]=, will match any of the characters 'a', 'b', or 'c'.
[h5 Character ranges]
-For example `[a-c]` will match any single character in the range 'a' to 'c'.
+For example =[a-c]= will match any single character in the range 'a' to 'c'.
By default, for Perl regular expressions, a character x is within the
range y to z, if the code point of the character lies within the codepoints of
the endpoints of the range. Alternatively, if you set the
-[link boost_regex.ref.syntax_option_type.syntax_option_type_perl `collate` flag]
+[link boost_regex.ref.syntax_option_type.syntax_option_type_perl =collate= flag]
when constructing the regular expression, then ranges are locale sensitive.
[h5 Negation]
If the bracket-expression begins with the ^ character, then it matches the
-complement of the characters it contains, for example `[^a-c]` matches
-any character that is not in the range `a-c`.
+complement of the characters it contains, for example =[^a-c]= matches
+any character that is not in the range =a-c=.
[h5 Character classes]
-An expression of the form `[[:name:]]` matches the named character class
-"name", for example `[[:lower:]]` matches any lower case character.
+An expression of the form [^\[\[:name:\]\]] matches the named character class
+"name", for example [^\[\[:lower:\]\]] matches any lower case character.
See [link boost_regex.syntax.character_classes character class names].
[h5 Collating Elements]
-An expression of the form `[[.col.]` matches the collating element /col/.
+An expression of the form [^\[\[.col.\]\]] matches the collating element /col/.
A collating element is any single character, or any sequence of characters
that collates as a single unit. Collating elements may also be used
-as the end point of a range, for example: `[[.ae.]-c]` matches the
+as the end point of a range, for example: [^\[\[.ae.\]-c\]] matches the
character sequence "ae", plus any single character in the range "ae"-c,
assuming that "ae" is treated as a single collating element in the current locale.
@@ -223,11 +255,11 @@ As an extension, a collating element may also be specified via it's
[[.NUL.]]
-matches a `\0` character.
+matches a =\0= character.
[h5 Equivalence classes]
-An expression of the form `[[=col=]]`, matches any character or collating element
+An expression of the form [^\[\[\=col\=\]\]], matches any character or collating element
whose primary sort key is the same as that for collating element /col/, as with
collating elements the name /col/ may be a
[link boost_regex.syntax.collating_names symbolic name]. A primary sort key is
@@ -250,7 +282,7 @@ that is either a "digit", /or/ is /not/ a "word" character.
[h5 Combinations]
All of the above can be combined in one character set declaration, for example:
-`[[:digit:]a-c[.NUL.]]`.
+[^\[\[:digit:\]a-c\[.NUL.\]\]].
[h4 Escapes]
@@ -260,24 +292,24 @@ The following escape sequences are all synonyms for single characters:
[table
[[Escape][Character]]
-[[`\a`][`\a`]]
-[[`\e`][`0x1B`]]
-[[`\f`][`\f`]]
-[[`\n`][`\n`]]
-[[`\r`][`\r`]]
-[[`\t`][`\t`]]
-[[`\v `][`\v`]]
-[[`\b`][`\b` (but only inside a character class declaration).]]
-[[`\cX`][An ASCII escape sequence - the character whose code point is X % 32]]
-[[`\xdd`][A hexadecimal escape sequence - matches the single character whose
+[[=\a=][=\a=]]
+[[=\e=][=0x1B=]]
+[[=\f=][=\f=]]
+[[=\n=][=\n=]]
+[[=\r=][=\r=]]
+[[=\t=][=\t=]]
+[[=\v=][=\v=]]
+[[=\b=][=\b= (but only inside a character class declaration).]]
+[[=\cX=][An ASCII escape sequence - the character whose code point is X % 32]]
+[[=\xdd=][A hexadecimal escape sequence - matches the single character whose
code point is 0xdd.]]
-[[`\x{dddd}`][A hexadecimal escape sequence - matches the single character whose
+[[=\x{dddd}=][A hexadecimal escape sequence - matches the single character whose
code point is 0xdddd.]]
-[[`\0ddd`][An octal escape sequence - matches the single character whose
+[[=\0ddd=][An octal escape sequence - matches the single character whose
code point is 0ddd.]]
-[[`\N{name}`][Matches the single character which has the
+[[=\N{name}=][Matches the single character which has the
[link boost_regex.syntax.collating_names symbolic name] /name/.
- For example `\N{newline}` matches the single character \\n.]]
+ For example =\N{newline}= matches the single character \\n.]]
]
[h5 "Single character" character classes:]
@@ -296,11 +328,15 @@ The following are supported by default:
[[`\s`][`[[:space:]]`]]
[[`\u`][`[[:upper:]]`]]
[[`\w`][`[[:word:]]`]]
+[[`\h`][Horizontal whitespace]]
+[[`\v`][Vertical whitespace]]
[[`\D`][`[^[:digit:]]`]]
[[`\L`][`[^[:lower:]]`]]
[[`\S`][`[^[:space:]]`]]
[[`\U`][`[^[:upper:]]`]]
[[`\W`][`[^[:word:]]`]]
+[[`\H`][Not Horizontal whitespace]]
+[[`\V`][Not Vertical whitespace]]
]
[h5 Character Properties]
@@ -316,19 +352,19 @@ to the [link boost_regex.syntax.character_classes names used in character classe
[[`\P{Name}`][Matches any character that does not have the property Name.][`[^[:Name:]]`]]
]
-For example `\pd` matches any "digit" character, as does `\p{digit}`.
+For example =\pd= matches any "digit" character, as does =\p{digit}=.
[h5 Word Boundaries]
The following escape sequences match the boundaries of words:
-`\<` Matches the start of a word.
+=\<= Matches the start of a word.
-`\>` Matches the end of a word.
+=\>= Matches the end of a word.
-`\b` Matches a word boundary (the start or end of a word).
+=\b= Matches a word boundary (the start or end of a word).
-`\B` Matches only when not at a word boundary.
+=\B= Matches only when not at a word boundary.
[h5 Buffer boundaries]
@@ -345,30 +381,44 @@ context is the whole of the input text that is being matched against
\\z Matches at the end of a buffer only (the same as \\').
\\Z Matches an optional sequence of newlines at the end of a buffer:
-equivalent to the regular expression `\n*\z`
+equivalent to the regular expression =\n*\z=
[h5 Continuation Escape]
-The sequence `\G` matches only at the end of the last match found, or at
+The sequence =\G= matches only at the end of the last match found, or at
the start of the text being matched if no previous match was found.
This escape useful if you're iterating over the matches contained within a
text, and you want each subsequence match to start where the last one ended.
[h5 Quoting escape]
-The escape sequence `\Q` begins a "quoted sequence": all the subsequent characters
+The escape sequence =\Q= begins a "quoted sequence": all the subsequent characters
are treated as literals, until either the end of the regular expression or \\E
-is found. For example the expression: `\Q\*+\Ea+` would match either of:
+is found. For example the expression: =\Q\*+\Ea+= would match either of:
\*+a
\*+aaa
[h5 Unicode escapes]
-`\C` Matches a single code point: in Boost regex this has exactly the
+=\C= Matches a single code point: in Boost regex this has exactly the
same effect as a "." operator.
-`\X` Matches a combining character sequence: that is any non-combining
+=\X= Matches a combining character sequence: that is any non-combining
character followed by a sequence of zero or more combining characters.
+
+[h5 Matching Line Endings]
+
+The escape sequence =\R= matches any line ending character sequence, specifically it is identical to
+the expression [^(?>\x0D\x0A?|\[\x0A-\x0C\x85\x{2028}\x{2029}\])].
+
+[h5 Keeping back some text]
+
+=\K= Resets the start location of $0 to the current text position: in other words everything to the
+left of \K is "kept back" and does not form part of the regular expression match. $` is updated
+accordingly.
+
+For example =foo\Kbar= matched against the text "foobar" would return the match "bar" for $0 and "foo"
+for $`. This can be used to simulate variable width lookbehind assertions.
[h5 Any other escape]
@@ -377,31 +427,62 @@ Any other escape sequence matches the character that is escaped, for example
[h4 Perl Extended Patterns]
-Perl-specific extensions to the regular expression syntax all start with `(?`.
+Perl-specific extensions to the regular expression syntax all start with =(?=.
+[h5 Named Subexpressions]
+
+You can create a named subexpression using:
+
+ (?expression)
+
+Which can be then be refered to by the name /NAME/. Alternatively you can delimit the name
+using 'NAME' as in:
+
+ (?'NAME'expression)
+
+These named subexpressions can be refered to in a backreference using either [^\g{NAME}] or [^\k]
+and can also be refered to by name in a [perl_format] format string for search and replace operations, or in the
+[match_results] member functions.
+
[h5 Comments]
-`(?# ... )` is treated as a comment, it's contents are ignored.
+=(?# ... )= is treated as a comment, it's contents are ignored.
[h5 Modifiers]
-`(?imsx-imsx ... )` alters which of the perl modifiers are in effect within
+=(?imsx-imsx ... )= alters which of the perl modifiers are in effect within
the pattern, changes take effect from the point that the block is first seen
-and extend to any enclosing `)`. Letters before a '-' turn that perl
+and extend to any enclosing =)=. Letters before a '-' turn that perl
modifier on, letters afterward, turn it off.
-`(?imsx-imsx:pattern)` applies the specified modifiers to pattern only.
+=(?imsx-imsx:pattern)= applies the specified modifiers to pattern only.
[h5 Non-marking groups]
-`(?:pattern)` lexically groups pattern, without generating an additional
+=(?:pattern)= lexically groups pattern, without generating an additional
sub-expression.
+[h5 Branch reset]
+
+=(?|pattern)= resets the subexpression count at the start of each "|" alternative within /pattern/.
+
+The sub-expression count following this construct is that of whichever branch had the largest number of
+sub-expressions. This construct is useful when you want to capture one of a number of alternative matches
+in a single sub-expression index.
+
+In the following example the index of each sub-expression is shown below the expression:
+
+[pre
+# before ---------------branch-reset----------- after
+/ ( a ) (?| x ( y ) z | (p (q) r) | (t) u (v) ) ( z ) /x
+# 1 2 2 3 2 3 4
+]
+
[h5 Lookahead]
-`(?=pattern)` consumes zero characters, only if pattern matches.
+[^(?=pattern)] consumes zero characters, only if pattern matches.
-`(?!pattern)` consumes zero characters, only if pattern does not match.
+=(?!pattern)= consumes zero characters, only if pattern does not match.
Lookahead is typically used to create the logical AND of two regular
expressions, for example if a password must contain a lower case letter,
@@ -414,43 +495,68 @@ could be used to validate the password.
[h5 Lookbehind]
-`(?<=pattern)` consumes zero characters, only if pattern could be matched
+[^(?<=pattern)] consumes zero characters, only if pattern could be matched
against the characters preceding the current position (pattern must be
of fixed length).
-`(?pattern)` /pattern/ is matched independently of the surrounding patterns,
+=(?>pattern)= /pattern/ is matched independently of the surrounding patterns,
the expression will never backtrack into /pattern/. Independent sub-expressions
are typically used to improve performance; only the best possible match
for pattern will be considered, if this doesn't allow the expression as a
whole to match then no match is found at all.
+[h5 Recursive Expressions]
+
+[^(?['N]) (?-['N]) (?+['N]) (?R) (?0)]
+
+=(?R)= and =(?0)= recurse to the start of the entire pattern.
+
+[^(?['N])] executes sub-expression /N/ recursively, for example =(?2)= will recurse to sub-expression 2.
+
+[^(?-['N])] and [^(?+['N])] are relative recursions, so for example =(?-1)= recurses to the last sub-expression to be declared,
+and =(?+1)= recurses to the next sub-expression to be declared.
+
[h5 Conditional Expressions]
-`(?(condition)yes-pattern|no-pattern)` attempts to match /yes-pattern/ if
+=(?(condition)yes-pattern|no-pattern)= attempts to match /yes-pattern/ if
the /condition/ is true, otherwise attempts to match /no-pattern/.
-`(?(condition)yes-pattern)` attempts to match /yes-pattern/ if the /condition/
+=(?(condition)yes-pattern)= attempts to match /yes-pattern/ if the /condition/
is true, otherwise fails.
-/condition/ may be either a forward lookahead assert, or the index of
+/condition/ may be either: a forward lookahead assert, the index of
a marked sub-expression (the condition becomes true if the sub-expression
-has been matched).
+has been matched), or an index of a recursion (the condition become true if we are executing
+directly inside the specified recursion).
+
+Here is a summary of the possible predicates:
+
+* [^(?(?\=assert)yes-pattern|no-pattern)] Executes /yes-pattern/ if the forward look-ahead assert matches, otherwise
+executes /no-pattern/.
+* =(?(?!assert)yes-pattern|no-pattern)= Executes /yes-pattern/ if the forward look-ahead assert does not match, otherwise
+executes /no-pattern/.
+* =(?(R)yes-pattern|no-pattern)= Executes /yes-pattern/ if we are executing inside a recursion, otherwise
+executes /no-pattern/.
+* [^(?(R['N])yes-pattern|no-pattern)] Executes /yes-pattern/ if we are executing inside a recursion to sub-expression /N/, otherwise
+executes /no-pattern/.
+* [^(?(DEFINE)never-exectuted-pattern)] Defines a block of code that is never executed and matches no characters:
+this is usually used to define one or more named sub-expressions which are refered to from elsewhere in the pattern.
[h4 Operator precedence]
The order of precedence for of operators is as follows:
# Collation-related bracket symbols `[==] [::] [..]`
-# Escaped characters `\`
+# Escaped characters =\=
# Character set (bracket expression) `[]`
-# Grouping `()`
-# Single-character-ERE duplication `* + ? {m,n}`
+# Grouping =()=
+# Single-character-ERE duplication =* + ? {m,n}=
# Concatenation
# Anchoring ^$
# Alternation |
@@ -469,42 +575,42 @@ with individual elements matched as follows;
[table
[[Construct][What gets matched]]
-[[`AtomA AtomB`][Locates the best match for /AtomA/ that has a following match for /AtomB/.]]
-[[`Expression1 | Expression2`][If /Expresion1/ can be matched then returns that match,
+[[=AtomA AtomB=][Locates the best match for /AtomA/ that has a following match for /AtomB/.]]
+[[=Expression1 | Expression2=][If /Expresion1/ can be matched then returns that match,
otherwise attempts to match /Expression2/.]]
-[[`S{N}`][Matches /S/ repeated exactly N times.]]
-[[`S{N,M}`][Matches S repeated between N and M times, and as many times as possible.]]
-[[`S{N,M}?`][Matches S repeated between N and M times, and as few times as possible.]]
-[[`S?, S*, S+`][The same as `S{0,1}`, `S{0,UINT_MAX}`, `S{1,UINT_MAX}` respectively.]]
-[[`S??, S*?, S+?`][The same as `S{0,1}?`, `S{0,UINT_MAX}?`, `S{1,UINT_MAX}?` respectively.]]
-[[`(?>S)`][Matches the best match for /S/, and only that.]]
-[[`(?=S), (?<=S)`][Matches only the best match for /S/ (this is only
+[[=S{N}=][Matches /S/ repeated exactly N times.]]
+[[=S{N,M}=][Matches S repeated between N and M times, and as many times as possible.]]
+[[=S{N,M}?=][Matches S repeated between N and M times, and as few times as possible.]]
+[[=S?, S*, S+=][The same as =S{0,1}=, =S{0,UINT_MAX}=, =S{1,UINT_MAX}= respectively.]]
+[[=S??, S*?, S+?=][The same as =S{0,1}?=, =S{0,UINT_MAX}?=, =S{1,UINT_MAX}?= respectively.]]
+[[=(?>S)=][Matches the best match for /S/, and only that.]]
+[[[^(?=S), (?<=S)]][Matches only the best match for /S/ (this is only
visible if there are capturing parenthesis within /S/).]]
-[[`(?!S), (?
extern template class __declspec(dllimport) std::basic_string;
# endif
diff --git a/include/boost/regex/icu.hpp b/include/boost/regex/icu.hpp
index 7af1d678..24715572 100644
--- a/include/boost/regex/icu.hpp
+++ b/include/boost/regex/icu.hpp
@@ -184,7 +184,9 @@ private:
offset_underscore = U_CHAR_CATEGORY_COUNT+3,
offset_unicode = U_CHAR_CATEGORY_COUNT+4,
offset_any = U_CHAR_CATEGORY_COUNT+5,
- offset_ascii = U_CHAR_CATEGORY_COUNT+6
+ offset_ascii = U_CHAR_CATEGORY_COUNT+6,
+ offset_horizontal = U_CHAR_CATEGORY_COUNT+7,
+ offset_vertical = U_CHAR_CATEGORY_COUNT+8
};
//
@@ -197,6 +199,8 @@ private:
static const char_class_type mask_unicode;
static const char_class_type mask_any;
static const char_class_type mask_ascii;
+ static const char_class_type mask_horizontal;
+ static const char_class_type mask_vertical;
static char_class_type lookup_icu_mask(const ::UChar32* p1, const ::UChar32* p2);
@@ -311,12 +315,12 @@ inline u32regex do_make_u32regex(InputIterator i,
boost::regex_constants::syntax_option_type opt,
const boost::mpl::int_<4>*)
{
- typedef std::vector vector_type;
+ typedef std::vector vector_type;
vector_type v;
while(i != j)
{
- v.push_back((UCHAR32)(*i));
- ++a;
+ v.push_back((UChar32)(*i));
+ ++i;
}
if(v.size())
return u32regex(&*v.begin(), v.size(), opt);
diff --git a/include/boost/regex/v4/basic_regex.hpp b/include/boost/regex/v4/basic_regex.hpp
index cb9ff3c5..09b0467b 100644
--- a/include/boost/regex/v4/basic_regex.hpp
+++ b/include/boost/regex/v4/basic_regex.hpp
@@ -19,6 +19,9 @@
#ifndef BOOST_REGEX_V4_BASIC_REGEX_HPP
#define BOOST_REGEX_V4_BASIC_REGEX_HPP
+#include
+#include
+
#ifdef BOOST_MSVC
#pragma warning(push)
#pragma warning(disable: 4103)
@@ -44,12 +47,160 @@ namespace re_detail{
template
class basic_regex_parser;
+template
+void bubble_down_one(I first, I last)
+{
+ if(first != last)
+ {
+ I next = last - 1;
+ while((next != first) && !(*(next-1) < *next))
+ {
+ (next-1)->swap(*next);
+ --next;
+ }
+ }
+}
+
+//
+// Class named_subexpressions
+// Contains information about named subexpressions within the regex.
+//
+template
+class named_subexpressions_base
+{
+public:
+ virtual int get_id(const charT* i, const charT* j)const = 0;
+ virtual int get_id(std::size_t hash)const = 0;
+#ifdef __GNUC__
+ // warning supression:
+ virtual ~named_subexpressions_base(){}
+#endif
+};
+
+template
+inline std::size_t hash_value_from_capture_name(Iterator i, Iterator j)
+{
+ std::size_t r = boost::hash_range(i, j);
+ r %= ((std::numeric_limits::max)() - 10001);
+ r += 10000;
+ return r;
+}
+
+template
+class named_subexpressions : public named_subexpressions_base
+{
+ struct name
+ {
+ name(const charT* i, const charT* j, int idx)
+ : /*n(i, j), */ index(idx)
+ {
+ hash = hash_value_from_capture_name(i, j);
+ }
+ name(std::size_t h, int idx)
+ : index(idx), hash(h)
+ {
+ }
+ //std::vector n;
+ int index;
+ std::size_t hash;
+ bool operator < (const name& other)const
+ {
+ return hash < other.hash; //std::lexicographical_compare(n.begin(), n.end(), other.n.begin(), other.n.end());
+ }
+ bool operator == (const name& other)const
+ {
+ return hash == other.hash; //n == other.n;
+ }
+ void swap(name& other)
+ {
+ //n.swap(other.n);
+ std::swap(index, other.index);
+ std::swap(hash, other.hash);
+ }
+ };
+public:
+ named_subexpressions(){}
+ void set_name(const charT* i, const charT* j, int index)
+ {
+ m_sub_names.push_back(name(i, j, index));
+ bubble_down_one(m_sub_names.begin(), m_sub_names.end());
+ }
+ int get_id(const charT* i, const charT* j)const
+ {
+ name t(i, j, 0);
+ typename std::vector::const_iterator pos = std::lower_bound(m_sub_names.begin(), m_sub_names.end(), t);
+ if((pos != m_sub_names.end()) && (*pos == t))
+ {
+ return pos->index;
+ }
+ return -1;
+ }
+ int get_id(std::size_t h)const
+ {
+ name t(h, 0);
+ typename std::vector::const_iterator pos = std::lower_bound(m_sub_names.begin(), m_sub_names.end(), t);
+ if((pos != m_sub_names.end()) && (*pos == t))
+ {
+ return pos->index;
+ }
+ return -1;
+ }
+private:
+ std::vector m_sub_names;
+};
+
+template
+class named_subexpressions_converter : public named_subexpressions_base
+{
+ boost::shared_ptr > m_converter;
+public:
+ named_subexpressions_converter(boost::shared_ptr > s)
+ : m_converter(s) {}
+ int get_id(const charT* i, const charT* j)const
+ {
+ if(i == j)
+ return -1;
+ std::vector v;
+ while(i != j)
+ {
+ v.push_back(*i);
+ ++i;
+ }
+ return m_converter->get_id(&v[0], &v[0] + v.size());
+ }
+ int get_id(std::size_t h)const
+ {
+ return m_converter->get_id(h);
+ }
+};
+
+template
+inline boost::shared_ptr > convert_to_named_subs_imp(
+ boost::shared_ptr > s,
+ boost::integral_constant const&)
+{
+ return s;
+}
+template
+inline boost::shared_ptr > convert_to_named_subs_imp(
+ boost::shared_ptr > s,
+ boost::integral_constant const&)
+{
+ return boost::shared_ptr >(new named_subexpressions_converter(s));
+}
+template
+inline boost::shared_ptr > convert_to_named_subs(
+ boost::shared_ptr > s)
+{
+ typedef typename boost::is_same::type tag_type;
+ return convert_to_named_subs_imp(s, tag_type());
+}
//
// class regex_data:
// represents the data we wish to expose to the matching algorithms.
//
template
-struct regex_data
+struct regex_data : public named_subexpressions
{
typedef regex_constants::syntax_option_type flag_type;
typedef std::size_t size_type;
@@ -77,6 +228,7 @@ struct regex_data
std::vector<
std::pair<
std::size_t, std::size_t> > m_subs; // Position of sub-expressions within the *string*.
+ bool m_has_recursions; // whether we have recursive expressions;
};
//
// class basic_regex_implementation
@@ -520,6 +672,10 @@ public:
BOOST_ASSERT(0 != m_pimpl.get());
return m_pimpl->get_data();
}
+ boost::shared_ptr > get_named_subs()const
+ {
+ return m_pimpl;
+ }
private:
shared_ptr > m_pimpl;
diff --git a/include/boost/regex/v4/basic_regex_creator.hpp b/include/boost/regex/v4/basic_regex_creator.hpp
index 9f2cbeec..6f005054 100644
--- a/include/boost/regex/v4/basic_regex_creator.hpp
+++ b/include/boost/regex/v4/basic_regex_creator.hpp
@@ -240,6 +240,7 @@ protected:
bool m_has_backrefs; // true if there are actually any backrefs
unsigned m_backrefs; // bitmask of permitted backrefs
boost::uintmax_t m_bad_repeats; // bitmask of repeats we can't deduce a startmap for;
+ bool m_has_recursions; // set when we have recursive expresisons to fixup
typename traits::char_class_type m_word_mask; // mask used to determine if a character is a word character
typename traits::char_class_type m_mask_space; // mask used to determine if a character is a word character
typename traits::char_class_type m_lower_mask; // mask used to determine if a character is a lowercase character
@@ -250,6 +251,7 @@ private:
basic_regex_creator(const basic_regex_creator&);
void fixup_pointers(re_syntax_base* state);
+ void fixup_recursions(re_syntax_base* state);
void create_startmaps(re_syntax_base* state);
int calculate_backstep(re_syntax_base* state);
void create_startmap(re_syntax_base* state, unsigned char* l_map, unsigned int* pnull, unsigned char mask);
@@ -263,7 +265,7 @@ private:
template
basic_regex_creator::basic_regex_creator(regex_data* data)
- : m_pdata(data), m_traits(*(data->m_ptraits)), m_last_state(0), m_repeater_id(0), m_has_backrefs(false), m_backrefs(0)
+ : m_pdata(data), m_traits(*(data->m_ptraits)), m_last_state(0), m_repeater_id(0), m_has_backrefs(false), m_backrefs(0), m_has_recursions(false)
{
m_pdata->m_data.clear();
m_pdata->m_status = ::boost::regex_constants::error_ok;
@@ -692,6 +694,13 @@ void basic_regex_creator::finalize(const charT* p1, const charT*
m_pdata->m_first_state = static_cast(m_pdata->m_data.data());
// fixup pointers in the machine:
fixup_pointers(m_pdata->m_first_state);
+ if(m_has_recursions)
+ {
+ m_pdata->m_has_recursions = true;
+ fixup_recursions(m_pdata->m_first_state);
+ }
+ else
+ m_pdata->m_has_recursions = false;
// create nested startmaps:
create_startmaps(m_pdata->m_first_state);
// create main startmap:
@@ -713,6 +722,13 @@ void basic_regex_creator::fixup_pointers(re_syntax_base* state)
{
switch(state->type)
{
+ case syntax_element_recurse:
+ m_has_recursions = true;
+ if(state->next.i)
+ state->next.p = getaddress(state->next.i, state);
+ else
+ state->next.p = 0;
+ break;
case syntax_element_rep:
case syntax_element_dot_rep:
case syntax_element_char_rep:
@@ -738,6 +754,93 @@ void basic_regex_creator::fixup_pointers(re_syntax_base* state)
}
}
+template
+void basic_regex_creator::fixup_recursions(re_syntax_base* state)
+{
+ re_syntax_base* base = state;
+ while(state)
+ {
+ switch(state->type)
+ {
+ case syntax_element_assert_backref:
+ {
+ // just check that the index is valid:
+ int id = static_cast(state)->index;
+ if(id < 0)
+ {
+ id = -id-1;
+ if(id >= 10000)
+ {
+ id = m_pdata->get_id(id);
+ if(id <= 0)
+ {
+ // check of sub-expression that doesn't exist:
+ if(0 == this->m_pdata->m_status) // update the error code if not already set
+ this->m_pdata->m_status = boost::regex_constants::error_bad_pattern;
+ //
+ // clear the expression, we should be empty:
+ //
+ this->m_pdata->m_expression = 0;
+ this->m_pdata->m_expression_len = 0;
+ //
+ // and throw if required:
+ //
+ if(0 == (this->flags() & regex_constants::no_except))
+ {
+ std::string message = this->m_pdata->m_ptraits->error_string(boost::regex_constants::error_bad_pattern);
+ boost::regex_error e(message, boost::regex_constants::error_bad_pattern, 0);
+ e.raise();
+ }
+ }
+ }
+ }
+ }
+ break;
+ case syntax_element_recurse:
+ {
+ bool ok = false;
+ re_syntax_base* p = base;
+ int id = static_cast(state)->alt.i;
+ if(id > 10000)
+ id = m_pdata->get_id(id);
+ while(p)
+ {
+ if((p->type == syntax_element_startmark) && (static_cast(p)->index == id))
+ {
+ static_cast(state)->alt.p = p;
+ ok = true;
+ break;
+ }
+ p = p->next.p;
+ }
+ if(!ok)
+ {
+ // recursion to sub-expression that doesn't exist:
+ if(0 == this->m_pdata->m_status) // update the error code if not already set
+ this->m_pdata->m_status = boost::regex_constants::error_bad_pattern;
+ //
+ // clear the expression, we should be empty:
+ //
+ this->m_pdata->m_expression = 0;
+ this->m_pdata->m_expression_len = 0;
+ //
+ // and throw if required:
+ //
+ if(0 == (this->flags() & regex_constants::no_except))
+ {
+ std::string message = this->m_pdata->m_ptraits->error_string(boost::regex_constants::error_bad_pattern);
+ boost::regex_error e(message, boost::regex_constants::error_bad_pattern, 0);
+ e.raise();
+ }
+ }
+ }
+ default:
+ break;
+ }
+ state = state->next.p;
+ }
+}
+
template
void basic_regex_creator::create_startmaps(re_syntax_base* state)
{
@@ -953,6 +1056,7 @@ void basic_regex_creator::create_startmap(re_syntax_base* state,
create_startmap(state->next.p, 0, pnull, mask);
return;
}
+ case syntax_element_recurse:
case syntax_element_backref:
// can be null, and any character can match:
if(pnull)
diff --git a/include/boost/regex/v4/basic_regex_parser.hpp b/include/boost/regex/v4/basic_regex_parser.hpp
index b8bc9963..7d2f5543 100644
--- a/include/boost/regex/v4/basic_regex_parser.hpp
+++ b/include/boost/regex/v4/basic_regex_parser.hpp
@@ -78,6 +78,8 @@ private:
const charT* m_end; // the end of the string being parsed
const charT* m_position; // our current parser position
unsigned m_mark_count; // how many sub-expressions we have
+ int m_mark_reset; // used to indicate that we're inside a (?|...) block.
+ unsigned m_max_mark; // largest mark count seen inside a (?|...) block.
std::ptrdiff_t m_paren_start; // where the last seen ')' began (where repeats are inserted).
std::ptrdiff_t m_alt_insert_point; // where to insert the next alternative
bool m_has_case_change; // true if somewhere in the current block the case has changed
@@ -96,7 +98,7 @@ private:
template
basic_regex_parser::basic_regex_parser(regex_data* data)
- : basic_regex_creator(data), m_mark_count(0), m_paren_start(0), m_alt_insert_point(0), m_has_case_change(false)
+ : basic_regex_creator(data), m_mark_count(0), m_mark_reset(-1), m_max_mark(0), m_paren_start(0), m_alt_insert_point(0), m_has_case_change(false)
{
}
@@ -123,8 +125,16 @@ void basic_regex_parser::parse(const charT* p1, const charT* p2,
switch(l_flags & regbase::main_option_type)
{
case regbase::perl_syntax_group:
- m_parser_proc = &basic_regex_parser::parse_extended;
- break;
+ {
+ m_parser_proc = &basic_regex_parser::parse_extended;
+ //
+ // Add a leading paren with index zero to give recursions a target:
+ //
+ re_brace* br = static_cast(this->append_state(syntax_element_startmark, sizeof(re_brace)));
+ br->index = 0;
+ br->icase = this->flags() & regbase::icase;
+ break;
+ }
case regbase::basic_syntax_group:
m_parser_proc = &basic_regex_parser::parse_basic;
break;
@@ -375,11 +385,17 @@ bool basic_regex_parser::parse_open_paren()
if(0 == (this->flags() & regbase::nosubs))
{
markid = ++m_mark_count;
+#ifndef BOOST_NO_STD_DISTANCE
if(this->flags() & regbase::save_subexpression_location)
this->m_pdata->m_subs.push_back(std::pair(std::distance(m_base, m_position) - 1, 0));
+#else
+ if(this->flags() & regbase::save_subexpression_location)
+ this->m_pdata->m_subs.push_back(std::pair((m_position - m_base) - 1, 0));
+#endif
}
re_brace* pb = static_cast(this->append_state(syntax_element_startmark, sizeof(re_brace)));
pb->index = markid;
+ pb->icase = this->flags() & regbase::icase;
std::ptrdiff_t last_paren_start = this->getoffset(pb);
// back up insertion point for alternations, and set new point:
std::ptrdiff_t last_alt_point = m_alt_insert_point;
@@ -392,6 +408,11 @@ bool basic_regex_parser::parse_open_paren()
bool old_case_change = m_has_case_change;
m_has_case_change = false; // no changes to this scope as yet...
//
+ // Back up branch reset data in case we have a nested (?|...)
+ //
+ int mark_reset = m_mark_reset;
+ m_mark_reset = -1;
+ //
// now recursively add more states, this will terminate when we get to a
// matching ')' :
//
@@ -416,6 +437,10 @@ bool basic_regex_parser::parse_open_paren()
this->flags(opts);
m_has_case_change = old_case_change;
//
+ // restore branch reset:
+ //
+ m_mark_reset = mark_reset;
+ //
// we either have a ')' or we have run out of characters prematurely:
//
if(m_position == m_end)
@@ -424,14 +449,20 @@ bool basic_regex_parser::parse_open_paren()
return false;
}
BOOST_ASSERT(this->m_traits.syntax_type(*m_position) == regex_constants::syntax_close_mark);
+#ifndef BOOST_NO_STD_DISTANCE
if(markid && (this->flags() & regbase::save_subexpression_location))
this->m_pdata->m_subs.at(markid - 1).second = std::distance(m_base, m_position);
+#else
+ if(markid && (this->flags() & regbase::save_subexpression_location))
+ this->m_pdata->m_subs.at(markid - 1).second = (m_position - m_base);
+#endif
++m_position;
//
// append closing parenthesis state:
//
pb = static_cast(this->append_state(syntax_element_endmark, sizeof(re_brace)));
pb->index = markid;
+ pb->icase = this->flags() & regbase::icase;
this->m_paren_start = last_paren_start;
//
// restore the alternate insertion point:
@@ -600,6 +631,7 @@ bool basic_regex_parser::parse_extended_escape()
// fall through:
case regex_constants::escape_type_class:
{
+escape_type_class_jump:
typedef typename traits::char_class_type mask_type;
mask_type m = this->m_traits.lookup_classname(m_position, m_position+1);
if(m != 0)
@@ -709,7 +741,104 @@ bool basic_regex_parser::parse_extended_escape()
return true;
}
fail(regex_constants::error_ctype, m_position - m_base);
+ return false;
}
+ case regex_constants::escape_type_reset_start_mark:
+ if(0 == (this->flags() & (regbase::main_option_type | regbase::no_perl_ex)))
+ {
+ re_brace* pb = static_cast(this->append_state(syntax_element_startmark, sizeof(re_brace)));
+ pb->index = -5;
+ pb->icase = this->flags() & regbase::icase;
+ this->m_pdata->m_data.align();
+ ++m_position;
+ return true;
+ }
+ goto escape_type_class_jump;
+ case regex_constants::escape_type_line_ending:
+ if(0 == (this->flags() & (regbase::main_option_type | regbase::no_perl_ex)))
+ {
+ const charT* e = get_escape_R_string();
+ const charT* old_position = m_position;
+ const charT* old_end = m_end;
+ const charT* old_base = m_base;
+ m_position = e;
+ m_base = e;
+ m_end = e + traits::length(e);
+ bool r = parse_all();
+ m_position = ++old_position;
+ m_end = old_end;
+ m_base = old_base;
+ return r;
+ }
+ goto escape_type_class_jump;
+ case regex_constants::escape_type_extended_backref:
+ if(0 == (this->flags() & (regbase::main_option_type | regbase::no_perl_ex)))
+ {
+ bool have_brace = false;
+ bool negative = false;
+ if(++m_position == m_end)
+ {
+ fail(regex_constants::error_escape, m_position - m_base);
+ return false;
+ }
+ // maybe have \g{ddd}
+ if(this->m_traits.syntax_type(*m_position) == regex_constants::syntax_open_brace)
+ {
+ if(++m_position == m_end)
+ {
+ fail(regex_constants::error_escape, m_position - m_base);
+ return false;
+ }
+ have_brace = true;
+ }
+ negative = (*m_position == static_cast('-'));
+ if((negative) && (++m_position == m_end))
+ {
+ fail(regex_constants::error_escape, m_position - m_base);
+ return false;
+ }
+ const charT* pc = m_position;
+ int i = this->m_traits.toi(pc, m_end, 10);
+ if(i < 0)
+ {
+ // Check for a named capture:
+ const charT* base = m_position;
+ while((m_position != m_end) && (this->m_traits.syntax_type(*m_position) != regex_constants::syntax_close_brace))
+ ++m_position;
+ i = this->m_pdata->get_id(base, m_position);
+ pc = m_position;
+ }
+ if(negative)
+ i = 1 + m_mark_count - i;
+ if((i > 0) && (this->m_backrefs & (1u << (i-1))))
+ {
+ m_position = pc;
+ re_brace* pb = static_cast(this->append_state(syntax_element_backref, sizeof(re_brace)));
+ pb->index = i;
+ pb->icase = this->flags() & regbase::icase;
+ }
+ else
+ {
+ fail(regex_constants::error_backref, m_position - m_end);
+ return false;
+ }
+ m_position = pc;
+ if(have_brace)
+ {
+ if((m_position == m_end) || (this->m_traits.syntax_type(*m_position) != regex_constants::syntax_close_brace))
+ {
+ fail(regex_constants::error_escape, m_position - m_base);
+ return false;
+ }
+ ++m_position;
+ }
+ return true;
+ }
+ goto escape_type_class_jump;
+ case regex_constants::escape_type_control_v:
+ if(0 == (this->flags() & (regbase::main_option_type | regbase::no_perl_ex)))
+ goto escape_type_class_jump;
+ // fallthrough:
default:
this->append_literal(unescape_character());
break;
@@ -737,6 +866,7 @@ template
bool basic_regex_parser::parse_repeat(std::size_t low, std::size_t high)
{
bool greedy = true;
+ bool pocessive = false;
std::size_t insert_point;
//
// when we get to here we may have a non-greedy ? mark still to come:
@@ -748,12 +878,19 @@ bool basic_regex_parser::parse_repeat(std::size_t low, std::size_
)
)
{
- // OK we have a perl regex, check for a '?':
+ // OK we have a perl or emacs regex, check for a '?':
if(this->m_traits.syntax_type(*m_position) == regex_constants::syntax_question)
{
greedy = false;
++m_position;
}
+ // for perl regexes only check for pocessive ++ repeats.
+ if((0 == (this->flags() & regbase::main_option_type))
+ && (this->m_traits.syntax_type(*m_position) == regex_constants::syntax_plus))
+ {
+ pocessive = true;
+ ++m_position;
+ }
}
if(0 == this->m_last_state)
{
@@ -822,6 +959,22 @@ bool basic_regex_parser::parse_repeat(std::size_t low, std::size_
// now fill in the alt jump for the repeat:
rep = static_cast(this->getaddress(rep_off));
rep->alt.i = this->m_pdata->m_data.size() - rep_off;
+ //
+ // If the repeat is pocessive then bracket the repeat with a (?>...)
+ // independent sub-expression construct:
+ //
+ if(pocessive)
+ {
+ re_brace* pb = static_cast(this->insert_state(insert_point, syntax_element_startmark, sizeof(re_brace)));
+ pb->index = -3;
+ pb->icase = this->flags() & regbase::icase;
+ re_jump* jmp = static_cast(this->insert_state(insert_point + sizeof(re_brace), syntax_element_jump, sizeof(re_jump)));
+ this->m_pdata->m_data.align();
+ jmp->alt.i = this->m_pdata->m_data.size() - this->getoffset(jmp);
+ pb = static_cast(this->append_state(syntax_element_endmark, sizeof(re_brace)));
+ pb->index = -3;
+ pb->icase = this->flags() & regbase::icase;
+ }
return true;
}
@@ -944,6 +1097,14 @@ bool basic_regex_parser::parse_alt()
fail(regex_constants::error_empty, this->m_position - this->m_base);
return false;
}
+ //
+ // Reset mark count if required:
+ //
+ if(m_max_mark < m_mark_count)
+ m_max_mark = m_mark_count;
+ if(m_mark_reset >= 0)
+ m_mark_count = m_mark_reset;
+
++m_position;
//
// we need to append a trailing jump:
@@ -1462,7 +1623,7 @@ charT basic_regex_parser::unescape_character()
int i = this->m_traits.toi(m_position, m_end, 16);
if((m_position == m_end)
|| (i < 0)
- || ((std::numeric_limits::is_specialized) && (charT(i) > (std::numeric_limits::max)()))
+ || ((std::numeric_limits::is_specialized) && (i > (int)(std::numeric_limits::max)()))
|| (this->m_traits.syntax_type(*m_position) != regex_constants::syntax_close_brace))
{
fail(regex_constants::error_badbrace, m_position - m_base);
@@ -1568,6 +1729,7 @@ bool basic_regex_parser::parse_backref()
m_position = pc;
re_brace* pb = static_cast(this->append_state(syntax_element_backref, sizeof(re_brace)));
pb->index = i;
+ pb->icase = this->flags() & regbase::icase;
}
else
{
@@ -1655,6 +1817,7 @@ bool basic_regex_parser::parse_perl_extension()
int markid = 0;
std::ptrdiff_t jump_offset = 0;
re_brace* pb = static_cast(this->append_state(syntax_element_startmark, sizeof(re_brace)));
+ pb->icase = this->flags() & regbase::icase;
std::ptrdiff_t last_paren_start = this->getoffset(pb);
// back up insertion point for alternations, and set new point:
std::ptrdiff_t last_alt_point = m_alt_insert_point;
@@ -1665,11 +1828,18 @@ bool basic_regex_parser::parse_perl_extension()
regex_constants::syntax_option_type old_flags = this->flags();
bool old_case_change = m_has_case_change;
m_has_case_change = false;
+ charT name_delim;
+ int mark_reset = m_mark_reset;
+ m_mark_reset = -1;
+ int v;
//
// select the actual extension used:
//
switch(this->m_traits.syntax_type(*m_position))
{
+ case regex_constants::syntax_or:
+ m_mark_reset = m_mark_count;
+ // fall through:
case regex_constants::syntax_colon:
//
// a non-capturing mark:
@@ -1677,6 +1847,57 @@ bool basic_regex_parser::parse_perl_extension()
pb->index = markid = 0;
++m_position;
break;
+ case regex_constants::syntax_digit:
+ {
+ //
+ // a recursive subexpression:
+ //
+ v = this->m_traits.toi(m_position, m_end, 10);
+ if((v < 0) || (this->m_traits.syntax_type(*m_position) != regex_constants::syntax_close_mark))
+ {
+ fail(regex_constants::error_backref, m_position - m_base);
+ return false;
+ }
+insert_recursion:
+ pb->index = markid = 0;
+ static_cast(this->append_state(syntax_element_recurse, sizeof(re_jump)))->alt.i = v;
+ static_cast(
+ this->append_state(syntax_element_toggle_case, sizeof(re_case))
+ )->icase = this->flags() & regbase::icase;
+ break;
+ }
+ case regex_constants::syntax_plus:
+ //
+ // A forward-relative recursive subexpression:
+ //
+ ++m_position;
+ v = this->m_traits.toi(m_position, m_end, 10);
+ if((v <= 0) || (this->m_traits.syntax_type(*m_position) != regex_constants::syntax_close_mark))
+ {
+ fail(regex_constants::error_backref, m_position - m_base);
+ return false;
+ }
+ v += m_mark_count;
+ goto insert_recursion;
+ case regex_constants::syntax_dash:
+ //
+ // Possibly a backward-relative recursive subexpression:
+ //
+ ++m_position;
+ v = this->m_traits.toi(m_position, m_end, 10);
+ if(v <= 0)
+ {
+ --m_position;
+ // Oops not a relative recursion at all, but a (?-imsx) group:
+ goto option_group_jump;
+ }
+ v = m_mark_count + 1 - v;
+ if(v <= 0)
+ {
+ fail(regex_constants::error_backref, m_position - m_base);
+ return false;
+ }
+ goto insert_recursion;
case regex_constants::syntax_equal:
pb->index = markid = -1;
++m_position;
@@ -1706,8 +1927,10 @@ bool basic_regex_parser::parse_perl_extension()
pb->index = markid = -1;
else
{
- fail(regex_constants::error_badrepeat, m_position - m_base);
- return false;
+ // Probably a named capture which also starts (?< :
+ name_delim = '>';
+ --m_position;
+ goto named_capture_jump;
}
++m_position;
jump_offset = this->getoffset(this->append_state(syntax_element_jump, sizeof(re_jump)));
@@ -1736,7 +1959,95 @@ bool basic_regex_parser::parse_perl_extension()
return false;
}
int v = this->m_traits.toi(m_position, m_end, 10);
- if(v > 0)
+ if(*m_position == charT('R'))
+ {
+ if(++m_position == m_end)
+ {
+ fail(regex_constants::error_badrepeat, m_position - m_base);
+ return false;
+ }
+ if(*m_position == charT('&'))
+ {
+ const charT* base = ++m_position;
+ while((m_position != m_end) && (this->m_traits.syntax_type(*m_position) != regex_constants::syntax_close_mark))
+ ++m_position;
+ if(m_position == m_end)
+ {
+ fail(regex_constants::error_badrepeat, m_position - m_base);
+ return false;
+ }
+ v = -static_cast(hash_value_from_capture_name(base, m_position));
+ }
+ else
+ {
+ v = -this->m_traits.toi(m_position, m_end, 10);
+ }
+ re_brace* br = static_cast(this->append_state(syntax_element_assert_backref, sizeof(re_brace)));
+ br->index = v < 0 ? (v - 1) : 0;
+ if(this->m_traits.syntax_type(*m_position) != regex_constants::syntax_close_mark)
+ {
+ fail(regex_constants::error_badrepeat, m_position - m_base);
+ return false;
+ }
+ if(++m_position == m_end)
+ {
+ fail(regex_constants::error_badrepeat, m_position - m_base);
+ return false;
+ }
+ }
+ else if((*m_position == charT('\'')) || (*m_position == charT('<')))
+ {
+ const charT* base = ++m_position;
+ while((m_position != m_end) && (*m_position != charT('>')) && (*m_position != charT('\'')))
+ ++m_position;
+ if(m_position == m_end)
+ {
+ fail(regex_constants::error_badrepeat, m_position - m_base);
+ return false;
+ }
+ v = static_cast(hash_value_from_capture_name(base, m_position));
+ re_brace* br = static_cast(this->append_state(syntax_element_assert_backref, sizeof(re_brace)));
+ br->index = v;
+ if((*m_position != charT('>')) && (*m_position != charT('\'')) || (++m_position == m_end))
+ {
+ fail(regex_constants::error_badrepeat, m_position - m_base);
+ return false;
+ }
+ if(this->m_traits.syntax_type(*m_position) != regex_constants::syntax_close_mark)
+ {
+ fail(regex_constants::error_badrepeat, m_position - m_base);
+ return false;
+ }
+ if(++m_position == m_end)
+ {
+ fail(regex_constants::error_badrepeat, m_position - m_base);
+ return false;
+ }
+ }
+ else if(*m_position == charT('D'))
+ {
+ const char* def = "DEFINE";
+ while(*def && (m_position != m_end) && (*m_position == charT(*def)))
+ ++m_position, ++def;
+ if((m_position == m_end) || *def)
+ {
+ fail(regex_constants::error_badrepeat, m_position - m_base);
+ return false;
+ }
+ re_brace* br = static_cast(this->append_state(syntax_element_assert_backref, sizeof(re_brace)));
+ br->index = 9999; // special magic value!
+ if(this->m_traits.syntax_type(*m_position) != regex_constants::syntax_close_mark)
+ {
+ fail(regex_constants::error_badrepeat, m_position - m_base);
+ return false;
+ }
+ if(++m_position == m_end)
+ {
+ fail(regex_constants::error_badrepeat, m_position - m_base);
+ return false;
+ }
+ }
+ else if(v > 0)
{
re_brace* br = static_cast(this->append_state(syntax_element_assert_backref, sizeof(re_brace)));
br->index = v;
@@ -1784,7 +2095,7 @@ bool basic_regex_parser::parse_perl_extension()
if((this->m_traits.syntax_type(*m_position) != regex_constants::syntax_equal)
&& (this->m_traits.syntax_type(*m_position) != regex_constants::syntax_not))
{
- fail(regex_constants::error_badrepeat, m_position - m_base);
+ fail(regex_constants::error_paren, m_position - m_base);
return false;
}
m_position -= 2;
@@ -1795,10 +2106,93 @@ bool basic_regex_parser::parse_perl_extension()
case regex_constants::syntax_close_mark:
fail(regex_constants::error_badrepeat, m_position - m_base);
return false;
+ case regex_constants::escape_type_end_buffer:
+ {
+ name_delim = *m_position;
+named_capture_jump:
+ markid = 0;
+ if(0 == (this->flags() & regbase::nosubs))
+ {
+ markid = ++m_mark_count;
+ #ifndef BOOST_NO_STD_DISTANCE
+ if(this->flags() & regbase::save_subexpression_location)
+ this->m_pdata->m_subs.push_back(std::pair(std::distance(m_base, m_position) - 2, 0));
+ #else
+ if(this->flags() & regbase::save_subexpression_location)
+ this->m_pdata->m_subs.push_back(std::pair((m_position - m_base) - 2, 0));
+ #endif
+ }
+ pb->index = markid;
+ const charT* base = ++m_position;
+ if(m_position == m_end)
+ {
+ fail(regex_constants::error_paren, m_position - m_base);
+ return false;
+ }
+ while((m_position != m_end) && (*m_position != name_delim))
+ ++m_position;
+ if(m_position == m_end)
+ {
+ fail(regex_constants::error_paren, m_position - m_base);
+ return false;
+ }
+ this->m_pdata->set_name(base, m_position, markid);
+ ++m_position;
+ break;
+ }
default:
+ if(*m_position == charT('R'))
+ {
+ ++m_position;
+ v = 0;
+ if(this->m_traits.syntax_type(*m_position) != regex_constants::syntax_close_mark)
+ {
+ fail(regex_constants::error_backref, m_position - m_base);
+ return false;
+ }
+ goto insert_recursion;
+ }
+ if(*m_position == charT('&'))
+ {
+ ++m_position;
+ const charT* base = m_position;
+ while((m_position != m_end) && (this->m_traits.syntax_type(*m_position) != regex_constants::syntax_close_mark))
+ ++m_position;
+ if(m_position == m_end)
+ {
+ fail(regex_constants::error_backref, m_position - m_base);
+ return false;
+ }
+ v = static_cast(hash_value_from_capture_name(base, m_position));
+ goto insert_recursion;
+ }
+ if(*m_position == charT('P'))
+ {
+ ++m_position;
+ if(m_position == m_end)
+ {
+ fail(regex_constants::error_backref, m_position - m_base);
+ return false;
+ }
+ if(*m_position == charT('>'))
+ {
+ ++m_position;
+ const charT* base = m_position;
+ while((m_position != m_end) && (this->m_traits.syntax_type(*m_position) != regex_constants::syntax_close_mark))
+ ++m_position;
+ if(m_position == m_end)
+ {
+ fail(regex_constants::error_backref, m_position - m_base);
+ return false;
+ }
+ v = static_cast(hash_value_from_capture_name(base, m_position));
+ goto insert_recursion;
+ }
+ }
//
// lets assume that we have a (?imsx) group and try and parse it:
//
+option_group_jump:
regex_constants::syntax_option_type opts = parse_options();
if(m_position == m_end)
return false;
@@ -1897,9 +2291,20 @@ bool basic_regex_parser::parse_perl_extension()
}
else if(this->getaddress(static_cast(b)->alt.i, b)->type == syntax_element_alt)
{
+ // Can't have seen more than one alternative:
fail(regex_constants::error_bad_pattern, m_position - m_base);
return false;
}
+ else
+ {
+ // We must *not* have seen an alternative inside a (DEFINE) block:
+ b = this->getaddress(b->next.i, b);
+ if((b->type == syntax_element_assert_backref) && (static_cast(b)->index == 9999))
+ {
+ fail(regex_constants::error_bad_pattern, m_position - m_base);
+ return false;
+ }
+ }
// check for invalid repetition of next state:
b = this->getaddress(expected_alt_point);
b = this->getaddress(static_cast(b)->next.i, b);
@@ -1915,6 +2320,7 @@ bool basic_regex_parser::parse_perl_extension()
//
pb = static_cast(this->append_state(syntax_element_endmark, sizeof(re_brace)));
pb->index = markid;
+ pb->icase = this->flags() & regbase::icase;
this->m_paren_start = last_paren_start;
//
// restore the alternate insertion point:
@@ -1924,6 +2330,31 @@ bool basic_regex_parser::parse_perl_extension()
// and the case change data:
//
m_has_case_change = old_case_change;
+ //
+ // And the mark_reset data:
+ //
+ if(m_max_mark > m_mark_count)
+ {
+ m_mark_count = m_max_mark;
+ }
+ m_mark_reset = mark_reset;
+
+
+ if(markid > 0)
+ {
+#ifndef BOOST_NO_STD_DISTANCE
+ if(this->flags() & regbase::save_subexpression_location)
+ this->m_pdata->m_subs.at(markid - 1).second = std::distance(m_base, m_position) - 1;
+#else
+ if(this->flags() & regbase::save_subexpression_location)
+ this->m_pdata->m_subs.at(markid - 1).second = (m_position - m_base) - 1;
+#endif
+ //
+ // allow backrefs to this mark:
+ //
+ if((markid > 0) && (markid < (int)(sizeof(unsigned) * CHAR_BIT)))
+ this->m_backrefs |= 1u << (markid - 1);
+ }
return true;
}
diff --git a/include/boost/regex/v4/cpp_regex_traits.hpp b/include/boost/regex/v4/cpp_regex_traits.hpp
index 89fe49d8..7ce3ed30 100644
--- a/include/boost/regex/v4/cpp_regex_traits.hpp
+++ b/include/boost/regex/v4/cpp_regex_traits.hpp
@@ -394,7 +394,9 @@ enum
char_class_graph=char_class_alnum|char_class_punct,
char_class_blank=1<<9,
char_class_word=1<<10,
- char_class_unicode=1<<11
+ char_class_unicode=1<<11,
+ char_class_horizontal_space=1<<12,
+ char_class_vertical_space=1<<13
};
#endif
@@ -413,6 +415,8 @@ public:
BOOST_STATIC_CONSTANT(char_class_type, mask_blank = 1u << 24);
BOOST_STATIC_CONSTANT(char_class_type, mask_word = 1u << 25);
BOOST_STATIC_CONSTANT(char_class_type, mask_unicode = 1u << 26);
+ BOOST_STATIC_CONSTANT(char_class_type, mask_horizontal = 1u << 27);
+ BOOST_STATIC_CONSTANT(char_class_type, mask_vertical = 1u << 28);
#endif
typedef std::basic_string string_type;
@@ -477,6 +481,10 @@ template
typename cpp_regex_traits_implementation::char_class_type const cpp_regex_traits_implementation::mask_word;
template
typename cpp_regex_traits_implementation::char_class_type const cpp_regex_traits_implementation::mask_unicode;
+template
+typename cpp_regex_traits_implementation::char_class_type const cpp_regex_traits_implementation::mask_vertical;
+template
+typename cpp_regex_traits_implementation::char_class_type const cpp_regex_traits_implementation::mask_horizontal;
#endif
#endif
@@ -688,18 +696,20 @@ void cpp_regex_traits_implementation::init()
// Custom class names:
//
#ifndef BOOST_REGEX_BUGGY_CTYPE_FACET
- static const char_class_type masks[14] =
+ static const char_class_type masks[16] =
{
std::ctype::alnum,
std::ctype::alpha,
std::ctype::cntrl,
std::ctype::digit,
std::ctype::graph,
+ cpp_regex_traits_implementation::mask_horizontal,
std::ctype::lower,
std::ctype::print,
std::ctype::punct,
std::ctype::space,
std::ctype::upper,
+ cpp_regex_traits_implementation::mask_vertical,
std::ctype::xdigit,
cpp_regex_traits_implementation::mask_blank,
cpp_regex_traits_implementation::mask_word,
@@ -713,11 +723,13 @@ void cpp_regex_traits_implementation::init()
::boost::re_detail::char_class_cntrl,
::boost::re_detail::char_class_digit,
::boost::re_detail::char_class_graph,
+ ::boost::re_detail::char_class_horizontal_space,
::boost::re_detail::char_class_lower,
::boost::re_detail::char_class_print,
::boost::re_detail::char_class_punct,
::boost::re_detail::char_class_space,
::boost::re_detail::char_class_upper,
+ ::boost::re_detail::char_class_vertical_space,
::boost::re_detail::char_class_xdigit,
::boost::re_detail::char_class_blank,
::boost::re_detail::char_class_word,
@@ -744,7 +756,7 @@ typename cpp_regex_traits_implementation::char_class_type
cpp_regex_traits_implementation::lookup_classname_imp(const charT* p1, const charT* p2) const
{
#ifndef BOOST_REGEX_BUGGY_CTYPE_FACET
- static const char_class_type masks[20] =
+ static const char_class_type masks[22] =
{
0,
std::ctype::alnum,
@@ -754,6 +766,7 @@ typename cpp_regex_traits_implementation::char_class_type
std::ctype::digit,
std::ctype::digit,
std::ctype::graph,
+ cpp_regex_traits_implementation::mask_horizontal,
std::ctype::lower,
std::ctype::lower,
std::ctype::print,
@@ -763,12 +776,13 @@ typename cpp_regex_traits_implementation::char_class_type
std::ctype::upper,
cpp_regex_traits_implementation::mask_unicode,
std::ctype::upper,
+ cpp_regex_traits_implementation::mask_vertical,
std::ctype::alnum | cpp_regex_traits_implementation::mask_word,
std::ctype::alnum | cpp_regex_traits_implementation::mask_word,
std::ctype::xdigit,
};
#else
- static const char_class_type masks[20] =
+ static const char_class_type masks[22] =
{
0,
::boost::re_detail::char_class_alnum,
@@ -778,6 +792,7 @@ typename cpp_regex_traits_implementation::char_class_type
::boost::re_detail::char_class_digit,
::boost::re_detail::char_class_digit,
::boost::re_detail::char_class_graph,
+ ::boost::re_detail::char_class_horizontal_space,
::boost::re_detail::char_class_lower,
::boost::re_detail::char_class_lower,
::boost::re_detail::char_class_print,
@@ -787,6 +802,7 @@ typename cpp_regex_traits_implementation::char_class_type
::boost::re_detail::char_class_upper,
::boost::re_detail::char_class_unicode,
::boost::re_detail::char_class_upper,
+ ::boost::re_detail::char_class_vertical_space,
::boost::re_detail::char_class_alnum | ::boost::re_detail::char_class_word,
::boost::re_detail::char_class_alnum | ::boost::re_detail::char_class_word,
::boost::re_detail::char_class_xdigit,
@@ -820,7 +836,9 @@ bool cpp_regex_traits_implementation::isctype(const charT c, char_class_t
|| ((mask & ::boost::re_detail::char_class_xdigit) && (m_pctype->is(std::ctype::xdigit, c)))
|| ((mask & ::boost::re_detail::char_class_blank) && (m_pctype->is(std::ctype::space, c)) && !::boost::re_detail::is_separator(c))
|| ((mask & ::boost::re_detail::char_class_word) && (c == '_'))
- || ((mask & ::boost::re_detail::char_class_unicode) && ::boost::re_detail::is_extended(c));
+ || ((mask & ::boost::re_detail::char_class_unicode) && ::boost::re_detail::is_extended(c))
+ || ((mask & ::boost::re_detail::char_class_vertical) && (is_separator(c) || (c == '\v')))
+ || ((mask & ::boost::re_detail::char_class_horizontal) && m_pctype->is(std::ctype::space, c) && !(is_separator(c) || (c == '\v')));
}
#endif
@@ -930,6 +948,12 @@ public:
&& m_pimpl->m_pctype->is(std::ctype::space, c)
&& !re_detail::is_separator(c))
return true;
+ else if((f & re_detail::cpp_regex_traits_implementation::mask_vertical)
+ && (::boost::re_detail::is_separator(c) || (c == '\v')))
+ return true;
+ else if((f & re_detail::cpp_regex_traits_implementation::mask_horizontal)
+ && this->isctype(c, std::ctype::space) && !this->isctype(c, re_detail::cpp_regex_traits_implementation::mask_vertical))
+ return true;
return false;
#else
return m_pimpl->isctype(c, f);
diff --git a/include/boost/regex/v4/iterator_category.hpp b/include/boost/regex/v4/iterator_category.hpp
index 20870a0c..9e401423 100644
--- a/include/boost/regex/v4/iterator_category.hpp
+++ b/include/boost/regex/v4/iterator_category.hpp
@@ -31,10 +31,14 @@ namespace detail{
template
struct is_random_imp
{
+#ifndef BOOST_NO_STD_ITERATOR_TRAITS
private:
typedef typename std::iterator_traits::iterator_category cat;
public:
BOOST_STATIC_CONSTANT(bool, value = (::boost::is_convertible::value));
+#else
+ BOOST_STATIC_CONSTANT(bool, value = false);
+#endif
};
template
diff --git a/include/boost/regex/v4/match_results.hpp b/include/boost/regex/v4/match_results.hpp
index acf509fa..09dd31f0 100644
--- a/include/boost/regex/v4/match_results.hpp
+++ b/include/boost/regex/v4/match_results.hpp
@@ -36,6 +36,13 @@ namespace boost{
#pragma warning(disable : 4251 4231 4660)
#endif
+namespace re_detail{
+
+template
+class named_subexpressions;
+
+}
+
template
class match_results
{
@@ -62,13 +69,14 @@ public:
typedef typename re_detail::regex_iterator_traits<
BidiIterator>::value_type char_type;
typedef std::basic_string string_type;
+ typedef re_detail::named_subexpressions_base named_sub_type;
// construct/copy/destroy:
explicit match_results(const Allocator& a = Allocator())
#ifndef BOOST_NO_STD_ALLOCATOR
- : m_subs(a), m_base() {}
+ : m_subs(a), m_base(), m_last_closed_paren(0) {}
#else
- : m_subs(), m_base() { (void)a; }
+ : m_subs(), m_base(), m_last_closed_paren(0) { (void)a; }
#endif
match_results(const match_results& m)
: m_subs(m.m_subs), m_base(m.m_base) {}
@@ -95,6 +103,24 @@ public:
return m_subs[sub].length();
return 0;
}
+ difference_type length(const char_type* sub) const
+ {
+ const char_type* end = sub;
+ while(*end) ++end;
+ return length(named_subexpression_index(sub, end));
+ }
+ template
+ difference_type length(const charT* sub) const
+ {
+ const charT* end = sub;
+ while(*end) ++end;
+ return length(named_subexpression_index(sub, end));
+ }
+ template
+ difference_type length(const std::basic_string& sub) const
+ {
+ return length(sub.c_str());
+ }
difference_type position(size_type sub = 0) const
{
sub += 2;
@@ -108,6 +134,24 @@ public:
}
return ~static_cast(0);
}
+ difference_type position(const char_type* sub) const
+ {
+ const char_type* end = sub;
+ while(*end) ++end;
+ return position(named_subexpression_index(sub, end));
+ }
+ template
+ difference_type position(const charT* sub) const
+ {
+ const charT* end = sub;
+ while(*end) ++end;
+ return position(named_subexpression_index(sub, end));
+ }
+ template
+ difference_type position(const std::basic_string& sub) const
+ {
+ return position(sub.c_str());
+ }
string_type str(int sub = 0) const
{
sub += 2;
@@ -122,6 +166,25 @@ public:
}
return result;
}
+ string_type str(const char_type* sub) const
+ {
+ return (*this)[sub].str();
+ }
+ template
+ string_type str(const std::basic_string& sub) const
+ {
+ return (*this)[sub].str();
+ }
+ template
+ string_type str(const charT* sub) const
+ {
+ return (*this)[sub].str();
+ }
+ template
+ string_type str(const std::basic_string& sub) const
+ {
+ return (*this)[sub].str();
+ }
const_reference operator[](int sub) const
{
sub += 2;
@@ -131,6 +194,75 @@ public:
}
return m_null;
}
+ //
+ // Named sub-expressions:
+ //
+ const_reference named_subexpression(const char_type* i, const char_type* j) const
+ {
+ int index = m_named_subs->get_id(i, j);
+ return index > 0 ? (*this)[index] : m_null;
+ }
+ template
+ const_reference named_subexpression(const charT* i, const charT* j) const
+ {
+ BOOST_STATIC_ASSERT(sizeof(charT) <= sizeof(char_type));
+ if(i == j)
+ return m_null;
+ std::vector s;
+ while(i != j)
+ s.insert(s.end(), *i++);
+ return named_subexpression(&*s.begin(), &*s.begin() + s.size());
+ }
+ int named_subexpression_index(const char_type* i, const char_type* j) const
+ {
+ int index = m_named_subs->get_id(i, j);
+ return index > 0 ? index : -20;
+ }
+ template
+ int named_subexpression_index(const charT* i, const charT* j) const
+ {
+ BOOST_STATIC_ASSERT(sizeof(charT) <= sizeof(char_type));
+ if(i == j)
+ return -20;
+ std::vector s;
+ while(i != j)
+ s.insert(s.end(), *i++);
+ return named_subexpression_index(&*s.begin(), &*s.begin() + s.size());
+ }
+ template
+ const_reference operator[](const std::basic_string& s) const
+ {
+ return named_subexpression(s.c_str(), s.c_str() + s.size());
+ }
+ const_reference operator[](const char_type* p) const
+ {
+ const char_type* e = p;
+ while(*e) ++e;
+ return named_subexpression(p, e);
+ }
+
+ template
+ const_reference operator[](const charT* p) const
+ {
+ BOOST_STATIC_ASSERT(sizeof(charT) <= sizeof(char_type));
+ if(*p == 0)
+ return m_null;
+ std::vector s;
+ while(*p)
+ s.insert(s.end(), *p++);
+ return named_subexpression(&*s.begin(), &*s.begin() + s.size());
+ }
+ template
+ const_reference operator[](const std::basic_string& ns) const
+ {
+ BOOST_STATIC_ASSERT(sizeof(charT) <= sizeof(char_type));
+ if(ns.empty())
+ return m_null;
+ std::vector s;
+ for(unsigned i = 0; i < ns.size(); ++i)
+ s.insert(s.end(), ns[i]);
+ return named_subexpression(&*s.begin(), &*s.begin() + s.size());
+ }
const_reference prefix() const
{
@@ -186,6 +318,10 @@ public:
::boost::re_detail::regex_format_imp(i, *this, fmt.data(), fmt.data() + fmt.size(), flags, re.get_traits());
return result;
}
+ const_reference get_last_closed_paren()const
+ {
+ return m_last_closed_paren == 0 ? m_null : (*this)[m_last_closed_paren];
+ }
allocator_type get_allocator() const
{
@@ -230,13 +366,15 @@ public:
m_null.matched = false;
}
- void BOOST_REGEX_CALL set_second(BidiIterator i, size_type pos, bool m = true)
+ void BOOST_REGEX_CALL set_second(BidiIterator i, size_type pos, bool m = true, bool escape_k = false)
{
+ if(pos)
+ m_last_closed_paren = pos;
pos += 2;
BOOST_ASSERT(m_subs.size() > pos);
m_subs[pos].second = i;
m_subs[pos].matched = m;
- if(pos == 2)
+ if((pos == 2) && !escape_k)
{
m_subs[0].first = i;
m_subs[0].matched = (m_subs[0].first != m_subs[0].second);
@@ -261,6 +399,7 @@ public:
m_subs.insert(m_subs.end(), n+2-len, v);
}
m_subs[1].first = i;
+ m_last_closed_paren = 0;
}
void BOOST_REGEX_CALL set_base(BidiIterator pos)
{
@@ -284,21 +423,34 @@ public:
m_subs[n].matched = false;
}
}
- void BOOST_REGEX_CALL set_first(BidiIterator i, size_type pos)
+ void BOOST_REGEX_CALL set_first(BidiIterator i, size_type pos, bool escape_k = false)
{
BOOST_ASSERT(pos+2 < m_subs.size());
- if(pos)
+ if(pos || escape_k)
+ {
m_subs[pos+2].first = i;
+ if(escape_k)
+ {
+ m_subs[1].second = i;
+ m_subs[1].matched = (m_subs[1].first != m_subs[1].second);
+ }
+ }
else
set_first(i);
}
void BOOST_REGEX_CALL maybe_assign(const match_results& m);
+ void BOOST_REGEX_CALL set_named_subs(boost::shared_ptr