2 //-----------------------------------------------------------------------------
6 #include <ctype.h> // For isspace
7 #include <string.h> // CLEANME: could this be only string ? Related to Win32 ?
11 * \brief Because is not yet available in g++2.96
13 std::istream& eatwhite(std::istream& is) {
26 * \brief Because not available in C++ (?)
28 void Tokenize (const std::string& str,
29 std::vector<std::string>& tokens,
30 const std::string& delimiters) {
31 std::string::size_type lastPos = str.find_first_not_of(delimiters,0);
32 std::string::size_type pos = str.find_first_of (delimiters,lastPos);
33 while (std::string::npos != pos || std::string::npos != lastPos) {
34 tokens.push_back(str.substr(lastPos, pos - lastPos));
35 lastPos = str.find_first_not_of(delimiters, pos);
36 pos = str.find_first_of (delimiters, lastPos);
42 * \brief Weed out a string from the non-printable characters (in order
43 * to avoid corrupting the terminal of invocation when printing)
44 * @param s string to remove non printable characters from
46 std::string CreateCleanString(std::string s) {
49 for(int i=0;i<str.size();i++)
56 if(!isprint(s[str.size()-1]))
57 if(s[str.size()-1]==0)
58 str[str.size()-1]=' ';
65 * \brief Add a SEPARATOR to the end of the name is necessary
66 * @param name file/directory name to normalize
68 void NormalizePath(std::string &name)
70 const char SEPARATOR_X = '/';
71 const char SEPARATOR_WIN = '\\';
72 const std::string SEPARATOR = "/";
75 if((name[size-1]!=SEPARATOR_X)&&(name[size-1]!=SEPARATOR_WIN))
83 * \brief Get the (directory) path from a full path file name
84 * @param fullName file/directory name to extract Path from
86 std::string GetPath(std::string &fullName)
88 int pos1=fullName.rfind("/");
89 int pos2=fullName.rfind("\\");
91 fullName.resize(pos1);
93 fullName.resize(pos2);
99 * \brief Get the (last) name of a full path file name
100 * @param fullName file/directory name to extract end name from
102 std::string GetName(std::string &fullName)
104 int fin=fullName.length()-1;
105 char a =fullName.c_str()[fin];
106 if (a == '/' || a == '\\') {
110 for (int i=fin;i!=0;i--) {
111 if (fullName.c_str()[i] == '/' || fullName.c_str()[i] == '\\')
116 std::string lastName;
117 for (int j=deb;j<fin+1;j++)
118 lastName=lastName+fullName.c_str()[j];