Page principale | Liste des namespaces | Hiérarchie des classes | Liste alphabétique | Liste des classes | Liste des fichiers | Membres de namespace | Membres de classe | Membres de fichier

Utils.cpp

Aller à la documentation de ce fichier.
00001 /*
00002     Copyright (c) 2005, Quentin Lequy and Romain Gaucher
00003     All rights reserved.
00004 
00005     Redistribution and use in source and binary forms, with or 
00006     without modification, are permitted provided that the following 
00007     conditions are met:
00008 
00009         * Redistributions of source code must retain the above copyright 
00010           notice, this list of conditions and the following disclaimer.
00011 
00012         * Redistributions in binary form must reproduce the above copyright 
00013           notice, this list of conditions and the following disclaimer in the 
00014           documentation and/or other materials provided with the distribution.
00015 
00016         * Neither the name of Quentin Lequy or Romain Gaucher nor the names 
00017           of its contributors may be used to endorse or promote products 
00018           derived from this software without specific prior written permission.
00019 
00020     THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 
00021     AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 
00022     IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 
00023     ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 
00024     LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 
00025     DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 
00026     SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 
00027     AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 
00028     (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 
00029     SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
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         // Skip delimiters at beginning.
00046         string::size_type lastPos = str.find_first_not_of(delimiters, 0);
00047         // Find first "non-delimiter".
00048         string::size_type pos     = str.find_first_of(delimiters, lastPos);
00049     
00050         while (string::npos != pos || string::npos != lastPos)
00051         {
00052             // Found a token, add it to the vector.
00053             tokens.push_back(str.substr(lastPos, pos - lastPos));
00054             // Skip delimiters.  Note the "not_of"
00055             lastPos = str.find_first_not_of(delimiters, pos);
00056             // Find next "non-delimiter"
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, "<", "&lt;");
00104         Replace(ret, ">", "&gt;");
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 }

Généré le Sun Oct 2 19:13:12 2005 pour Modelib par  doxygen 1.4.4