/usr/share/doc/libbobcat2-dev/man/pattern.3.html is in libbobcat-dev 2.20.01-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 | <html><head>
<title>FBB::Pattern</title>
<link rev="made" href="mailto:Frank B. Brokken: f.b.brokken@rug.nl">
</head>
<body text="#27408B" bgcolor="#FFFAF0">
<hr>
<h1>FBB::Pattern</h1>
<h2>libbobcat1-dev_2.20.01-x.tar.gz</h2>
<h2>2005-2011</h2>
<html><head>
<link rev="made" href="mailto:Frank B. Brokken: f.b.brokken@rug.nl">
</head>
<body text="#27408B" bgcolor="#FFFAF0">
<hr>
<h1></h1>
<html><head>
<title>FBB::Pattern(3bobcat)</title>
<link rev="made" href="mailto:Frank B. Brokken: f.b.brokken@rug.nl">
</head>
<body text="#27408B" bgcolor="#FFFAF0">
<hr>
<h1>FBB::Pattern(3bobcat)</h1>
<h2>libbobcat1-dev_2.20.01-x.tar.gz Pattern matcher</h2>
<h2>2005-2011</h2>
<p>
<h2>NAME</h2>FBB::Pattern - Performs RE pattern matching
<p>
<h2>SYNOPSIS</h2>
<strong>#include <bobcat/pattern></strong><br>
Linking option: <em>-lbobcat</em>
<p>
<h2>DESCRIPTION</h2>
<strong>Pattern</strong> objects may be used for Regular Expression (RE) pattern
matching. The class is a wrapper around the <strong>regcomp</strong>(3) family of
functions. By default it uses `extended regular expressions', requiring you to
escape multipliers and bounding-characters when they should be interpreted as
ordinary characters (i.e., <em>*, +, ?, ^, $, |, (, ), [, ], {, }</em> should be
escaped when used as literal characters).
<p>
The <strong>Pattern</strong> class supports the use of the following (Perl-like)
special escape sequences: <br>
\b - indicating a word-boundary <br>
\d - indicating a digit (<em>[[:digit:]]</em>) character <br>
\s - indicating a white-space (<em>[:space:]</em>) character <br>
\w - indicating a word (<em>[:alnum:]</em>) character
<p>
The corresponding capitals (e.g., <strong>\W</strong>) define the complementary
character sets. The capitalized character set shorthands are not expanded
inside explicit character-classes (i.e., <em>[ ... ]</em> constructions). So
<em>[\W]</em> represents a set of two characters: <em>\</em> and <em>W</em>.
<p>
As the backslash (<em>\</em>) is treated as a special character it should be
handled carefully. <strong>Pattern</strong> converts the escape sequences <em>\d \s \w</em> (and
outside of explicit character classes the sequences <em>\D \S \W</em>) to their
respective character classes. All other escape sequences are kept as is, and
the resulting regular expression is offered to the pattern matching
compilation function <strong>regcomp</strong>(3). This function will again interpret
escape sequences. Consequently some care should be exercised when defining
patterns containing escape sequences. Here are the rules:
<ul>
<li> Special escape sequences (like <em>\d</em>) are converted to character
classes. E.g.,
<pre>
---------------------------------------------------------
Specify: Converts to: regcomp uses: Matches:
---------------------------------------------------------
\d [[:digit:]] [[:digit:]] 3
---------------------------------------------------------
</pre>
<li> Ordinary escape sequences (like <em>\x</em>) are kept as-is. E.g.,
<pre>
---------------------------------------------------------
Specify: Converts to: regcomp uses: Matches:
---------------------------------------------------------
\x \x x x
---------------------------------------------------------
</pre>
<li> To specify a literal escape sequence, it must be written twice. E.g.,
<pre>
---------------------------------------------------------
Specify: Converts to: regcomp uses: Matches:
---------------------------------------------------------
\\x \\x \x \x
---------------------------------------------------------
</pre>
</ul>
<p>
<h2>NAMESPACE</h2>
<strong>FBB</strong><br>
All constructors, members, operators and manipulators, mentioned in this
man-page, are defined in the namespace <strong>FBB</strong>.
<p>
<h2>INHERITS FROM</h2>
-
<p>
<h2>TYPEDEF</h2>
<ul>
<li> <strong>Pattern::Position</strong>:<br>
A nested type representing the offsets of the first character and
the offset beyond the last character of the matched text or indexed
subexpression, defined as <em>std::pair<std::string::size_type,
std::string::size_type></em>.
</ul>
<p>
<h2>CONSTRUCTORS</h2>
<ul>
<li> <strong>Pattern()</strong>:<br>
The default constructor defines no pattern, but is available as a
placeholder for, e.g., containers requiring default constructors. A
<strong>Pattern</strong> object thus constructed cannot be used to match patterns, but
can be the <em>lvalue</em> in assignments where another <strong>Pattern</strong> object is
the <em>rvalue</em>. However, it can receive a pattern using the member
<strong>setPattern()</strong> (see below). An <strong>FBB::Errno</strong> object is thrown if the object
could not be constructed.
<li> <strong>Pattern(std::string const &pattern,
bool caseSensitive = true,
size_t nSub = 10,
int options = REG_EXTENDED | REG_NEWLINE)</strong>:<br>
This constructor compiles <em>pattern</em>, preparing the <strong>Pattern</strong>
object for pattern matches. The second parameter determines whether case
sensitive matching will be used (the default) or not. Subexpressions are
defined by parentheses pairs. Each matching pair defines a subexpression,
where the order-number of their opening parentheses determines the
subexpression's index. By default at most 10 subexpressions are recognized.
The <em>options</em> flags may be:
<p>
REG_EXTENDED: <br>
Use POSIX Extended Regular Expression syntax when
interpreting regex. If not set, POSIX Basic Regular
Expression syntax is used.
<p>
REG_NOSUB: <br>
Support for substring addressing of matches is not
required. The nmatch and pmatch parameters to
regexec are ignored if the pattern buffer supplied
was compiled with this flag set.
<p>
REG_NEWLINE: <br>
Match-any-character operators don't match a newline.
<p>
A non-matching list ([^...]) not containing a newline
does not match a newline.
<p>
Match-beginning-of-line operator (^) matches the empty
string immediately after a newline, regardless of whether
eflags, the execution flags of regexec, contains
REG_NOTBOL.
<p>
Match-end-of-line operator ($) matches the empty
string immediately before a newline, regardless of
whether eflags contains REG_NOTEOL.
</ul>
<p>
<em>Pattern</em> offers copy and move constructors.
<p>
<h2>MEMBER FUNCTIONS</h2>
All members of <strong>std::ostringstream</strong> and <strong> std::exception</strong> are
available, as <strong>Pattern</strong> inherits from these classes.
<ul>
<li> <strong>std::string before() const</strong>:<br>
Following a successful match, <strong>before()</strong> returns the text before the
matched text.
<li> <strong>std::string beyond() const</strong>:<br>
Following a successful match, <strong>beyond()</strong> returns the text beyond the
matched text.
<li> <strong>size_t end() const</strong>:<br>
Returns the number of matched elements (text and
subexpressions). <strong>end()</strong> is the lowest index value for which <strong>position()</strong>
returns two <em>std::string::npos</em> values (see the <strong>position()</strong> member
function, below).
<li> <strong>void match(std::string const &text, int options = 0)</strong>:<br>
Match a string with a pattern. If the text could not be matched, an
<strong>Errno</strong> exception is thrown , using <strong>Pattern::match()</strong> as its prefix-text.
<p>
Options may be:
<p>
REG_NOTBOL: <br>
The match-beginning-of-line operator always fails to match
(but see the compilation flag REG_NEWLINE above) This flag
may be used when different portions of a string are passed
to regexec and the beginning of the string should not be
interpreted as the beginning of the line.
<p>
REG_NOTEOL: <br>
The match-end-of-line operator always fails to
match (but see the compilation flag REG_NEWLINE)
<li> <strong>std::string matched() const</strong>:<br>
Following a successful match, this function returns the matched text.
<li> <strong>std::string const &pattern() const</strong>:<br>
This member function returns the pattern that is offered to
<strong>regcomp</strong>(3). It returns the contents of a <em>static</em> string that is
overwritten at each construction of a <strong>Pattern</strong> object and at each call of
the <em>setPattern()</em> member function.
<li> <strong>Pattern::Position position(size_t index) const</strong>:<br>
With <em>index == 0</em> the fully matched text is returned (identical to
<em>matched()</em>). Other index values return the corresponding
subexpressions. <strong>std::string::npos, std::string::npos</strong> is returned if index
is at least <strong>end()</strong> (which may happen at index value 0).
<li> <strong>void setPattern(std::string const &pattern,
bool caseSensitive = true,
size_t nSub = 10,
int options = REG_EXTENDED | REG_NEWLINE)</strong>:<br>
This member function installs a new compiled <em>pattern</em> in its
<strong>Pattern</strong> object. This member's parameters are identical to the second
constructor's parameters. Refer to that constructor for details about the
parameters. Like the constructor, an <strong>FBB::Errno</strong> exception is thrown if the
new pattern could not be compiled.
<li> <strong>void swap(Pattern &other)</strong>:<br>
The contents of the current object and the <em>other</em> object are
swapped.
</ul>
<p>
<h2>OVERLOADED OPERATORS</h2>
<p>
<ul>
<li> <strong>Pattern &operator=(Pattern &other)</strong>:<br>
A standard overloaded assignment operator.
<li> <strong>std::string operator[](size_t index) const</strong>:<br>
Returns the matched text (for index 0) or the text of a
subexpression. An empty string is returned for index values which are at least
<strong>end()</strong>.
<li> <strong>Pattern &operator<<(int matchOptions)</strong>:<br>
Defines match-options to be used with the following overloaded
operator.
<li> <strong>bool operator<<(std::string const &text)</strong>:<br>
Performs a <strong>match(text, matchOptions)</strong> call, catching any exception
that might be thrown. If no <em>matchOptions</em> were set using the above
overloaded operator, none are used. The options set this way are not `sticky':
when necessary, they have to be re-inserted before each new pattern
matching. The function returns <strong>true</strong> if the matching was successful,
<strong>false</strong> otherwise.
</ul>
<p>
<h2>EXAMPLE</h2>
<pre>
/*
driver.cc
*/
#include "driver.h"
#include <bobcat/pattern>
using namespace std;
using namespace FBB;
void showSubstr(string const &str)
{
static int
count = 1;
cout << "String " << count++ << " is '" << str << "'\n";
}
int main(int argc, char **argv)
{
{
Pattern one("one");
Pattern two(one);
Pattern three("a");
Pattern four;
three = two;
}
try
{
Pattern pattern("aap|noot|mies");
{
Pattern extra(Pattern(pattern));
}
if (pattern << "noot")
cout << "noot matches\n";
else
cout << ": noot doesn't match\n";
}
catch (Errno const &e)
{
cout << e.why() << ": compilation failed" << endl;
}
string pat = "\\d+";
while (true)
{
cout << "Pattern: '" << pat << "'\n";
try
{
Pattern patt(pat, argc == 1); // case sensitive by default,
// any arg for case insensitive
cout << "Compiled pattern: " << patt.pattern() << endl;
Pattern pattern;
pattern = patt; // assignment operator
while (true)
{
cout << "string to match : ";
string st;
getline(cin, st);
if (st == "")
break;
cout << "String: '" << st << "'\n";
try
{
pattern.match(st);
Pattern p3(pattern);
cout << "before: " << p3.before() << "\n"
"matched: " << p3.matched() << "\n"
"beyond: " << pattern.beyond() << "\n"
"end() = " << pattern.end() << endl;
for (size_t idx = 0; idx < pattern.end(); ++idx)
{
string str = pattern[idx];
if (str == "")
cout << "part " << idx << " not present\n";
else
{
Pattern::Position pos = pattern.position(idx);
cout << "part " << idx << ": '" << str << "' (" <<
pos.first << "-" << pos.second << ")\n";
}
}
}
catch (Errno const &e)
{
cout << e.why() << ": " << st << " doesn't match" << endl;
continue;
}
}
}
catch (Errno const &e)
{
cout << e.why() << ": compilation failed" << endl;
}
cout << "New pattern: ";
if (!getline(cin, pat) || !pat.length())
return 0;
}
}
</pre>
<p>
<h2>FILES</h2>
<em>bobcat/pattern</em> - defines the class interface
<p>
<h2>SEE ALSO</h2>
<strong>bobcat</strong>(7), <strong>regcomp</strong>(3), <strong>regex</strong>(3), <strong>regex</strong>(7)
<p>
<h2>BUGS</h2>
Using <em>Pattern</em> objects as static data members of classes (or as global
objects) is potentially dangerous. If the object files defining these static
data members are stored in a dynamic library they may not be initialized
properly or timely, and their eventual destruction may result in a
segmentation fault. This is a well-known problem with static data, see, e.g.,
<em>http://www.parashift.com/c++-faq-lite/ctors.html#faq-10.15</em>. In situations
like this prefer the use of a (shared, unique) pointer to a <em>Pattern</em>,
initialzing the pointer when, e.g., first used.
<p>
<h2>DISTRIBUTION FILES</h2>
<ul>
<li> <em>bobcat_2.20.01-x.dsc</em>: detached signature;
<li> <em>bobcat_2.20.01-x.tar.gz</em>: source archive;
<li> <em>bobcat_2.20.01-x_i386.changes</em>: change log;
<li> <em>libbobcat1_2.20.01-x_*.deb</em>: debian package holding the
libraries;
<li> <em>libbobcat1-dev_2.20.01-x_*.deb</em>: debian package holding the
libraries, headers and manual pages;
<li> <em>http://sourceforge.net/projects/bobcat</em>: public archive location;
</ul>
<p>
<h2>BOBCAT</h2>
Bobcat is an acronym of `Brokken's Own Base Classes And Templates'.
<p>
<h2>COPYRIGHT</h2>
This is free software, distributed under the terms of the
GNU General Public License (GPL).
<p>
<h2>AUTHOR</h2>
Frank B. Brokken (<strong>f.b.brokken@rug.nl</strong>).
<p>
|