00001
00015 #ifndef STRINGUTILS_H
00016 #define STRINGUTILS_H
00017
00018 #include "IS3DCommon.H"
00019 #include <iostream>
00020 #include <sstream>
00021
00022 #include "G3DOperators.H"
00023 #include "IS3DCommon.H"
00024
00025
00026 #define DEFINE_TO_QUOTED_STR( d ) #d
00027
00028
00036 bool popNextToken(std::string &in, std::string &token,
00037 bool returnFalseOnSemiColon = false);
00038
00039
00043 bool popUntilSemicolon(std::string &in, std::string &popped);
00044
00047 Array<std::string> splitIntoArray(const std::string &in);
00048
00055 Array< Array< std::string > > readDelimitedData(const std::string &csvString,
00056 const std::string &delimiter,
00057 bool removeQuotes=true);
00058
00061 std::string joinIntoString(const Array<std::string>& in,
00062 const std::string& delimiter=std::string(" "));
00063
00065 std::string convertNewlinesAndTabsToSpaces(std::string input);
00066
00067 std::string intToString(int i);
00068 int stringToInt(const std::string &in);
00069
00070 std::string realToString(double r);
00071 double stringToReal(const std::string &in);
00072
00075 int iMinNonNeg(int i1, int i2);
00076
00077
00082 template <class T>
00083 static inline bool retypeString(const std::string &str, T &val) {
00084 std::istringstream is(str.c_str());
00085 is >> val;
00086 if (!is) return false;
00087 else return true;
00088 }
00089
00090
00092 std::string spacesString(int num);
00093
00095 int numSubstringOccurances(const std::string &str, const std::string &substr);
00096
00099 int findNth(const std::string &str, const std::string &substr, const int n);
00100
00103 template <class T>
00104 Array<T> insertIntoArray(Array<T> inputArray, T newElement,
00105 int insertBeforeElementNum)
00106 {
00107 debugAssert(insertBeforeElementNum >= 0);
00108 debugAssert(insertBeforeElementNum <= inputArray.size());
00109
00110 Array<T> anew;
00111
00112 for (int i=0;i<insertBeforeElementNum;i++)
00113 anew.append(inputArray[i]);
00114
00115 anew.append(newElement);
00116
00117 for (int i=insertBeforeElementNum;i<inputArray.size();i++)
00118 anew.append(inputArray[i]);
00119
00120 debugAssert(anew.size() == (inputArray.size() + 1));
00121 return anew;
00122 }
00123
00124
00125
00126
00127
00129
00143 bool
00144 getXMLField(const std::string &input, const std::string &fieldName,
00145 Table<std::string, std::string> &propertiesAndValues,
00146 std::string &fieldData,
00147 std::string &leftoverInput);
00148
00151 std::string
00152 writeXMLField(const std::string &fieldName,
00153 const Table<std::string, std::string> &propertiesAndValues,
00154 const std::string &fieldData);
00155
00156
00157 char**
00158 stringArrayTo2DCharArray(const Array<std::string> &a);
00159
00160 void
00161 delete2DCharArray(char **ptr, int size);
00162
00163
00164
00165
00166 #endif