VR-Forces 4.8 Class Documentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
csvUtil.h
Go to the documentation of this file.
1 /*******************************************************************************
2 ** Copyright (c) 2005 MAK Technologies, Inc.
3 ** All rights reserved.
4 *******************************************************************************/
5 /*******************************************************************************
6 ** $RCSfile: parseCSV.h,v $ $Revision: 1.1 $ $State: Exp $
7 *******************************************************************************/
8 
11 
12 
13 #pragma once
14 
15 #include <string>
16 
21 
22 template <typename Container>
23 void parseCsv (Container &container, std::string const &in)
24 {
25  const std::string::size_type len = in.length();
26  std::string::size_type i = 0;
27  std::string::size_type j = 0;
28 
29  while ( j < len )
30  {
31  i = in.find_first_of(",", i);
32  if (i == std::string::npos)
33  {
34  container.push_back(in.substr(j, len));
35  return;
36  }
37  if (i == j)
38  {
39  container.push_back("");
40  }
41  else
42  {
43  container.push_back(in.substr(j, i-j));
44  }
45  i++;
46  j=i;
47  }
48 }
void parseCsv(Container &container, std::string const &in)
This was adapted from an improved strtok function from the gnu libstdc++ FAQ : http://gcc.gnu.org/onlinedocs/libstdc++/21_strings/stringtok_h.txt It was changed to leave whitespace alone, and insert nulls into the list for empty fields (i.e.
Definition: csvUtil.h:23

Document ID: Generated on Thu Aug 27 10:56:05 EDT 2020 from SVN revision 217100
Copyright © 2005-2020 MAK Technologies. All Rights Reserved (www.mak.com)