File: search_demo.cc

package info (click to toggle)
libpcre%2B%2B 0.9.5-3
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 2,608 kB
  • ctags: 211
  • sloc: sh: 9,165; cpp: 835; makefile: 78
file content (39 lines) | stat: -rw-r--r-- 803 bytes parent folder | download | duplicates (5)
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
#include <string>
#include "../libpcre++/pcre++.h"

using namespace std;
using namespace pcrepp;

void usage();

int main(int argc, char *argv[]) {
  if(argc <2)
    usage();
  else {
    string search  = argv[1];

    Pcre expression(search, PCRE_GLOBAL | PCRE_CASELESS);

    string input;

    cout << "> ";
    while(getline(cin, input)) {
      if(expression.search(input) == true)
	cout << "true" << endl;
      else
	cout << "false" << endl;
      cout << "> ";
    }
  }
  return true;
}

void usage() {
  cout << endl
       << "Usage: search <search-for>\n"
       << "search must be a regular expression.\n"
       << "Every line on STDIN will then searched\n"
       << "for 'search-for'. If a match is found,\n"
       << "'true' will be printed, 'false' otherwise." << endl;
  exit(-1);
}