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

◆ range()

template<class T >
tfxx::Range<T> tfxx::string::range ( const std::string &  s)

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.

Definition at line 61 of file rangestring.h.

References gen_split().

62  {
63  typedef tfxx::Range<T> Trange;
64  typename Trange::Tvalue v1, v2;
65  std::list<std::string> slist;
66  tfxx::string::gen_split(slist, s, "-", true);
67  std::list<std::string>::const_iterator i=slist.begin();
68  std::istringstream iss(*i);
69  iss >> v1;
70  if (slist.size()>1)
71  {
72  ++i;
73  iss.str(*i);
74  // clear status after reading first number
75  iss.clear();
76  iss >> v2;
77  }
78  else
79  { v2=v1; }
80  Trange retval(v1,v2);
81  return retval;
82  } // tfxx::Range<T> range(const std::string& s)
A class to deal with numerical ranges.
Definition: range.h:50
void gen_split(C &v, const std::string &s, const std::string &delimiter=" ", const bool &dropdelimiter=false)
Definition: stringfunc.h:112
Here is the call graph for this function: