Added support for "format_first_only" new format flag

[SVN r10119]
This commit is contained in:
John Maddock
2001-05-17 11:55:55 +00:00
parent f466b2ad2a
commit 04b11fdd1c
7 changed files with 421 additions and 373 deletions

View File

@ -3,6 +3,9 @@ FIXED: Support for STLPort 4.1b6.
FIXED: Library calling convention for VC6 debug builds. FIXED: Library calling convention for VC6 debug builds.
FIXED: Borland compiler support when using non-default calling convention. FIXED: Borland compiler support when using non-default calling convention.
CHANGED: Reorganised and simplified config setup. 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: Version 310:
ADDED: Support for static linking with VC6 + dynamic runtime. ADDED: Support for static linking with VC6 + dynamic runtime.
@ -259,5 +262,6 @@ BUG: character sets don't function correctly when regbase::char_classes

View File

@ -57,8 +57,9 @@ void load_file(std::string& s, std::istream& is)
int main(int argc, const char** argv) int main(int argc, const char** argv)
{ {
e1.set_expression(expression_text); try{
e2.set_expression(pre_expression); e1.assign(expression_text);
e2.assign(pre_expression);
for(int i = 1; i < argc; ++i) for(int i = 1; i < argc; ++i)
{ {
std::cout << "Processing file " << argv[i] << std::endl; 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); boost::regex_merge(out, s.begin(), s.end(), e1, format_string);
os << footer_text; os << footer_text;
} }
}
catch(...)
{ return -1; }
return 0; return 0;
} }
@ -129,3 +133,4 @@ const char* footer_text = "</PRE>\n</BODY>\n\n";

View File

@ -15,8 +15,9 @@ content="C:\PROGRAM FILES\MICROSOFT OFFICE\OFFICE\html.dot">
<table border="0" cellpadding="7" cellspacing="0" width="100%"> <table border="0" cellpadding="7" cellspacing="0" width="100%">
<tr> <tr>
<td valign="top" width="50%"><h3><img src="../../c++boost.gif" <td valign="top" width="50%"><h3><img
alt="C++ Boost" width="276" height="86"></h3> src="../../c++boost.gif" alt="C++ Boost" width="276"
height="86"></h3>
</td> </td>
<td valign="top" width="50%"><h3 align="center">Regex++, <td valign="top" width="50%"><h3 align="center">Regex++,
RegEx Class Reference. </h3> RegEx Class Reference. </h3>
@ -112,8 +113,8 @@ are allowed. </p>
</tr> </tr>
<tr> <tr>
<td valign="top" width="7%">&nbsp;</td> <td valign="top" width="7%">&nbsp;</td>
<td valign="top" width="43%">RegEx(<b>const</b> RegEx&amp; <td valign="top" width="43%">RegEx(<b>const</b>
o);</td> RegEx&amp; o);</td>
<td valign="top" width="42%">Copy constructor, all the <td valign="top" width="42%">Copy constructor, all the
properties of parameter <i>o</i> are copied.</td> properties of parameter <i>o</i> are copied.</td>
<td valign="top" width="7%">&nbsp;</td> <td valign="top" width="7%">&nbsp;</td>
@ -196,7 +197,8 @@ are allowed. </p>
<tr> <tr>
<td valign="top" width="7%">&nbsp;</td> <td valign="top" width="7%">&nbsp;</td>
<td valign="top" width="43%"><b>bool</b> Match(<b>const</b> <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 <td valign="top" width="42%">Attempts to match the
current expression against the text <i>p</i> using the current expression against the text <i>p</i> using the
match flags <i>flags</i> - see <a match flags <i>flags</i> - see <a
@ -221,7 +223,8 @@ are allowed. </p>
<tr> <tr>
<td valign="top" width="7%">&nbsp;</td> <td valign="top" width="7%">&nbsp;</td>
<td valign="top" width="43%"><b>bool</b> Search(<b>const</b> <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 <td valign="top" width="42%">Attempts to find a match for
the current expression somewhere in the text <i>p</i> the current expression somewhere in the text <i>p</i>
using the match flags <i>flags </i>- see <a using the match flags <i>flags </i>- see <a
@ -306,7 +309,8 @@ are allowed. </p>
<td valign="top" width="7%">&nbsp;</td> <td valign="top" width="7%">&nbsp;</td>
<td valign="top" width="43%"><b>unsigned</b> <b>int</b> <td valign="top" width="43%"><b>unsigned</b> <b>int</b>
Grep(std::vector&lt;<b>unsigned int</b>&gt;&amp; v, <b>const</b> Grep(std::vector&lt;<b>unsigned int</b>&gt;&amp; 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 <td valign="top" width="42%">Finds all matches of the
current expression in the text <i>p</i> using the match current expression in the text <i>p</i> using the match
flags <i>flags </i>- see <a flags <i>flags </i>- see <a
@ -435,11 +439,16 @@ are allowed. </p>
replace operation: searches through the string <i>in</i> replace operation: searches through the string <i>in</i>
for all occurrences of the current expression, for each for all occurrences of the current expression, for each
occurrence replaces the match with the format string <i>fmt</i>. occurrence replaces the match with the format string <i>fmt</i>.
Uses <i>flags</i> to determine what gets matched. If <i>copy</i> Uses <i>flags</i> to determine what gets matched, and how
is true then all unmatched sections of input are copied the format string should be treated. If <i>copy</i> is
unchanged to output. Returns the new string. See <a 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 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%">&nbsp;</td> <td valign="top" width="7%">&nbsp;</td>
</tr> </tr>
<tr> <tr>
@ -451,18 +460,23 @@ are allowed. </p>
replace operation: searches through the string <i>in</i> replace operation: searches through the string <i>in</i>
for all occurrences of the current expression, for each for all occurrences of the current expression, for each
occurrence replaces the match with the format string <i>fmt</i>. occurrence replaces the match with the format string <i>fmt</i>.
Uses <i>flags</i> to determine what gets matched. If <i>copy</i> Uses <i>flags</i> to determine what gets matched, and how
is true then all unmatched sections of input are copied the format string should be treated. If <i>copy</i> is
unchanged to output. Returns the new string. See <a 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 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%">&nbsp;</td> <td valign="top" width="7%">&nbsp;</td>
</tr> </tr>
<tr> <tr>
<td>&nbsp;</td> <td>&nbsp;</td>
<td valign="top"><b>unsigned</b> Split(std::vector&lt;std::string&gt;&amp; <td valign="top"><b>unsigned</b> Split(std::vector&lt;std::string&gt;&amp;
v, std::string&amp; s, <b>unsigned</b> flags = match_default, v, std::string&amp; s, <b>unsigned</b> flags =
<b>unsigned</b> max_count = ~0);</td> match_default, <b>unsigned</b> max_count = ~0);</td>
<td valign="top">Splits the input string and pushes each <td valign="top">Splits the input string and pushes each
one onto the vector. If the expression contains no marked one onto the vector. If the expression contains no marked
sub-expressions, then one string is outputted for each sub-expressions, then one string is outputted for each

View File

@ -33,7 +33,8 @@ enum format_flags_t{
format_sed = match_max << 1, // sed style replacement. format_sed = match_max << 1, // sed style replacement.
format_perl = format_sed << 1, // perl style replacement. format_perl = format_sed << 1, // perl style replacement.
format_no_copy = format_perl << 1, // don't copy non-matching segments. 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{ 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, re_copy_out(*out, iterator(m[-1].first), iterator(m[-1].second)));
oi_assign(out, _reg_format_aux(*out, m, f, flags, *pt)); oi_assign(out, _reg_format_aux(*out, m, f, flags, *pt));
*last = m[-2].first; *last = m[-2].first;
return true; return flags & format_first_only ? false : true;
} }
}; };

File diff suppressed because it is too large Load Diff

View File

@ -82,6 +82,7 @@ flag_info flag_data[] = {
{ BOOST_RE_STR("format_sed"), 10, format_sed, 3 }, { BOOST_RE_STR("format_sed"), 10, format_sed, 3 },
{ BOOST_RE_STR("format_perl"), 11, format_perl, 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_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_NO_POSIX_TEST"), 17, REG_NO_POSIX_TEST, 4 },
{ BOOST_RE_STR("REG_UNICODE_ONLY"), 16, REG_UNICODE_ONLY, 4 }, { BOOST_RE_STR("REG_UNICODE_ONLY"), 16, REG_UNICODE_ONLY, 4 },

View File

@ -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?" (?1A:B)C "...ACBC,,,ACBC*ACBC?"
(a+)|(b+) "...aaabb,,,ab*abbb?" ?1:B "...B,,,B*B?" (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: ; changes to newline handling with 2.11:
; ;
@ -871,3 +878,4 @@ a+(?#b+)b+ xaaabbba 1 7