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

rangestring works

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: 1797
SVN UUID:     67feda4a-a26e-11df-9d6e-31afc202ad0c
parent ff89da77
......@@ -3,7 +3,7 @@
*
* ----------------------------------------------------------------------------
*
* $Id: rangelist.h,v 1.1 2005-07-01 07:40:41 tforb Exp $
* $Id: rangelist.h,v 1.2 2005-07-04 10:41:06 tforb Exp $
* \author Thomas Forbriger
* \date 30/06/2005
*
......@@ -23,7 +23,7 @@
#define TF_RANGELIST_H_VERSION \
"TF_RANGELIST_H V1.0 "
#define TF_RANGELIST_H_CVSID \
"$Id: rangelist.h,v 1.1 2005-07-01 07:40:41 tforb Exp $"
"$Id: rangelist.h,v 1.2 2005-07-04 10:41:06 tforb Exp $"
#include<tfxx/range.h>
#include<list>
......@@ -46,7 +46,7 @@ namespace tfxx {
{
bool retval=false;
typename Tlist::const_iterator i=Mlist.begin();
while ((i!=Mist.end()) && (!retval))
while ((i!=Mlist.end()) && (!retval))
{ retval = i->contains(v); ++i; }
return retval;
}
......
......@@ -3,7 +3,7 @@
*
* ----------------------------------------------------------------------------
*
* $Id: rangestring.h,v 1.1 2005-07-01 07:40:41 tforb Exp $
* $Id: rangestring.h,v 1.2 2005-07-04 10:41:06 tforb Exp $
* \author Thomas Forbriger
* \date 30/06/2005
*
......@@ -23,7 +23,7 @@
#define TF_RANGESTRING_H_VERSION \
"TF_RANGESTRING_H V1.0 "
#define TF_RANGESTRING_H_CVSID \
"$Id: rangestring.h,v 1.1 2005-07-01 07:40:41 tforb Exp $"
"$Id: rangestring.h,v 1.2 2005-07-04 10:41:06 tforb Exp $"
#include<tfxx/range.h>
#include<tfxx/rangelist.h>
......@@ -35,7 +35,12 @@ namespace tfxx {
namespace string {
/* read range from string */
/*! read range from string
*
* The string may contain a single number or a range in a format like
* "5-19". Open ranges (like "3-" or "-18") as well as negative values are
* not supported.
*/
template<class T>
tfxx::Range<T> range(const std::string& s)
{
......@@ -47,14 +52,24 @@ namespace tfxx {
std::istringstream iss(*i);
iss >> v1;
if (slist.size()>1)
{ ++i; iss.str(*i); iss >> v2; }
{
++i;
iss.str(*i);
// clear status after reading first number
iss.clear();
iss >> v2;
}
else
{ v2=v1; }
Trange retval(v1,v2);
return retval;
}
/* read rangelist from string */
/*! read rangelist from string
*
* Reads a comma separated list of range strings an passes tham to the
* range reading function to build a list of ranges.
*/
template<class T>
tfxx::RangeList<T> rangelist(const std::string& s)
{
......
......@@ -3,7 +3,7 @@
*
* ----------------------------------------------------------------------------
*
* $Id: stringtest.cc,v 1.1 2005-07-01 07:40:42 tforb Exp $
* $Id: stringtest.cc,v 1.2 2005-07-04 10:41:07 tforb Exp $
* \author Thomas Forbriger
* \date 30/06/2005
*
......@@ -19,7 +19,7 @@
#define STRINGTEST_VERSION \
"STRINGTEST V1.0 test string functions"
#define STRINGTEST_CVSID \
"$Id: stringtest.cc,v 1.1 2005-07-01 07:40:42 tforb Exp $"
"$Id: stringtest.cc,v 1.2 2005-07-04 10:41:07 tforb Exp $"
#include <iostream>
#include <tfxx/commandline.h>
......@@ -113,6 +113,12 @@ int main(int iargc, char* argv[])
std::cout << *i << std::endl;
++i;
}
std::cout << "values contained in all ranges:" << std::endl;
for (int i=1; i<=100; ++i)
{
if (rnglist.contains(i)) { std::cout << i << " "; }
}
std::cout << std::endl;
}
}
......
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