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

trimws operates well

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: 2889
SVN UUID:     67feda4a-a26e-11df-9d6e-31afc202ad0c
parent 25761f54
......@@ -3,7 +3,7 @@
*
* ----------------------------------------------------------------------------
*
* $Id: tsofttest.cc,v 1.11 2009-11-11 18:07:07 tforb Exp $
* $Id: tsofttest.cc,v 1.12 2009-11-12 07:23:55 tforb Exp $
* \author Thomas Forbriger
* \date 17/09/2009
*
......@@ -35,7 +35,7 @@
#define TSOFTTEST_VERSION \
"TSOFTTEST V1.0 test tsoft reading"
#define TSOFTTEST_CVSID \
"$Id: tsofttest.cc,v 1.11 2009-11-11 18:07:07 tforb Exp $"
"$Id: tsofttest.cc,v 1.12 2009-11-12 07:23:55 tforb Exp $"
#include <iostream>
#include <fstream>
......@@ -58,6 +58,14 @@ struct Options {
/*----------------------------------------------------------------------*/
std::string passtrimws(std::string line)
{
datread::tsoft::trimws(line);
return(line);
}
/*----------------------------------------------------------------------*/
int main(int iargc, char* argv[])
{
......@@ -178,11 +186,11 @@ int main(int iargc, char* argv[])
int count=0;
while (is.good())
{
getline(is, line);
line=datread::tsoft::getDOSline(is);
if (is.good())
{
datread::tsoft::Line theline(line);
cout << theline.theline() << endl;
cout << "<" << theline.theline() << ">" << endl;
if (theline.hastag())
{
indata=false;
......@@ -234,9 +242,11 @@ int main(int iargc, char* argv[])
{
if (opt.verbose)
{ cout << "test 2: test trimws" << endl; }
cout << "++++" << datread::tsoft::trimws(" hdj wed ") << "++++" << endl;
cout << "++++" << datread::tsoft::trimws(" hdj wed") << "++++" << endl;
cout << "++++" << datread::tsoft::trimws("hdj wed ") << "++++" << endl;
cout << "++++" << passtrimws(" hdj wed ") << "++++" << endl;
cout << "++++" << passtrimws(" hdj wed") << "++++" << endl;
cout << "++++" << passtrimws("hdj wed ") << "++++" << endl;
cout << "++++" << passtrimws(" ") << "++++" << endl;
cout << "++++" << passtrimws("") << "++++" << endl;
}
// end of test 2
......
......@@ -3,7 +3,7 @@
*
* ----------------------------------------------------------------------------
*
* $Id: channeltranslation.cc,v 1.3 2009-11-11 18:07:07 tforb Exp $
* $Id: channeltranslation.cc,v 1.4 2009-11-12 07:23:55 tforb Exp $
* \author Thomas Forbriger
* \date 11/11/2009
*
......@@ -35,7 +35,7 @@
#define DATREAD_CHANNELTRANSLATION_CC_VERSION \
"DATREAD_CHANNELTRANSLATION_CC V1.0 "
#define DATREAD_CHANNELTRANSLATION_CC_CVSID \
"$Id: channeltranslation.cc,v 1.3 2009-11-11 18:07:07 tforb Exp $"
"$Id: channeltranslation.cc,v 1.4 2009-11-12 07:23:55 tforb Exp $"
#include <iomanip>
#include <datreadxx/error.h>
......@@ -252,10 +252,12 @@ namespace datread {
SFFchannelid translate(const TSOFTchannelid& ci)
{
/*
std::cout << "translate: "
<< ci.location << ":"
<< ci.instrument << ":"
<< ci.datatype << ":" << std::endl;
*/
SFFchannelid retval;
retval.station=NSP;
retval.channel=NSP;
......@@ -271,10 +273,12 @@ namespace datread {
&& (tci.instrument==ci.instrument)
&& (tci.datatype==ci.datatype))
{
/*
std::cout << "found: "
<< tci.location << ":"
<< tci.instrument << ":"
<< tci.datatype << ":" << std::endl;
*/
SFFchannelid sci=schannelid(*pc);
retval.station=sci.station;
retval.channel=sci.channel;
......
......@@ -3,7 +3,7 @@
*
* ----------------------------------------------------------------------------
*
* $Id: tsoftdata.cc,v 1.12 2009-11-11 18:15:09 tforb Exp $
* $Id: tsoftdata.cc,v 1.13 2009-11-12 07:23:55 tforb Exp $
* \author Thomas Forbriger
* \date 16/09/2009
*
......@@ -35,7 +35,7 @@
#define DATREAD_TSOFTDATA_CC_VERSION \
"DATREAD_TSOFTDATA_CC V1.0 "
#define DATREAD_TSOFTDATA_CC_CVSID \
"$Id: tsoftdata.cc,v 1.12 2009-11-11 18:15:09 tforb Exp $"
"$Id: tsoftdata.cc,v 1.13 2009-11-12 07:23:55 tforb Exp $"
#include <datreadxx/error.h>
#include <datreadxx/tsoftdata.h>
......@@ -86,7 +86,8 @@ namespace datread {
if (j <len)
{
Mhascontent=true;
Mcontent=trimws(line.substr(j,len-j+1));
Mcontent=line.substr(j,len-j+1);
trimws(Mcontent);
}
}
}
......@@ -236,7 +237,8 @@ namespace datread {
const libtime::TRelativeTime& dt,
const bool& debug)
{
std::string theundetval=trimws(undetval);
std::string theundetval(undetval);
trimws(theundetval);
Dataline thedata(line);
if (debug)
{
......@@ -247,7 +249,8 @@ namespace datread {
}
for (int ich=0; ich<thedata.nsamples(); ++ich)
{
std::string thesample=trimws(thedata.sample(ich));
std::string thesample(thedata.sample(ich));
trimws(thesample);
if (debug)
{
std::cout << " sample: " << thesample << std::endl;
......@@ -297,13 +300,30 @@ namespace datread {
/*----------------------------------------------------------------------*/
//! helper function trimws
std::string trimws(const std::string& line)
void trimws(std::string& line)
{
string::size_type ib=line.find_first_not_of(" ", 0);
string::size_type il=line.find_last_not_of(" ", line.length());
il=il<ib ? ib : il;
return (line.substr(ib,il-ib+1));
} // std::string trimws(const std::string& line)
// std::cout << "<" << line << ">" << std::endl;
if (line.length()>0)
{
// std::cout << line.length() << " > 0" << std::endl;
string::size_type ib=line.find_first_not_of(" ", 0);
if (ib==string::npos)
{
line="";
}
else
{
string::size_type il=line.find_last_not_of(" \r", line.length());
string::size_type n=il>=ib ? il-ib+1 : 0;
if (n==0) { ib = 0; }
/*
std::cout << "ib = " << ib << "; il = " << il <<
"; n = " << n << std::endl;
*/
if ((ib!=0) || (n!=line.length())) { line=line.substr(ib,n); }
}
}
} // trimws(std::string& line)
/*----------------------------------------------------------------------*/
......@@ -333,8 +353,9 @@ namespace datread {
std::string inputline;
getline(is, inputline);
// check for DOS file
inputline.replace(inputline.find("\r"), 1, "");
return(trimws(inputline));
// inputline.replace(inputline.find("\r"), 1, "");
trimws(inputline);
return(inputline);
} // std::string getDOSline(std::istream& is)
} // namespace tsoft
......
......@@ -3,7 +3,7 @@
*
* ----------------------------------------------------------------------------
*
* $Id: tsoftdata.h,v 1.13 2009-11-11 18:15:09 tforb Exp $
* $Id: tsoftdata.h,v 1.14 2009-11-12 07:23:55 tforb Exp $
* \author Thomas Forbriger
* \date 16/09/2009
*
......@@ -39,7 +39,7 @@
#define DATREAD_TSOFTDATA_H_VERSION \
"DATREAD_TSOFTDATA_H V1.0 "
#define DATREAD_TSOFTDATA_H_CVSID \
"$Id: tsoftdata.h,v 1.13 2009-11-11 18:15:09 tforb Exp $"
"$Id: tsoftdata.h,v 1.14 2009-11-12 07:23:55 tforb Exp $"
#include<iostream>
#include<string>
......@@ -121,7 +121,7 @@ namespace datread {
/*! \brief helper function trimws
* \ingroup tsoft
*/
std::string trimws(const std::string& line);
void trimws(std::string& line);
/*----------------------------------------------------------------------*/
......@@ -174,7 +174,11 @@ namespace datread {
//! set channel info
void setchannelinfo(const std::string& line);
//! set unit info
void setunits(const std::string& line) { Munits=trimws(line); }
void setunits(const std::string& line)
{
Munits=line;
trimws(Munits);
}
//! return location
const std::string& thelocation() const { return Mlocation; }
//! return instrument
......
......@@ -3,7 +3,7 @@
*
* ----------------------------------------------------------------------------
*
* $Id: tsoftreader.cc,v 1.11 2009-11-11 18:15:09 tforb Exp $
* $Id: tsoftreader.cc,v 1.12 2009-11-12 07:23:55 tforb Exp $
* \author Thomas Forbriger
* \date 16/09/2009
*
......@@ -35,7 +35,7 @@
#define DATREAD_TSOFTREADER_CC_VERSION \
"DATREAD_TSOFTREADER_CC V1.0 "
#define DATREAD_TSOFTREADER_CC_CVSID \
"$Id: tsoftreader.cc,v 1.11 2009-11-11 18:15:09 tforb Exp $"
"$Id: tsoftreader.cc,v 1.12 2009-11-12 07:23:55 tforb Exp $"
#include <iostream>
#include <sstream>
......@@ -102,10 +102,11 @@ namespace datread {
bool inunits=false;
std::string inputline;
inputline=getDOSline(is);
if (debug) { std::cout << "<" << inputline << ">" << endl; }
while (is.good())
{
int linelength=datread::tsoft::trimws(inputline).length();
datread::tsoft::Line theline(inputline);
int linelength=theline.theline().length();
if ((!indata) && (linelength > 0))
{ Mfree.push_back(theline.theline()); }
if (theline.hastag() && (linelength > 0))
......@@ -205,6 +206,7 @@ namespace datread {
}
// read next line
inputline=getDOSline(is);
if (debug) { std::cout << "<" << inputline << ">" << endl; }
} // while (is.good())
// file is read
// check if input is complete
......
......@@ -3,7 +3,7 @@
*
* ----------------------------------------------------------------------------
*
* $Id: tsoftsffcontainer.cc,v 1.3 2009-11-11 18:07:07 tforb Exp $
* $Id: tsoftsffcontainer.cc,v 1.4 2009-11-12 07:23:55 tforb Exp $
* \author Thomas Forbriger
* \date 11/11/2009
*
......@@ -35,7 +35,7 @@
#define DATREAD_TSOFTSFFCONTAINER_CC_VERSION \
"DATREAD_TSOFTSFFCONTAINER_CC V1.0 "
#define DATREAD_TSOFTSFFCONTAINER_CC_CVSID \
"$Id: tsoftsffcontainer.cc,v 1.3 2009-11-11 18:07:07 tforb Exp $"
"$Id: tsoftsffcontainer.cc,v 1.4 2009-11-12 07:23:55 tforb Exp $"
#include <datreadxx/tsoftsffcontainer.h>
#include <datreadxx/tsoftreader.h>
......@@ -95,10 +95,12 @@ namespace datread {
tci.location=ci.thelocation();
tci.instrument=ci.theinstrument();
tci.datatype=ci.thedatatype();
/*
std::cout << "translate: "
<< tci.location << ":"
<< tci.instrument << ":"
<< tci.datatype << ":" << std::endl;
*/
SFFchannelid sci=translate(tci);
I->Mwid2.station=sci.station;
......
Supports Markdown
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