Commit 84927510 authored by thomas.forbriger's avatar thomas.forbriger Committed by thomas.forbriger
Browse files

implemented string stripper for parameter strings

This is a legacy commit from before 2015-03-01.
It may be incomplete as well as inconsistent.
See COPYING.legacy and README.history for details.

SVN Path:     http://gpitrsvn.gpi.uni-karlsruhe.de/repos/TFSoftware/trunk
SVN Revision: 3920
SVN UUID:     67feda4a-a26e-11df-9d6e-31afc202ad0c
parent 7625a8ab
......@@ -62,6 +62,9 @@ TESTHEADERS=$(wildcard tests/*.h)
TESTCCSRC=$(wildcard tests/*.cc)
TESTCSRC=$(wildcard tests/*.c)
TESTCCBIN=$(patsubst tests/%.cc,%,$(TESTCCSRC))
TESTCBIN=$(patsubst tests/%.c,%,$(TESTCSRC))
INCINSTALLPATH=$(LOCINCLUDEDIR)/stfinv
LIBINSTALLPATH=$(LOCLIBDIR)
......@@ -91,7 +94,7 @@ CXXFLAGS+=-Wall $(FLAGS)
LDFLAGS+=-L$(LOCLIBDIR)
CPPFLAGS+=-I$(LOCINCLUDEDIR) $(FLAGS)
EDITFILES=Makefile README $(wildcard *.cfg *.h *.cc *.c)
EDITFILES=Makefile README $(wildcard *.cfg *.h *.cc *.c tests/*.cc tests/*.c)
flist: $(EDITFILES)
echo $^ | tr ' ' '\n' | sort > $@
......@@ -106,7 +109,7 @@ clean: ;
-find . -name \*.d | xargs --no-run-if-empty /bin/rm -v
-find . -name \*.hd | xargs --no-run-if-empty /bin/rm -v
-find . -name \*.strip | xargs --no-run-if-empty /bin/rm -v
-/bin/rm -vf flist *.a *.so *.xxx
-/bin/rm -vf flist *.a *.so *.xxx $(TESTCBIN) $(TESTCCBIN)
#======================================================================
# pattern rules
......@@ -241,11 +244,9 @@ endif
# test code
# ---------
writetest sactest hpmotest mseedtest pdastest tfasciitest\
tsofttest sfftest sutest: %: tests/%.o libdatrwxx.a
$(CXX) $(FLAGS) -o $@ $< -I$(LOCINCLUDEDIR) \
-ldatrwxx -lsffxx -lgsexx -ltsxx -ltfxx -laff -ltime++ \
$(TESTCCBIN): %: tests/%.o libstfinv.a
$(CXX) $(FLAGS) -o $@ $^ -I$(LOCINCLUDEDIR) \
-ltfxx -laff \
-L$(LOCLIBDIR)
/bin/mv -fv $@ $(LOCBINDIR)
# ----- END OF Makefile -----
......@@ -38,10 +38,21 @@
#define STFINV_PARAMETERHANDLER_CC_CVSID \
"$Id$"
#include<iostream>
#include <stfinv/parameterhandler.h>
namespace stfinv {
} // namespace stfinv
std::string stfinv::tools::clipstring(std::string& s, const std::string& delim)
{
std::string::size_type i=s.find(delim);
std::string result;
if ((i>=0) && (i<s.length())) {
result=s.substr(0,i);
s.erase(0,i+delim.length());
} else {
result=s;
s.erase();
}
return(result);
}
/* ----- END OF parameterhandler.cc ----- */
......@@ -42,8 +42,30 @@
#define STFINV_PARAMETERHANDLER_H_CVSID \
"$Id$"
#include <string>
namespace stfinv {
/*! \brief Namespace for internal tools
* \ingroup tools
*/
namespace tools {
/*! strip substring
* \ingroup tools
*
* Strips off first substring up to given delimiter.
* The string is passed as a reference and will be modified (i.e. the
* stripped substring as well as the delimiter will be erased).
*
* \param s input string
* \param delim delimiter to look for
* \return first part of string up to delimiter
*/
std::string clipstring(std::string& s, const std::string& delim=":");
} // namespace tools
} // namespace stfinv
#endif // STFINV_PARAMETERHANDLER_H_VERSION (includeguard)
......
This is a legacy version of the repository. It may be incomplete as well as
inconsistent. See README.history for details. For the old stock of the
repository copyright and licence conditions apply as specified for versions
commited after 2015-03-01. Use recent versions as a base for new development.
The legacy version is only stored to keep a record of history.
/*! \file tooltest.cc
* \brief test internal tools
*
* ----------------------------------------------------------------------------
*
* $Id$
* \author Thomas Forbriger
* \date 07/05/2011
*
* test internal tools
*
* Copyright (c) 2011 by Thomas Forbriger (BFO Schiltach)
*
* ----
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
* ----
*
*
* REVISIONS and CHANGES
* - 07/05/2011 V1.0 Thomas Forbriger
*
* ============================================================================
*/
#define TOOLTEST_VERSION \
"TOOLTEST V1.0 test internal tools"
#define TOOLTEST_CVSID \
"$Id$"
#include <iostream>
#include <tfxx/commandline.h>
#include <stfinv/parameterhandler.h>
using std::cout;
using std::cerr;
using std::endl;
/*----------------------------------------------------------------------*/
struct Options {
bool testclip, verbose;
std::string clipstring;
}; // struct Options
/*----------------------------------------------------------------------*/
int main(int iargc, char* argv[])
{
// define usage information
char usage_text[]=
{
TOOLTEST_VERSION "\n"
"usage: tooltest [-clip string]" "\n"
" or: tooltest --help|-h" "\n"
};
// define full help text
char help_text[]=
{
TOOLTEST_CVSID
};
// define commandline options
using namespace tfxx::cmdline;
static Declare options[]=
{
// 0: print help
{"help",arg_no,"-"},
// 1: verbose mode
{"v",arg_no,"-"},
// 2: verbose mode
{"clip",arg_yes,"-"},
{NULL}
};
// no arguments? print usage...
if (iargc<2)
{
cerr << usage_text << endl;
exit(0);
}
// collect options from commandline
Commandline cmdline(iargc, argv, options);
// help requested? print full help text...
if (cmdline.optset(0))
{
cerr << usage_text << endl;
cerr << help_text << endl;
exit(0);
}
Options opt;
opt.verbose=cmdline.optset(1);
opt.testclip=cmdline.optset(2);
opt.clipstring=cmdline.string_arg(2);
// dummy operation: print rest of command line
if (opt.verbose)
{
cout << "part of command line which was not parsed:" << endl;
}
while (cmdline.extra()) { cout << cmdline.next() << endl; }
/*----------------------------------------------------------------------*/
if (opt.testclip)
{
if (opt.verbose)
{
cout << endl;
cout << "Test stfinv::tools::clipstring with default delimiter"
<< endl;
}
std::string s=opt.clipstring;
cout << "remainder is: " << s << endl;
while (s.length()>0)
{
cout << "stripped off: " << stfinv::tools::clipstring(s) << endl;
cout << "remainder is: " << s << endl;
}
std::string delim="++";
if (opt.verbose)
{
cout << endl;
cout << "Test stfinv::tools::clipstring with delimiter "
<< delim << endl;
}
s=opt.clipstring;
cout << "remainder is: " << s << endl;
while (s.length()>0)
{
cout << "stripped off: " << stfinv::tools::clipstring(s,delim) << endl;
cout << "remainder is: " << s << endl;
}
} // if (opt.testclip)
/*----------------------------------------------------------------------*/
}
/* ----- END OF tooltest.cc ----- */
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment