Minsky
anonymous_namespace{CSVParser.cc} Namespace Reference

Classes

struct  Any
 An any with cached hash. More...
 
struct  DuplicateKey
 
struct  InvalidData
 
struct  MemoryExhausted
 
struct  NoDataColumns
 
struct  ShortLine
 
class  Tokens
 

Typedefs

using SliceLabelToken = uint32_t
 
using Key = vector< SliceLabelToken, LibCAllocator< SliceLabelToken > >
 
template<class V >
using Map = map< Key, V, less< Key >, LibCAllocator< pair< const Key, V > >>
 

Functions

double quotedStoD (const string &s, size_t &charsProcd)
 
string stripWSAndDecimalSep (const string &s)
 
size_t firstNumerical (const vector< string > &v)
 
bool emptyTail (const vector< string > &v, size_t start)
 

Typedef Documentation

◆ Key

using anonymous_namespace{CSVParser.cc}::Key = typedef vector<SliceLabelToken, LibCAllocator<SliceLabelToken> >

Definition at line 225 of file CSVParser.cc.

◆ Map

template<class V >
using anonymous_namespace{CSVParser.cc}::Map = typedef map<Key,V,less<Key>,LibCAllocator<pair<const Key,V> >>

Definition at line 226 of file CSVParser.cc.

◆ SliceLabelToken

using anonymous_namespace{CSVParser.cc}::SliceLabelToken = typedef uint32_t

Definition at line 224 of file CSVParser.cc.

Function Documentation

◆ emptyTail()

bool anonymous_namespace{CSVParser.cc}::emptyTail ( const vector< string > &  v,
size_t  start 
)

Definition at line 328 of file CSVParser.cc.

Referenced by minsky::DataSpec::processChunk().

329  {
330  for (size_t i=start; i<v.size(); ++i)
331  if (!v[i].empty()) return false;
332  return true;
333  }
Here is the caller graph for this function:

◆ firstNumerical()

size_t anonymous_namespace{CSVParser.cc}::firstNumerical ( const vector< string > &  v)

Definition at line 305 of file CSVParser.cc.

References quotedStoD(), and stripWSAndDecimalSep().

Referenced by minsky::DataSpec::processChunk().

306  {
307  size_t r=0;
308  for (size_t i=0; i<v.size(); ++i)
309  try
310  {
311  if (!v[i].empty())
312  {
313  size_t c=0;
314  auto s=stripWSAndDecimalSep(v[i]);
315  quotedStoD(s,c);
316  if (c!=s.size())
317  r=i+1;
318  }
319  }
320  catch (...)
321  {
322  r=i+1;
323  }
324  return r;
325  }
string stripWSAndDecimalSep(const string &s)
Definition: CSVParser.cc:294
double quotedStoD(const string &s, size_t &charsProcd)
Definition: CSVParser.cc:272
Here is the call graph for this function:
Here is the caller graph for this function:

◆ quotedStoD()

double anonymous_namespace{CSVParser.cc}::quotedStoD ( const string &  s,
size_t &  charsProcd 
)

Definition at line 272 of file CSVParser.cc.

Referenced by firstNumerical(), and minsky::isNumerical().

273  {
274  //strip possible quote characters
275  if (!s.empty() && s[0]==s[s.size()-1] && !isalnum(s[0]))
276  {
277  const double r=quotedStoD(s.substr(1,s.size()-2),charsProcd);
278  charsProcd+=2;
279  return r;
280  }
281  if (s.empty()) return nan(""); // treat empty cell as a missing value
282  // first try to read the cell as a number
283  try {
284  const double r=stod(s,&charsProcd);
285  if (charsProcd==s.size())
286  return r;
287  }
288  catch (...) {}
289  // if not, then strip any leading non-numerical characters ([^0-9.,+-])
290  auto n=s.find_first_of("0123456789,.+-");
291  return stod(s.substr(n),&charsProcd);
292  }
double quotedStoD(const string &s, size_t &charsProcd)
Definition: CSVParser.cc:272
Here is the caller graph for this function:

◆ stripWSAndDecimalSep()

string anonymous_namespace{CSVParser.cc}::stripWSAndDecimalSep ( const string &  s)

Definition at line 294 of file CSVParser.cc.

Referenced by firstNumerical(), and minsky::isNumerical().

295  {
296  string r;
297  for (auto c: s)
298  if (!isspace(c) && c!=',' && c!='.')
299  r+=c;
300  return r;
301  }
Here is the caller graph for this function: