1 /*=========================================================================
4 Module: $RCSfile: gdcmUtil.cxx,v $
6 Date: $Date: 2004/06/20 18:08:48 $
7 Version: $Revision: 1.44 $
9 Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
10 l'Image). All rights reserved. See Doc/License.txt or
11 http://www.creatis.insa-lyon.fr/Public/Gdcm/License.htm for details.
13 This software is distributed WITHOUT ANY WARRANTY; without even
14 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 PURPOSE. See the above copyright notices for more information.
17 =========================================================================*/
20 #include "gdcmDebug.h"
22 #include <ctype.h> // For isspace
23 #include <string.h> // CLEANME: could this be only string ? Related to Win32 ?
28 * \brief Because is not yet available in g++2.96
30 std::istream& eatwhite(std::istream& is) {
43 * \brief Because not available in C++ (?)
45 void Tokenize (const std::string& str,
46 std::vector<std::string>& tokens,
47 const std::string& delimiters) {
48 std::string::size_type lastPos = str.find_first_not_of(delimiters,0);
49 std::string::size_type pos = str.find_first_of (delimiters,lastPos);
50 while (std::string::npos != pos || std::string::npos != lastPos) {
51 tokens.push_back(str.substr(lastPos, pos - lastPos));
52 lastPos = str.find_first_not_of(delimiters, pos);
53 pos = str.find_first_of (delimiters, lastPos);
59 * \brief Weed out a string from the non-printable characters (in order
60 * to avoid corrupting the terminal of invocation when printing)
61 * @param s string to remove non printable characters from
63 std::string CreateCleanString(std::string s) {
66 for(unsigned int i=0;i<str.size();i++)
73 if(!isprint(s[str.size()-1]))
74 if(s[str.size()-1]==0)
75 str[str.size()-1]=' ';
82 * \brief Add a SEPARATOR to the end of the name is necessary
83 * @param name file/directory name to normalize
85 void NormalizePath(std::string &name)
87 const char SEPARATOR_X = '/';
88 const char SEPARATOR_WIN = '\\';
89 const std::string SEPARATOR = "/";
92 if((name[size-1]!=SEPARATOR_X)&&(name[size-1]!=SEPARATOR_WIN))
100 * \brief Get the (directory) path from a full path file name
101 * @param fullName file/directory name to extract Path from
103 std::string GetPath(std::string &fullName)
105 int pos1=fullName.rfind("/");
106 int pos2=fullName.rfind("\\");
108 fullName.resize(pos1);
110 fullName.resize(pos2);
116 * \brief Get the (last) name of a full path file name
117 * @param fullName file/directory name to extract end name from
119 std::string GetName(std::string &fullName)
121 int fin=fullName.length()-1;
122 char a =fullName.c_str()[fin];
123 if (a == '/' || a == '\\') {
127 for (int i=fin;i!=0;i--) {
128 if (fullName.c_str()[i] == '/' || fullName.c_str()[i] == '\\')
133 std::string lastName;
134 for (int j=deb;j<fin+1;j++)
135 lastName=lastName+fullName.c_str()[j];