mirror of
https://github.com/boostorg/regex.git
synced 2025-07-13 04:16:37 +02:00
Added support for "format_first_only" new format flag
[SVN r10119]
This commit is contained in:
@ -3,6 +3,9 @@ FIXED: Support for STLPort 4.1b6.
|
||||
FIXED: Library calling convention for VC6 debug builds.
|
||||
FIXED: Borland compiler support when using non-default calling convention.
|
||||
CHANGED: Reorganised and simplified config setup.
|
||||
ADDED: Support for replacing only the first occurance during a regex_merge
|
||||
using the format_first_only flag.
|
||||
CHANGED: Removed use of deprecated api set_expression in one of the examples.
|
||||
|
||||
Version 310:
|
||||
ADDED: Support for static linking with VC6 + dynamic runtime.
|
||||
@ -259,5 +262,6 @@ BUG: character sets don't function correctly when regbase::char_classes
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -57,8 +57,9 @@ void load_file(std::string& s, std::istream& is)
|
||||
|
||||
int main(int argc, const char** argv)
|
||||
{
|
||||
e1.set_expression(expression_text);
|
||||
e2.set_expression(pre_expression);
|
||||
try{
|
||||
e1.assign(expression_text);
|
||||
e2.assign(pre_expression);
|
||||
for(int i = 1; i < argc; ++i)
|
||||
{
|
||||
std::cout << "Processing file " << argv[i] << std::endl;
|
||||
@ -80,6 +81,9 @@ int main(int argc, const char** argv)
|
||||
boost::regex_merge(out, s.begin(), s.end(), e1, format_string);
|
||||
os << footer_text;
|
||||
}
|
||||
}
|
||||
catch(...)
|
||||
{ return -1; }
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -129,3 +133,4 @@ const char* footer_text = "</PRE>\n</BODY>\n\n";
|
||||
|
||||
|
||||
|
||||
|
||||
|
48
hl_ref.htm
48
hl_ref.htm
@ -15,8 +15,9 @@ content="C:\PROGRAM FILES\MICROSOFT OFFICE\OFFICE\html.dot">
|
||||
|
||||
<table border="0" cellpadding="7" cellspacing="0" width="100%">
|
||||
<tr>
|
||||
<td valign="top" width="50%"><h3><img src="../../c++boost.gif"
|
||||
alt="C++ Boost" width="276" height="86"></h3>
|
||||
<td valign="top" width="50%"><h3><img
|
||||
src="../../c++boost.gif" alt="C++ Boost" width="276"
|
||||
height="86"></h3>
|
||||
</td>
|
||||
<td valign="top" width="50%"><h3 align="center">Regex++,
|
||||
RegEx Class Reference. </h3>
|
||||
@ -112,8 +113,8 @@ are allowed. </p>
|
||||
</tr>
|
||||
<tr>
|
||||
<td valign="top" width="7%"> </td>
|
||||
<td valign="top" width="43%">RegEx(<b>const</b> RegEx&
|
||||
o);</td>
|
||||
<td valign="top" width="43%">RegEx(<b>const</b>
|
||||
RegEx& o);</td>
|
||||
<td valign="top" width="42%">Copy constructor, all the
|
||||
properties of parameter <i>o</i> are copied.</td>
|
||||
<td valign="top" width="7%"> </td>
|
||||
@ -196,7 +197,8 @@ are allowed. </p>
|
||||
<tr>
|
||||
<td valign="top" width="7%"> </td>
|
||||
<td valign="top" width="43%"><b>bool</b> Match(<b>const</b>
|
||||
<b>char</b>* p, <b>unsigned</b> <b>int</b> flags = match_default);</td>
|
||||
<b>char</b>* p, <b>unsigned</b> <b>int</b> flags =
|
||||
match_default);</td>
|
||||
<td valign="top" width="42%">Attempts to match the
|
||||
current expression against the text <i>p</i> using the
|
||||
match flags <i>flags</i> - see <a
|
||||
@ -221,7 +223,8 @@ are allowed. </p>
|
||||
<tr>
|
||||
<td valign="top" width="7%"> </td>
|
||||
<td valign="top" width="43%"><b>bool</b> Search(<b>const</b>
|
||||
<b>char</b>* p, <b>unsigned</b> <b>int</b> flags = match_default);</td>
|
||||
<b>char</b>* p, <b>unsigned</b> <b>int</b> flags =
|
||||
match_default);</td>
|
||||
<td valign="top" width="42%">Attempts to find a match for
|
||||
the current expression somewhere in the text <i>p</i>
|
||||
using the match flags <i>flags </i>- see <a
|
||||
@ -306,7 +309,8 @@ are allowed. </p>
|
||||
<td valign="top" width="7%"> </td>
|
||||
<td valign="top" width="43%"><b>unsigned</b> <b>int</b>
|
||||
Grep(std::vector<<b>unsigned int</b>>& v, <b>const</b>
|
||||
<b>char</b>* p, <b>unsigned</b> <b>int</b> flags = match_default);</td>
|
||||
<b>char</b>* p, <b>unsigned</b> <b>int</b> flags =
|
||||
match_default);</td>
|
||||
<td valign="top" width="42%">Finds all matches of the
|
||||
current expression in the text <i>p</i> using the match
|
||||
flags <i>flags </i>- see <a
|
||||
@ -435,11 +439,16 @@ are allowed. </p>
|
||||
replace operation: searches through the string <i>in</i>
|
||||
for all occurrences of the current expression, for each
|
||||
occurrence replaces the match with the format string <i>fmt</i>.
|
||||
Uses <i>flags</i> to determine what gets matched. If <i>copy</i>
|
||||
is true then all unmatched sections of input are copied
|
||||
unchanged to output. Returns the new string. See <a
|
||||
Uses <i>flags</i> to determine what gets matched, and how
|
||||
the format string should be treated. If <i>copy</i> is
|
||||
true then all unmatched sections of input are copied
|
||||
unchanged to output, if the flag <em>format_first_only</em>
|
||||
is set then only the first occurance of the pattern found
|
||||
is replaced. Returns the new string. See <a
|
||||
href="format_string.htm#format_string">also format string
|
||||
syntax</a>.</td>
|
||||
syntax</a>, <a href="template_class_ref.htm#match_type">match
|
||||
flags</a> and <a
|
||||
href="template_class_ref.htm#format_flags">format flags</a>.</td>
|
||||
<td valign="top" width="7%"> </td>
|
||||
</tr>
|
||||
<tr>
|
||||
@ -451,18 +460,23 @@ are allowed. </p>
|
||||
replace operation: searches through the string <i>in</i>
|
||||
for all occurrences of the current expression, for each
|
||||
occurrence replaces the match with the format string <i>fmt</i>.
|
||||
Uses <i>flags</i> to determine what gets matched. If <i>copy</i>
|
||||
is true then all unmatched sections of input are copied
|
||||
unchanged to output. Returns the new string. See <a
|
||||
Uses <i>flags</i> to determine what gets matched, and how
|
||||
the format string should be treated. If <i>copy</i> is
|
||||
true then all unmatched sections of input are copied
|
||||
unchanged to output, if the flag <em>format_first_only</em>
|
||||
is set then only the first occurance of the pattern found
|
||||
is replaced. Returns the new string. See <a
|
||||
href="format_string.htm#format_string">also format string
|
||||
syntax</a>.</td>
|
||||
syntax</a>, <a href="template_class_ref.htm#match_type">match
|
||||
flags</a> and <a
|
||||
href="template_class_ref.htm#format_flags">format flags</a>.</td>
|
||||
<td valign="top" width="7%"> </td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td> </td>
|
||||
<td valign="top"><b>unsigned</b> Split(std::vector<std::string>&
|
||||
v, std::string& s, <b>unsigned</b> flags = match_default,
|
||||
<b>unsigned</b> max_count = ~0);</td>
|
||||
v, std::string& s, <b>unsigned</b> flags =
|
||||
match_default, <b>unsigned</b> max_count = ~0);</td>
|
||||
<td valign="top">Splits the input string and pushes each
|
||||
one onto the vector. If the expression contains no marked
|
||||
sub-expressions, then one string is outputted for each
|
||||
|
@ -33,7 +33,8 @@ enum format_flags_t{
|
||||
format_sed = match_max << 1, // sed style replacement.
|
||||
format_perl = format_sed << 1, // perl style replacement.
|
||||
format_no_copy = format_perl << 1, // don't copy non-matching segments.
|
||||
format_is_if = format_no_copy << 1 // internal use only.
|
||||
format_first_only = format_no_copy << 1, // Only replace first occurance.
|
||||
format_is_if = format_first_only << 1 // internal use only.
|
||||
};
|
||||
|
||||
namespace re_detail{
|
||||
@ -468,7 +469,7 @@ public:
|
||||
oi_assign(out, re_copy_out(*out, iterator(m[-1].first), iterator(m[-1].second)));
|
||||
oi_assign(out, _reg_format_aux(*out, m, f, flags, *pt));
|
||||
*last = m[-2].first;
|
||||
return true;
|
||||
return flags & format_first_only ? false : true;
|
||||
}
|
||||
};
|
||||
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -82,6 +82,7 @@ flag_info flag_data[] = {
|
||||
{ BOOST_RE_STR("format_sed"), 10, format_sed, 3 },
|
||||
{ BOOST_RE_STR("format_perl"), 11, format_perl, 3 },
|
||||
{ BOOST_RE_STR("format_no_copy"), 14, format_no_copy, 3 },
|
||||
{ BOOST_RE_STR("format_first_only"), 17, format_first_only, 3 },
|
||||
|
||||
{ BOOST_RE_STR("REG_NO_POSIX_TEST"), 17, REG_NO_POSIX_TEST, 4 },
|
||||
{ BOOST_RE_STR("REG_UNICODE_ONLY"), 16, REG_UNICODE_ONLY, 4 },
|
||||
|
@ -813,6 +813,13 @@ a+(b+) "...aaabb,,,ab*abbb?" $1 "...bb,,,b*bbb?"
|
||||
(a+)|(b+) "...aaabb,,,ab*abbb?" (?1A:B)C "...ACBC,,,ACBC*ACBC?"
|
||||
(a+)|(b+) "...aaabb,,,ab*abbb?" ?1:B "...B,,,B*B?"
|
||||
|
||||
- match_default normal REG_EXTENDED REG_STARTEND REG_MERGE format_first_only
|
||||
; move to copying unmatched data, but replace first occurance only:
|
||||
a+ "...aaa,,," bbb "...bbb,,,"
|
||||
a+(b+) "...aaabb,,," $1 "...bb,,,"
|
||||
a+(b+) "...aaabb,,,ab*abbb?" $1 "...bb,,,ab*abbb?"
|
||||
(a+)|(b+) "...aaabb,,,ab*abbb?" (?1A)(?2B) "...Abb,,,ab*abbb?"
|
||||
|
||||
;
|
||||
; changes to newline handling with 2.11:
|
||||
;
|
||||
@ -871,3 +878,4 @@ a+(?#b+)b+ xaaabbba 1 7
|
||||
|
||||
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user