COOPY » Guide  version 0.6.5
/home/paulfitz/cvs/coopy_scm/coopy/src/libcoopy_core/include/coopy/Stringer.h
Go to the documentation of this file.
00001 #ifndef COOPY_STRINGER
00002 #define COOPY_STRINGER
00003 
00004 #include <string>
00005 #include <list>
00006 #include <coopy/SheetCell.h>
00007 
00008 #ifdef WANT_MAP2STRING
00009 #include <map>
00010 #include <string>
00011 std::string stringify(const std::string& x);
00012 std::string stringify(const coopy::store::SheetCell& x);
00013 template <class T1, class T2>
00014 std::string map2string(const std::map<T1,T2>& src) {
00015   std::string result = "";
00016   for (typename std::map<T1,T2>::const_iterator it=src.begin(); it!=src.end(); it++) {
00017     if (it!=src.begin()) {
00018       result += " ";
00019     }
00020     result += it->first;
00021     result += ":";
00022     result += stringify(it->second);
00023   }
00024   return result;
00025 }
00026 #endif
00027 
00028 std::string stringer_encoder(bool x);
00029 std::string stringer_encoder(int x);
00030 std::string stringer_encoder(const std::string& x);
00031 std::string stringer_encoder(const coopy::store::SheetCell& x);
00032 
00033 #ifdef WANT_VECTOR2STRING
00034 #include <vector>
00035 #include <string>
00036 template <class T>
00037 std::string vector2string(const std::vector<T>& src) {
00038   std::string result = "";
00039   for (typename std::vector<T>::const_iterator it=src.begin(); it!=src.end(); it++) {
00040     if (it!=src.begin()) {
00041       result += " ";
00042     }
00043     result += stringer_encoder(*it);
00044   }
00045   return result;
00046 }
00047 #endif
00048 
00049 
00050 class Stringer {
00051 public:
00052   static void split(const std::string& str, 
00053                     const std::string& delimiters, 
00054                     std::list<std::string>& tokens) {
00055     size_t lastPos = str.find_first_not_of(delimiters, 0);
00056     size_t pos = str.find_first_of(delimiters, lastPos);
00057     while (std::string::npos != pos || std::string::npos != lastPos) {
00058       tokens.push_back(str.substr(lastPos, pos - lastPos));
00059       lastPos = str.find_first_not_of(delimiters, pos);
00060       pos = str.find_first_of(delimiters, lastPos);
00061     }
00062   }
00063 
00064 
00065   static void replace(std::string& str, const std::string& old, 
00066                       const std::string& rep) {
00067     size_t pos = 0;
00068     while((pos = str.find(old, pos)) != std::string::npos) {
00069       str.replace(pos, old.length(), rep);
00070       pos += rep.length();
00071     }
00072   }
00073 
00074   static std::string getSpreadsheetColumnName(int x);
00075   static std::string nextSpreadsheetColumnName(std::string current);
00076 };
00077 
00078 
00079 std::string quoteSql(std::string x, char del, bool alwaysQuote);
00080 
00081 
00082 #endif
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines