00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032 #include "Utils.h"
00033 #include <string>
00034 #include <vector>
00035
00036
00037 namespace Modelib {
00038
00039 namespace Utils
00040 {
00041 using namespace std;
00042
00043 void Tokenize(const string& str, vector<string>& tokens, const string& delimiters)
00044 {
00045
00046 string::size_type lastPos = str.find_first_not_of(delimiters, 0);
00047
00048 string::size_type pos = str.find_first_of(delimiters, lastPos);
00049
00050 while (string::npos != pos || string::npos != lastPos)
00051 {
00052
00053 tokens.push_back(str.substr(lastPos, pos - lastPos));
00054
00055 lastPos = str.find_first_not_of(delimiters, pos);
00056
00057 pos = str.find_first_of(delimiters, lastPos);
00058 }
00059 }
00060
00061
00069 string AvoidSpaces(string& s)
00070 {
00071 string t;
00072 for(string::const_iterator iter = s.begin();iter!=s.end();++iter)
00073 if (*iter != ' ' && *iter != '\t')
00074 t += *iter;
00075 return t;
00076 }
00077
00086 void Replace(string& where, const string& what, const string& by)
00087 {
00088 for (string::size_type i = where.find(what);
00089 i != string::npos;
00090 i = where.find(what, i + by.size()))
00091 where.replace(i, what.size(), by);
00092 }
00093
00100 string toHTML(const string& str)
00101 {
00102 string ret(str);
00103 Replace(ret, "<", "<");
00104 Replace(ret, ">", ">");
00105 return ret;
00106 }
00107
00114 string toLATEX(const string& str)
00115 {
00116 string ret(str);
00117 Replace(ret, "<=", "\\leq");
00118 Replace(ret, ">=", "\\geq");
00119 Replace(ret, "!=", "\\neq");
00120 Replace(ret, "==", "=");
00121 Replace(ret, "$", "");
00122 return ret;
00123 }
00124
00125
00126 }
00127
00128
00129 }