mirror of
https://github.com/boostorg/regex.git
synced 2025-07-23 09:07:25 +02:00
regex: updated snip4.cpp (fixed patholgical expressions).
[SVN r8366]
This commit is contained in:
@ -2053,7 +2053,7 @@ follows: <br>
|
||||
takes C/C++ source code as input, and outputs syntax highlighted
|
||||
HTML code. </p>
|
||||
|
||||
<pre><font color="#008040">#include <iostream></font>
|
||||
<pre>
|
||||
<font color="#008040">#include <fstream></font>
|
||||
<font color="#008040">#include <sstream></font>
|
||||
<font color="#008040">#include <string></font>
|
||||
@ -2082,8 +2082,8 @@ boost::regex e1, e2;
|
||||
<b>while</b>(is.get(c))
|
||||
{
|
||||
<b>if</b>(s.capacity() == s.size())
|
||||
s.reserve(s.capacity() * <font color="#000080">3</font>);
|
||||
s.append(<font color="#000080">1</font>, c);
|
||||
s.reserve(s.capacity() * <font color="#0000A0">3</font>);
|
||||
s.append(<font color="#0000A0">1</font>, c);
|
||||
}
|
||||
}
|
||||
|
||||
@ -2105,12 +2105,12 @@ color="#0000FF">".htm"</font>));
|
||||
<font color="#000080"><i>// temporary string stream</i></font>
|
||||
std::ostringstream t(std::ios::out | std::ios::binary);
|
||||
std::ostream_iterator<<b>char</b>, <b>char</b>> oi(t);
|
||||
regex_merge(oi, in.begin(), in.end(), e2, pre_format);
|
||||
boost::regex_merge(oi, in.begin(), in.end(), e2, pre_format);
|
||||
<font color="#000080"><i>// then output to final output stream</i></font>
|
||||
<font color="#000080"><i>// adding syntax highlighting:</i></font>
|
||||
std::string s(t.str());
|
||||
std::ostream_iterator<<b>char</b>, <b>char</b>> out(os);
|
||||
regex_merge(out, s.begin(), s.end(), e1, format_string);
|
||||
boost::regex_merge(out, s.begin(), s.end(), e1, format_string);
|
||||
os << footer_text;
|
||||
}
|
||||
<b>return</b> <font color="#0000A0">0</font>;
|
||||
@ -2123,14 +2123,14 @@ color="#0000FF">"(?1<)(?2>)"</font>;
|
||||
|
||||
|
||||
<b>const</b> <b>char</b>* expression_text = <font color="#000080"><i>// preprocessor directives: index 1</i></font>
|
||||
<font color="#0000FF">"(^[[:blank:]]*#([^\\n]*\\\\[[:space:]]+)*[^\\n]*)|"</font>
|
||||
<font color="#000080"><i>// comment: index 3</i></font>
|
||||
<font color="#0000FF">"(//[^\\n]*|/\\*([^*]|\\*+[^*/])*\\*+/)|"</font>
|
||||
<font color="#000080"><i>// literals: index 5</i></font>
|
||||
<font color="#0000FF">"\\<([+-]?((0x[[:xdigit:]]+)|(([[:digit:]]*\\.)?[[:digit:]]+([eE][+-]?[[:digit:]]+)?))u?((int(8|16|32|64))|L)?)\\>|"</font>
|
||||
<font color="#000080"><i>// string literals: index 14</i></font>
|
||||
<font color="#0000FF">"('([^\\\\']|\\\\.)*'|\"([^\\\\\"]|\\\\.)*\")|"</font>
|
||||
<font color="#000080"><i>// keywords: index 17</i></font>
|
||||
<font color="#0000FF">"(^[[:blank:]]*#(?:[^\\\\\\n]|\\\\[^\\n[:punct:][:word:]]*[\\n[:punct:][:word:]])*)|"</font>
|
||||
<font color="#000080"><i>// comment: index 2</i></font>
|
||||
<font color="#0000FF">"(//[^\\n]*|/\\*.*?\\*/)|"</font>
|
||||
<font color="#000080"><i>// literals: index 3</i></font>
|
||||
<font color="#0000FF">"\\<([+-]?(?:(?:0x[[:xdigit:]]+)|(?:(?:[[:digit:]]*\\.)?[[:digit:]]+(?:[eE][+-]?[[:digit:]]+)?))u?(?:(?:int(?:8|16|32|64))|L)?)\\>|"</font>
|
||||
<font color="#000080"><i>// string literals: index 4</i></font>
|
||||
<font color="#0000FF">"('(?:[^\\\\']|\\\\.)*'|\"(?:[^\\\\\"]|\\\\.)*\")|"</font>
|
||||
<font color="#000080"><i>// keywords: index 5</i></font>
|
||||
<font color="#0000FF">"\\<(__asm|__cdecl|__declspec|__export|__far16|__fastcall|__fortran|__import"</font>
|
||||
<font color="#0000FF">"|__pascal|__rtti|__stdcall|_asm|_cdecl|__except|_export|_far16|_fastcall"</font>
|
||||
<font color="#0000FF">"|__finally|_fortran|_import|_pascal|_stdcall|__thread|__try|asm|auto|bool"</font>
|
||||
@ -2143,16 +2143,16 @@ color="#0000FF">"(?1<)(?2>)"</font>;
|
||||
;
|
||||
|
||||
<b>const</b> <b>char</b>* format_string = <font color="#0000FF">"(?1<font color=\"#008040\">$&</font>)"</font>
|
||||
<font color="#0000FF">"(?3<I><font color=\"#000080\">$&</font></I>)"</font>
|
||||
<font color="#0000FF">"(?5<font color=\"#0000A0\">$&</font>)"</font>
|
||||
<font color="#0000FF">"(?14<font color=\"#0000FF\">$&</font>)"</font>
|
||||
<font color="#0000FF">"(?17<B>$&</B>)"</font>;
|
||||
<font color="#0000FF">"(?2<I><font color=\"#000080\">$&</font></I>)"</font>
|
||||
<font color="#0000FF">"(?3<font color=\"#0000A0\">$&</font>)"</font>
|
||||
<font color="#0000FF">"(?4<font color=\"#0000FF\">$&</font>)"</font>
|
||||
<font color="#0000FF">"(?5<B>$&</B>)"</font>;
|
||||
|
||||
<b>const</b> <b>char</b>* header_text = <font color="#0000FF">"<HTML>\n<HEAD>\n"</font>
|
||||
<font color="#0000FF">"<TITLE>Auto-generated html formated source</TITLE>\n"</font>
|
||||
<font color="#0000FF">"<META HTTP-EQUIV=\"Content-Type\" CONTENT=\"text/html; charset=windows-1252\">\n"</font>
|
||||
<font color="#0000FF">"</HEAD>\n"</font>
|
||||
<font color="#0000FF">"<BODY LINK=\"#0000ff\" VLINK=\"#800080\" BGCOLOR=\"#ffff99\">\n"</font>
|
||||
<font color="#0000FF">"<BODY LINK=\"#0000ff\" VLINK=\"#800080\" BGCOLOR=\"#ffffff\">\n"</font>
|
||||
<font color="#0000FF">"<P> </P>\n<PRE>"</font>;
|
||||
|
||||
<b>const</b> <b>char</b>* footer_text = <font color="#0000FF">"</PRE>\n</BODY>\n\n"</font>;
|
||||
|
Reference in New Issue
Block a user