This file is indexed.

/usr/include/pcre++.h is in libpcre++-dev 0.9.5-6.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
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
/*
 *
 *  This file  is part of the PCRE++ Class Library.
 *
 *  By  accessing  this software,  PCRE++, you  are  duly informed
 *  of and agree to be  bound  by the  conditions  described below
 *  in this notice:
 *
 *  This software product,  PCRE++,  is developed by Thomas Linden
 *  and copyrighted (C) 2002-2003 by Thomas Linden,with all rights 
 *  reserved.
 *
 *  There  is no charge for PCRE++ software.  You can redistribute
 *  it and/or modify it under the terms of the GNU  Lesser General
 *  Public License, which is incorporated by reference herein.
 *
 *  PCRE++ is distributed WITHOUT ANY WARRANTY, IMPLIED OR EXPRESS,
 *  OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE or that
 *  the use of it will not infringe on any third party's intellec-
 *  tual property rights.
 *
 *  You should have received a copy of the GNU Lesser General Public
 *  License along with PCRE++.  Copies can also be obtained from:
 *
 *    http://www.gnu.org/licenses/lgpl.txt
 *
 *  or by writing to:
 *
 *  Free Software Foundation, Inc.
 *  59 Temple Place, Suite 330
 *  Boston, MA 02111-1307
 *  USA
 *
 *  Or contact:
 *
 *   "Thomas Linden" <tom@daemon.de>
 *
 *
 */

#ifndef HAVE_PCRE_PP_H
#define HAVE_PCRE_PP_H

#include <string>
#include <sstream>
#include <vector>
#include <map>
#include <stdexcept>
#include <iostream>


extern "C" {
  #include <pcre.h>
  #include <locale.h>
}

namespace pcrepp {

#ifdef DEBUG
#define __pcredebug cerr << "(pcre++ DEBUG) " << __LINE__ << ": " 
#else
#define __pcredebug if(0) cerr 
#endif

/** additional binary flag in the hope Philip never ever uses the same in the future
 * @see Pcre(const std::string& expression, unsigned int flags)
 */
#define PCRE_GLOBAL 0x10000


/**
 * The Pcre class is a wrapper around the PCRE library.
 *
 * The library "pcre++" defines a class named "Pcre" which you
 * can use to search in strings using reular expressions as
 * well as getting matched sub strings. It does currently not
 * support all features, which the underlying PCRE library
 * provides, but the most important stuff is implemented.
 *
 * Please study this example code to learn how to use this class:
 * @include examples/demo.cc
 *
 * Compile your programs which use the prce++ class using the following
 * command line:
 * @code
 *   g++ -c yourcode.o `pcre-config --cflags` `pcre++-config --cflags`
 *   g++ yourcode.o `pcre-config --libs` `pcre++-config --libs` -o yourprogram
 * @endcode
 *
 * If you want to learn more about regular expressions which can be used
 * with pcre++, then please read the following documentation:
 * <a href="perlre.html">perlre - Perl regular expressions</a>
 *
 * The pcre library itself does also contain some usefull documentation,
 * which maybe interesting for you:
 * <a href="pcre.html">PCRE manual page</a>
 */

class Pcre {
 private:
  std::string _expression;   /* the given regular expression */
  unsigned int _flags;       /* the given flags, 0 if not defined */
  bool case_t, global_t;     /* internal compile flags, used by replace() and split() */
  pcre *p_pcre;              /* pcre object pointer */
  pcre_extra *p_pcre_extra;  /* stuff required by pcre lib */
  int sub_len;
  int *sub_vec;
  int erroffset;
  char *err_str;
  std::vector<std::string> *resultset;          /* store substrings, if any */
  bool _have_paren;          /* indicate wether we have already parentesis applied in replace */

  const unsigned char *tables; /* locale tables */

  bool did_match;            /** true if the expression produced a match */
  int  num_matches;          /** number of matches if std::vector<std::string>* expected */

  /* reset all counters and free objects, prepare for another search */
  void reset();

  /* compile the pattern */
  void Compile(int flags);

  /* do the actual search, will be called by the public ::search(..) methods */
  bool dosearch(const std::string& stuff, int OffSet);

  /* do the actual split() job, called by the various wrapper split() methods */
  std::vector<std::string> _split(const std::string& piece, int limit, int start_offset, int end_offset);
  
  /* replace $1 .. $n with the corresponding substring, used by replace() */
  std::string _replace_vars(const std::string& piece);

  /* init pointers with NULL */
  void zero();

  std::map<std::string,std::string> info();
  std::string info(int what);

 public:

  /**
   * Exception wrapper class.
   *
   * All errors which may occur inside the Pcre class will
   * throw an exception of this type("Pcre::exception").
   *
   * You can catch such exceptions like this:
   *
   * @code
   * try {
   *   ..
   * }
   * catch(Pcre::exception &e) {
   *   cout << "Pcre++ error: " << e.what() << endl;
   * }
   * @endcode
   */
  class exception : public std::runtime_error {
  private:
    std::string translate(int num) {
      std::string msg;
      switch(num) {
      case -1: msg = "PCRE_ERROR_NOMATCH";      break;
      case -2: msg = "PCRE_ERROR_NULL";         break;
      case -3: msg = "PCRE_ERROR_BADOPTION";    break;
      case -4: msg = "PCRE_ERROR_BADMAGIC";     break;
      case -5: msg = "PCRE_ERROR_UNKNOWN_NODE"; break;
      case -6: msg = "PCRE_ERROR_NOMEMORY";     break;
      case -7: msg = "PCRE_ERROR_NOSUBSTRING";  break;
	// pcre4-HINT: add PCRE_ERROR_MATCHLIMIT support
      }
      return msg;
    }
  public:
    exception(const std::string & msg) : runtime_error(msg) { }
    exception(int num) : runtime_error(translate(num)) { }
  };


  /** Empty Constructor.
   * Create a new empty Pcre object. This is the simplest
   * constructor available, you might consider one of the other
   * constructors as a better solution.
   * You need to initialize thie Pcre object, if you use the
   * empty constructor. You can use one of the two available
   * operator= operators to assign it an expression or a Pcre
   * copy.
   *
   * @return A new empty Pcre object
   */
  Pcre();

  /** Constructor.
   * Compile the given pattern. An Pcre object created this way can
   * be used multiple times to do searches.
   *
   * @param "expression"  a string, which must be a valid perl regular expression.
   * @return A new Pcre object, which holds te compiled pattern.
   * @see Pcre(const std::string& expression, const std::string& flags)
   * @see Pcre(const std::string& expression, unsigned int flags)
   */
  Pcre(const std::string& expression);

  /** Constructor.
   * Compile the given pattern. An Pcre object created this way can
   * be used multiple times to do searches.
   *
   * @param "expression"  a string, which must be a valid perl regular expression.
   * @param "flags" can be one or more of the following letters:
   *
   *- <b>i</b>   Search case insensitive.
   *
   *- <b>m</b>   Match on multiple lines, thus ^ and $ are interpreted
   *             as the start and end of the entire string, not of a
   *             single line.
   *
   *- <b>s</b>   A dot in an expression matches newlines too(which is
   *             normally not the case).
   *
   *- <b>x</b>   Whitespace characters will be ignored (except within
   *             character classes or if escaped).
   *
   *- <b>g</b>   Match multiple times. This flags affects only the behavior of the
   *             replace(const std::string& piece, const std::string& with) method.
   *
   * @return A new Pcre object, which holds te compiled pattern.
   * @see Pcre(const std::string& expression)
   * @see Pcre(const std::string& expression, unsigned int flags)
   */
  Pcre(const std::string& expression, const std::string& flags);

  /** Constructor.
   * Compile the given pattern. An Pcre object created this way can
   * be used multiple times to do searches.
   *
   * @param "expression"  a string, which must be a valid perl regular expression.
   * @param "flags" option bits can be one or more of the following bits:
   *
   * - PCRE_ANCHORED        anchored pattern.
   * - PCRE_CASELESS        case insensitive search.
   * - PCRE_DOLLAR_ENDONLY  dollar sign matches only at end.
   * - PCRE_DOTALL          newline is contained in .
   * - PCRE_EXTENDED        whitespace characters will be ignored.
   * - PCRE_EXTRA           use perl incompatible pcre extensions.
   * - PCRE_MULTILINE       match on multiple lines.
   * - PCRE_NO_AUTO_CAPTURE disable the use of numbered capturing parentheses in the pattern. 
   * - PCRE_UNGREEDY        qunatifiers behave not greedy by default.
   * - PCRE_UTF8            use utf8 support.
   * - PCRE_GLOBAL          (PCRE++ internal flag) match multiple times used only in the
   *                        replace(const std::string& piece, const std::string& with) method.
   *
   * @return A new Pcre object, which holds te compiled pattern.
   * @see Pcre(const std::string& expression)
   * @see Pcre(const std::string& expression, const std::string& flags)
   * @see pcreapi(3) manpage
   */
  Pcre(const std::string& expression, unsigned int flags);

  /** Copy Constructor
   * Creates a new Pcre object of an existing one.
   * @param "P" an existing Pcre object.
   * @return A new Pcre object, which holds te compiled pattern.
   * @see Pcre(const std::string& expression)
   * @see Pcre(const std::string& expression, const std::string& flags)
   */
  Pcre(const Pcre &P);

  /** Operator =.
   * @param "expression" a valid regular expression.
   * @return a new Pcre object.
   *
   * Example:
   *
   * @code
   * Pcre regex = "(A+?)";
   * @endcode
   */
  const Pcre& operator = (const std::string& expression); 

  /** Operator =.
   * @param "&P" an Pcre object
   * @return a new Pcre object
   *
   * Example:
   *
   * @code
   * Pcre reg1("^[a-z]+?");
   * Pcre reg2;
   * reg2 = reg1;
   * @endcode
   */
  const Pcre& operator = (const Pcre &P);

  /** Destructor.
   * The desturcor will automatically invoked if the object
   * is no more used. It frees all the memory allocated by
   * pcre++.
   */
  ~Pcre();

  /** Do a search on the given string.
   * This method does the actual search on the given string.
   * @param "stuff" the string in which you want to search for something.
   * @return boolean <b>true</b> if the regular expression matched. <b>false</b> if not.
   * @see bool search(const std::string& stuff, int OffSet)
   */
  bool search(const std::string& stuff);

  /** Do a search on the given string beginning at the given offset.
   * This method does the actual search on the given string.
   * @param "stuff" the string in which you want to search for something.
   * @param "OffSet" the offset where to start the search.
   * @return boolean <b>true</b> if the regular expression matched. <b>false</b> if not.
   * @see bool search(const std::string& stuff)
   */
  bool search(const std::string& stuff, int OffSet);

  /** Return a vector of substrings, if any.
   * @return a pointer to an std::vector<std::string>, which may be NULL, if no substrings has been found.
   * @see std::vector<std::string>
   */
  std::vector<std::string>* get_sub_strings() const;

  /** Get a substring at a known position. 
   * This method throws an out-of-range exception if the given position
   * is invalid.
   * @param "pos" the position of the substring to return. Identical to perl's $1..$n.
   * @return the substring at the given position.
   *
   * Example:
   * @code
   * 
   * std::string mysub = regex.get_match(1); 
   * 
   * @endcode
   * Get the first substring that matched the expression in the "regex" object.
   */
  std::string get_match(int pos) const;

  /** Get the start position of a substring within the searched string.
   * This method returns the character position of the first character of
   * a substring withing the searched string.
   * @param "pos" the position of the substring. Identical to perl's $1..$n.
   * @return the integer character position of the first character of a substring. Positions are starting at 0.
   *
   * Example:
   * @code
   * 
   * Pcre regex("([0-9]+)");               // search for numerical characters
   * regex.search("The 11th september.");  // do the search on this string
   * std::string day = regex.get_match(1);      // returns "11"
   * int pos = regex.get_match_start(1);   // returns 4, because "11" begins at the
   *                                       // 4th character inside the search string.
   *
   * @endcode
   * @see int get_match_end(int pos)
   * @see int get_match_end()
   * @see int get_match_start()
   */
  int get_match_start(int pos) const;

  /** Get the end position of a substring within the searched string.
   * This method returns the character position of the last character of
   * a substring withing the searched string.
   * @param "pos" the position of the substring. Identical to perl's $1..$n.
   * @return the integer character position of the last character of a substring. Positions are starting at 0.
   *
   * Example:
   * @code
   *
   * Pcre regex("([0-9]+)");               // search for numerical characters
   * regex.search("The 11th september.");  // do the search on this string
   * std::string day = regex.get_match(1);      // returns "11"
   * int pos = regex.get_match_end(1);     // returns 5, because "11" ends at the
   *                                       // 5th character inside the search string.
   *
   * @endcode
   * @see int get_match_start(int pos)
   * @see int get_match_start()
   * @see int get_match_end()
   */
  int get_match_end(int pos) const;




  /** Get the start position of the entire match within the searched string.
   * This method returns the character position of the first character of
   * the entire match within the searched string.
   * @return the integer character position of the first character of the entire match.
   *
   * Example:
   * @code
   *
   * Pcre regex("([0-9]+)\s([a-z]+)");     // search for the date(makes 2 substrings
   * regex.search("The 11th september.");  // do the search on this string
   * int pos = regex.get_match_start();    // returns 4, because "11th september" begins at the
   *                                       // 4th character inside the search string.
   *
   * @endcode
   * @see int get_match_start(int pos)
   * @see int get_match_end(int pos)
   * @see int get_match_end()
   */
  int get_match_start() const;

  /** Get the end position of the entire match within the searched string.
   * This method returns the character position of the last character of
   * the entire match within the searched string.
   * @return the integer character position of the last character of the entire match.
   *
   * Example:
   * @code
   *
   * Pcre regex("([0-9]+)\s([a-z]+)");     // search for the date(makes 2 substrings
   * regex.search("The 11th september.");  // do the search on this string
   * int pos = regex.get_match_end();      // returns 17, because "11th september", which is
                                           // the entire match, ends at the
   *                                       // 17th character inside the search string.
   *
   * @endcode
   * @see int get_match_start()
   * @see int get_match_start(int pos)
   * @see int get_match_end(int pos)
   */
  int get_match_end() const;




  /** Get the length of a substring at a known position. 
   * This method throws an out-of-range exception if the given position
   * is invalid.
   * @param "pos" the position of the substring-length to return. Identical to perl's $1..$n.
   * @return the length substring at the given position.
   *
   */
  size_t get_match_length(int pos) const;

  /** Test if a search was successfull.
   * This method must be invoked <b>after</b> calling search().
   * @return boolean <b>true</b> if the search was successfull at all, or <b>false</b> if not.
   */
  bool matched() const { return did_match; };

  /** Get the number of substrings generated by pcre++.
   * @return the number of substrings generated by pcre++.
   */
  int  matches() const { return num_matches; }


  /** split a string into pieces
   * This method will split the given string into a vector
   * of strings using the compiled expression (given to the constructor).
   *
   * @param "piece" The string you want to split into it's parts.
   * @return an vector of strings
   * @see std::vector<std::string>
   * @see std::vector<std::string> split(const std::string& piece, int limit)
   * @see std::vector<std::string> split(const std::string& piece, int limit, int start_offset)
   * @see std::vector<std::string> split(const std::string& piece, int limit, int start_offset, int end_offset)
   * @see std::vector<std::string> split(const std::string& piece, std::vector<int> positions)
   */
  std::vector<std::string> split(const std::string& piece);

  /** split a string into pieces
   * This method will split the given string into a vector
   * of strings using the compiled expression (given to the constructor).
   *
   * @param "piece" The string you want to split into it's parts.
   * @param "limit" the maximum number of elements you want to get back from split().
   * @return an vector of strings
   * @see std::vector<std::string>
   * @see std::vector<std::string> split(const std::string& piece)
   * @see std::vector<std::string> split(const std::string& piece, int limit, int start_offset)
   * @see std::vector<std::string> split(const std::string& piece, int limit, int start_offset, int end_offset)
   * @see std::vector<std::string> split(const std::string& piece, std::vector<int> positions)
   */
  std::vector<std::string> split(const std::string& piece, int limit);

  /** split a string into pieces
   * This method will split the given string into a vector
   * of strings using the compiled expression (given to the constructor).
   *
   * @param "piece" The string you want to split into it's parts.
   * @param "limit" the maximum number of elements you want to get back from split().
   * @param "start_offset" at which substring the returned vector should start.
   * @return an vector of strings
   * @see std::vector<std::string>
   * @see std::vector<std::string> split(const std::string& piece)
   * @see std::vector<std::string> split(const std::string& piece, int limit)
   * @see std::vector<std::string> split(const std::string& piece, int limit, int start_offset, int end_offset)
   * @see std::vector<std::string> split(const std::string& piece, std::vector<int> positions)
   */
  std::vector<std::string> split(const std::string& piece, int limit, int start_offset);

  /** split a string into pieces
   * This method will split the given string into a vector
   * of strings using the compiled expression (given to the constructor).
   *
   * @param "piece" The string you want to split into it's parts.
   * @param "limit" the maximum number of elements you want to get back from split().
   * @param "start_offset" at which substring the returned vector should start.
   * @param "end_offset" at which substring the returned vector should end.
   * @return an vector of strings
   * @see std::vector<std::string> split(const std::string& piece)
   * @see std::vector<std::string> split(const std::string& piece, int limit)
   * @see std::vector<std::string> split(const std::string& piece, int limit, int start_offset)
   * @see std::vector<std::string> split(const std::string& piece, std::vector<int> positions)
   * @see std::vector<std::string>
   */
  std::vector<std::string> split(const std::string& piece, int limit, int start_offset, int end_offset);

  /** split a string into pieces
   * This method will split the given string into a vector
   * of strings using the compiled expression (given to the constructor).
   *
   * @param "piece" The string you want to split into it's parts.
   * @param "positions" a std::vector<int> of positions, which the returned vector should contain.
   * @return an vector of strings
   * @see std::vector<std::string> split(const std::string& piece)
   * @see std::vector<std::string> split(const std::string& piece, int limit)
   * @see std::vector<std::string> split(const std::string& piece, int limit, int start_offset)
   * @see std::vector<std::string> split(const std::string& piece, int limit, int start_offset)
   * @see std::vector<std::string>
   */
  std::vector<std::string> split(const std::string& piece, std::vector<int> positions);

  /** Replace parts of a string using regular expressions.
   * This method is the counterpart of the perl s/// operator.
   * It replaces the substrings which matched the given regular expression
   * (given to the constructor) with the supplied string.
   *
   * @param "piece" the string in which you want to search and replace.
   * @param "with"  the string which you want to place on the positions which match the expression (given to the constructor).
   */
  std::string replace(const std::string& piece, const std::string& with);

  /** Return pointer to underlying pcre object.
   * The pcre object allows you to access the pcre API directly.
   * E.g. if your are using pcre version 4.x and want to use the
   * new functionality which is currently not supported by pcre++.
   * An example would be: pcre_fullinfo(), pcre_study() or the
   * callout functionality.
   *
   * @return "pcre*" pointer to pcre object.
   * @see man pcre
   * @see pcre_extra* get_pcre_extra()
   */
  pcre* get_pcre();

  /** Return pointer to underlying pcre_extra structure.
   * The returned pcre_extra structure can be used in conjunction
   * with the pcre* object returned by pcre().
   *
   * @return "pcre_extra*" pointer to pcre_extra structure.
   * @see pcre* get_pcre()
   */
  pcre_extra* get_pcre_extra();

  /** Analyze pattern for speeding up the matching process.
   * When a pattern is going to be used several times, it  is  worth  spending  more
   * time  analyzing  it in order to speed up the time taken for matching.
   *
   * An excpetion will be thrown if analyzing the pattern failed.
   */
  void study();

  /** Sets locale for all character operations
   * Returns false if locale can't be set. Otherwise returns true
   * @param "locale" locale alias name you want to use.
   * @return true if setting locale were successful
   *
   * @see locale(1)
   */
  bool setlocale(const char* locale);

  /** Return substring of a match at a known possition using the array notation.
   * This method throws an out-of-range exception if the given position
   * is invalid.
   * @param "index" the position of the substring to return. Identical to perl's $1..$n.
   * @return the substring at the given position.
   *
   * Example:
   * @code
   * 
   * std::string mysub = regex[1]; 
   * 
   * @endcode
   * Get the first substring that matched the expression in the "regex" object.
   *
   * @see std::string get_match(int pos)
   */
  std::string operator[](int index) {
    return get_match(index);
  }
}; 

} // end namespace pcre

#endif // HAVE_PCRE_PP_H