ewmscp  ..
Functions
escaper.cpp File Reference

(v0.19-24-g0617ca1 with changes)

#include <fstream>
#include <memory>
#include "escapism.h"
Include dependency graph for escaper.cpp:

Go to the source code of this file.

Functions

int main (int argc, const char *argv[])
 

Function Documentation

◆ main()

int main ( int  argc,
const char *  argv[] 
)

Definition at line 8 of file escaper.cpp.

8  {
9  options::parser parser("", "", {});
10  options::single<std::string> escaperType('e', "escaper", "type of escaper", "Url");
12  options::single<bool> unEscape('d',"unescape","unescape the input");
13  options::single<bool> noNewline('n',"nonewline","don't add newlines");
14  options::single<char> inputSep('i',"inputSep","input separator",'\n');
15  options::single<char> outputSep('o',"outputSep","output separator",'\n');
16  options::container<std::string> files('f',"files","files to read input from, '-' is stdin");
17  options::positional<options::container<std::string>> strings(10, "strings", "strings");
18  parser.fParse(argc,argv);
19 
20  auto escaper = escapism::newEscaper(escaperType);
21 
22  for (const auto& in: strings) {
23  std::string out;
24  if (unEscape) {
25  escaper->deEscape(in,out);
26  } else {
27  escaper->escape(in,out);
28  }
29  std::cout << out;
30  if (!noNewline) {
31  std::cout << outputSep;
32  }
33  }
34 
35  for (const auto& f: files) {
36  std::unique_ptr<std::istream> in;
37  if (f == "-") {
38  in.reset(&std::cin);
39  } else {
40  in.reset(new std::ifstream(f));
41  }
42  for (std::string line; std::getline(*in, line, inputSep.fGetValue());) {
43  std::string out;
44  if (unEscape) {
45  escaper->deEscape(line,out);
46  } else {
47  escaper->escape(line,out);
48  }
49  std::cout << out;
50  if (!noNewline) {
51  std::cout << outputSep;
52  }
53  }
54  }
55 }

References escapism::addAllowedNamesToOption(), f(), options::single< T >::fGetValue(), and escapism::newEscaper().

Here is the call graph for this function:
options::parser
class that contains the parser, i.e. does that option handling
Definition: Options.h:363
options::single< std::string >
options::single< bool >
class specialisation for options of type bool
Definition: Options.h:595
options::container< std::string >
escapism::addAllowedNamesToOption
static void addAllowedNamesToOption(options::single< std::string > &option)
Definition: escapism.cpp:31
escapism::newEscaper
static const escapism * newEscaper(const std::string &name)
Definition: escapism.cpp:25
options::positional
Definition: Options.h:876
f
int f(int a, int line)
Definition: cctest.cpp:4