solarpowerlog trunk
/home/tobi/workspace/solarpowerlog/src/DataFilters/HTMLWriter/formatter/CFormatterSearchCSVEntry.cpp
Go to the documentation of this file.
00001 /*
00002  * CFormatterSearchCSVEntry.cpp
00003  *
00004  *  Created on: Jan 5, 2010
00005  *      Author: tobi
00006  */
00007 
00008 #include "DataFilters/HTMLWriter/formatter/CFormatterSearchCSVEntry.h"
00009 
00010 #include <sstream>
00011 
00012 using namespace std;
00013 
00014 bool CFormatterSearchCSVEntry::Format(const std::string & what,
00015           std::string & store, const std::vector<std::string> & parameters)
00016 {
00017      // the task is to get a comma-seperated value by what
00018      // and extract the position for the element given by the parameter
00019      // [2] and store the number in store.
00020      std::string s;
00021 
00022      try {
00023           s = parameters[2];
00024      } catch (...) {
00025           return false;
00026      }
00027 
00028      // What we got:
00029      // value, value2, value3
00030      // We count the seperators, and we are set.
00031 
00032      size_t pos = what.find(s);
00033 
00034      if (pos == std::string::npos)
00035           return false;
00036 
00037      int count = 0;
00038      for (size_t i = 0; i < pos; i++) {
00039           if (what[i] == ',' && (i == 0 || what[i - 1] != '\\')) {
00040                count++;
00041           }
00042      }
00043 
00044      std::stringstream ss;
00045      ss << count;
00046      ss >> store;
00047 
00048      return true;
00049 }
00050 
00051 CFormatterSearchCSVEntry::CFormatterSearchCSVEntry()
00052 {
00053      // TODO Auto-generated constructor stub
00054 
00055 }
00056 
00057 CFormatterSearchCSVEntry::~CFormatterSearchCSVEntry()
00058 {
00059      // TODO Auto-generated destructor stub
00060 }