2 //-----------------------------------------------------------------------------
6 #include <ctype.h> // For isspace
7 #include <string.h> // CLEANME: could this be only string ? Related to Win32 ?
12 * \brief Because is not yet available in g++2.96
14 std::istream& eatwhite(std::istream& is) {
27 * \brief Because not available in C++ (?)
29 void Tokenize (const std::string& str,
30 std::vector<std::string>& tokens,
31 const std::string& delimiters) {
32 std::string::size_type lastPos = str.find_first_not_of(delimiters,0);
33 std::string::size_type pos = str.find_first_of (delimiters,lastPos);
34 while (std::string::npos != pos || std::string::npos != lastPos) {
35 tokens.push_back(str.substr(lastPos, pos - lastPos));
36 lastPos = str.find_first_not_of(delimiters, pos);
37 pos = str.find_first_of (delimiters, lastPos);
43 * \brief Weed out a string from the non-printable characters (in order
44 * to avoid corrupting the terminal of invocation when printing)
45 * @param s string to remove non printable characters from
47 std::string CreateCleanString(std::string s) {
50 for(unsigned int i=0;i<str.size();i++)
57 if(!isprint(s[str.size()-1]))
58 if(s[str.size()-1]==0)
59 str[str.size()-1]=' ';
66 * \brief Add a SEPARATOR to the end of the name is necessary
67 * @param name file/directory name to normalize
69 void NormalizePath(std::string &name)
71 const char SEPARATOR_X = '/';
72 const char SEPARATOR_WIN = '\\';
73 const std::string SEPARATOR = "/";
76 if((name[size-1]!=SEPARATOR_X)&&(name[size-1]!=SEPARATOR_WIN))
84 * \brief Get the (directory) path from a full path file name
85 * @param fullName file/directory name to extract Path from
87 std::string GetPath(std::string &fullName)
89 int pos1=fullName.rfind("/");
90 int pos2=fullName.rfind("\\");
92 fullName.resize(pos1);
94 fullName.resize(pos2);
100 * \brief Get the (last) name of a full path file name
101 * @param fullName file/directory name to extract end name from
103 std::string GetName(std::string &fullName)
105 int fin=fullName.length()-1;
106 char a =fullName.c_str()[fin];
107 if (a == '/' || a == '\\') {
111 for (int i=fin;i!=0;i--) {
112 if (fullName.c_str()[i] == '/' || fullName.c_str()[i] == '\\')
117 std::string lastName;
118 for (int j=deb;j<fin+1;j++)
119 lastName=lastName+fullName.c_str()[j];