TF++, Miscellaneous classes and modules in C++:

◆ main()

int main ( int  iargc,
char *  argv[] 
)

Definition at line 65 of file stringtest.cc.

References tfxx::cmdline::arg_no, tfxx::cmdline::arg_yes, tfxx::string::gen_split(), tfxx::RangeList< T >::list(), tfxx::cmdline::Commandline::optset(), tfxx::string::patsubst(), Options::patsubsttest, Options::rangestring, Options::rangetest, Options::splittest, tfxx::cmdline::Commandline::string_arg(), and STRINGTEST_VERSION.

66 {
67 
68  // define usage information
69  char usage_text[]=
70  {
72  "usage: stringtest [-r r] [-p] [-s]" "\n"
73  " or: stringtest --help|-h" "\n"
74  };
75 
76  // define full help text
77  char help_text[]=
78  {
79  STRINGTEST_CVSID
80  "-r r read ranges from \'r\'" "\n"
81  "-p test pattern substitution" "\n"
82  "-s split functions" "\n"
83  };
84 
85  // define commandline options
86  using namespace tfxx::cmdline;
87  static Declare options[]=
88  {
89  // 0: print help
90  {"help",arg_no,"-"},
91  // 1: verbose mode
92  {"v",arg_no,"-"},
93  // 2: test range reading
94  {"r",arg_yes,"-"},
95  // 3: pattern substitution
96  {"p",arg_no,"-"},
97  // 4: string split function
98  {"s",arg_no,"-"},
99  {NULL}
100  };
101 
102  // no arguments? print usage...
103  if (iargc<2)
104  {
105  cerr << usage_text << endl;
106  exit(0);
107  }
108 
109  // collect options from commandline
110  Commandline cmdline(iargc, argv, options);
111 
112  // help requested? print full help text...
113  if (cmdline.optset(0))
114  {
115  cerr << usage_text << endl;
116  cerr << help_text << endl;
117  exit(0);
118  }
119 
120  Options opt;
121  opt.rangetest=cmdline.optset(2);
122  opt.rangestring=cmdline.string_arg(2);
123  opt.patsubsttest=cmdline.optset(3);
124  opt.splittest=cmdline.optset(4);
125 
126  /*----------------------------------------------------------------------*/
127  if (opt.splittest)
128  {
129  std::string a("a:bc:def:ghij");
130  std::list<std::string> splitted;
131  tfxx::string::gen_split(splitted, a, ":", true);
132  cout << a << " is splitted to:" << endl;
133  for (std::list<std::string>::const_iterator I=splitted.begin();
134  I!=splitted.end(); ++I)
135  {
136  cout << *I << endl;
137  }
138  }
139 
140  /*----------------------------------------------------------------------*/
141  if (opt.rangetest)
142  {
143  typedef tfxx::RangeList<int> Trangelist;
144  Trangelist
145  rnglist=tfxx::string::rangelist<Trangelist::Tvalue>(opt.rangestring);
146  Trangelist::Tlist rlist=rnglist.list();
147  Trangelist::Tlist::const_iterator i=rlist.begin();
148  while (i!=rlist.end())
149  {
150  std::cout << *i << std::endl;
151  ++i;
152  }
153  std::cout << "values contained in all ranges:" << std::endl;
154  for (int i=1; i<=100; ++i)
155  {
156  if (rnglist.contains(i)) { std::cout << i << " "; }
157  }
158  std::cout << std::endl;
159  }
160 
161  /*----------------------------------------------------------------------*/
162 
163  // pattern substitution test
164  if (opt.patsubsttest)
165  {
166  {
167  std::string s=
168  "This is a string that will be modified by string functions";
169  std::string p="string";
170  std::string r="nonsense";
171  std::cout << s << std::endl;
172  std::cout << tfxx::string::patsubst(s,p,r) << std::endl;
173  }
174  {
175  std::string s=
176  "% <- front middle -> % and end -> %";
177  std::string p="%";
178  std::string r="****";
179  std::cout << s << std::endl;
180  std::cout << tfxx::string::patsubst(s,p,r) << std::endl;
181  }
182  } // pattern substitution test
183 }
bool splittest
Definition: stringtest.cc:50
std::string rangestring
Definition: stringtest.cc:51
bool rangetest
Definition: stringtest.cc:50
option requires an argument
Definition: commandline.h:102
bool patsubsttest
Definition: stringtest.cc:50
std::string patsubst(const std::string &s, const std::string &p, const std::string &r)
Definition: stringfunc.cc:160
void gen_split(C &v, const std::string &s, const std::string &delimiter=" ", const bool &dropdelimiter=false)
Definition: stringfunc.h:112
Namespace containing all components of module commandline. ,.
Definition: commandline.cc:41
Tlist list() const
Definition: rangelist.h:67
Evaluates commandline by calling long_getopt. ,You may instantiate a Commandline object by passing th...
Definition: commandline.h:201
#define STRINGTEST_VERSION
Definition: stringtest.cc:35
struct to define options ,This struct is used to define a list of options. An example is: ...
Definition: commandline.h:136
option has no argument
Definition: commandline.h:100
Here is the call graph for this function: