Update of /cvsroot/objecthandler/ObjectHandler/oh
In directory sc8-pr-cvs3.sourceforge.net:/tmp/cvs-serv4318/oh
Modified Files:
utilities.cpp utilities.hpp
Log Message:
revised processing for ohParseFields()
Index: utilities.cpp
===================================================================
RCS file: /cvsroot/objecthandler/ObjectHandler/oh/utilities.cpp,v
retrieving revision 1.10
retrieving revision 1.11
diff -C2 -d -r1.10 -r1.11
*** utilities.cpp 30 Jun 2006 09:33:39 -0000 1.10
--- utilities.cpp 3 Jul 2006 08:19:26 -0000 1.11
***************
*** 26,30 ****
#include <sstream>
#include <boost/regex.hpp>
- #include <boost/lexical_cast.hpp>
namespace ObjHandler {
--- 26,29 ----
***************
*** 84,88 ****
// parse a whitespace-delimited list of symbols
// into a vector of strings
! std::vector<std::string> split(const std::string &line) {
std::vector<std::string> ret;
std::string::const_iterator start = line.begin();
--- 83,89 ----
// parse a whitespace-delimited list of symbols
// into a vector of strings
! std::vector<std::string> split(
! const std::string &line,
! unsigned int maxRequired) {
std::vector<std::string> ret;
std::string::const_iterator start = line.begin();
***************
*** 90,94 ****
boost::match_results<std::string::const_iterator> m;
static const boost::regex r("[^[:space:]]+");
! while (boost::regex_search(start, end, m, r)) {
ret.push_back(std::string(m[0].first, m[0].second));
start = m[0].second;
--- 91,95 ----
boost::match_results<std::string::const_iterator> m;
static const boost::regex r("[^[:space:]]+");
! while (maxRequired-- && boost::regex_search(start, end, m, r)) {
ret.push_back(std::string(m[0].first, m[0].second));
start = m[0].second;
***************
*** 97,129 ****
}
! double parseField(const std::string &line,
! const long &index /* index - 1-base for user, 0-base internally */ ) {
! if (index<1) {
! std::stringstream msg;
! msg << "the index of the requested field - " << index
! << " - is invalid - minimum value is 1.";
! throw Exception(msg.str());
! }
! unsigned int i = static_cast<unsigned int>(index);
! std::vector<std::string> fields = split(line);
! if (i>fields.size()) {
! std::stringstream msg;
! msg << "Error parsing string -" << std::endl
! << line << std::endl << "- requested field index " << i
! << " exceeds #fields (" << fields.size() << ") found in string";
! throw Exception(msg.str());
! }
! double ret;
! try {
! ret = boost::lexical_cast<double>(fields[i-1]);
! } catch (boost::bad_lexical_cast &) {
! std::stringstream msg;
! msg << "Error parsing string -" << std::endl
! << line << std::endl << "- requested field #" << i
! << " comprising text '" << fields[i-1]
! << "' could not be converted to a number";
! throw Exception(msg.str());
! }
! return ret;
}
--- 98,106 ----
}
! std::string uppercase(const std::string& s) {
! std::string output = s;
! for (std::string::iterator i=output.begin(); i!=output.end(); i++)
! *i = std::toupper(*i);
! return output;
}
Index: utilities.hpp
===================================================================
RCS file: /cvsroot/objecthandler/ObjectHandler/oh/utilities.hpp,v
retrieving revision 1.7
retrieving revision 1.8
diff -C2 -d -r1.7 -r1.8
*** utilities.hpp 30 Jun 2006 09:33:39 -0000 1.7
--- utilities.hpp 3 Jul 2006 08:19:26 -0000 1.8
***************
*** 26,29 ****
--- 26,30 ----
#include <oh/objhandlerdefines.hpp>
#include <string>
+ #include <vector>
namespace ObjHandler {
***************
*** 80,87 ****
void logAllObjects();
! //! Extract the ith number from a whitespace-delimited list of fields.
! /*! Used to parse data returned from Reuters function RtGet().
! */
! double parseField(const std::string &line, const long &i);
//@}
--- 81,89 ----
void logAllObjects();
! // some basic utilities
! std::vector<std::string> split(
! const std::string &line,
! unsigned int maxRequired);
! std::string uppercase(const std::string& s);
//@}
|