Files
poco/Foundation/samples/grep/src/grep.cpp
Roger Meier b0581433a7 LICENSE: add info about SPDX-License-Identifier usage and use it
fix: remove executable flag and change back to 100644 (was 100755)

Signed-off-by: Roger Meier <r.meier@siemens.com>
2014-05-14 08:38:09 +02:00

64 lines
1.1 KiB
C++

//
// grep.cpp
//
// $Id: //poco/1.4/Foundation/samples/grep/src/grep.cpp#1 $
//
// This sample demonstrates the RegularExpression class.
//
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// SPDX-License-Identifier: BSL-1.0
//
#include "Poco/RegularExpression.h"
#include <iostream>
using Poco::RegularExpression;
int main(int argc, char** argv)
{
if (argc < 2)
{
std::cout << "usage: " << argv[0] << ": [-i] [-x] pattern" << std::endl;
return 1;
}
std::string pattern;
int options = 0;
for (int i = 1; i < argc; ++i)
{
std::string arg(argv[i]);
if (arg == "-i")
options += RegularExpression::RE_CASELESS;
else if (arg == "-x")
options += RegularExpression::RE_EXTENDED;
else
pattern = arg;
}
RegularExpression re(pattern, options);
int c = std::cin.get();
while (c != -1)
{
std::string line;
while (c != -1 && c != '\n')
{
line += (char) c;
c = std::cin.get();
}
RegularExpression::Match mtch;
if (re.match(line, mtch))
std::cout << line << std::endl;
if (c != -1) c = std::cin.get();
}
return 0;
}