Changeset 21404
- Timestamp:
- 2010-01-04T17:43:22+13:00 (13 years ago)
- Location:
- main/trunk/greenstone2/common-src/src/lib
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
main/trunk/greenstone2/common-src/src/lib/fileutil.cpp
r14177 r21404 38 38 39 39 40 // returns the proper concatenation of the two paths40 // returns the proper concatenation of directory + directory/filename 41 41 text_t filename_cat (text_t path1, text_t path2) { 42 42 text_t::iterator here; … … 108 108 } 109 109 110 111 112 // returns the proper concatenation of the two paths, as in 113 // /usr/bin:/usr/local/bin (for Unix) and c:\usr\bin;c:\usr\local\bin (for windows) 114 115 text_t pathname_cat (text_t path1, text_t path2) { 116 text_t::iterator here; 117 text_t::iterator begin; 118 text_t::iterator end; 119 120 // make sure there are no slashes at the end of path1 121 122 if (!path1.empty()) { 123 // remove all trailing slashes 124 here = path1.end(); 125 --here; 126 begin = path1.begin(); 127 while (here != begin && (*here == '/' || *here == '\\')) { 128 --here; 129 } 130 ++here; 131 path1.erase(here,path1.end()); 132 133 // add one final slash 134 #ifdef __WIN32__ 135 path1 += ";"; 136 #else 137 path1 += ":"; 138 #endif 139 } 140 141 // make sure there are no slashes at the end of path2 142 here = path2.end(); 143 --here; 144 begin = path2.begin(); 145 while (here != begin && (*here == '/' || *here == '\\')) { 146 --here; 147 } 148 ++here; 149 path2.erase (here, path2.end()); 150 151 text_t fullpath = path1 + path2; 152 153 // make sure all the right slashes are used 154 here = fullpath.begin(); 155 end = fullpath.end(); 156 while (here != end) { 157 #ifdef __WIN32__ 158 if (*here == '/') *here = '\\'; 159 #else 160 if (*here == '\\') *here = '/'; 161 #endif 162 ++here ; 163 } 164 return fullpath; 165 } 166 167 text_t pathname_cat (text_t path1, text_t path2, text_t path3) { 168 return pathname_cat(pathname_cat(path1,path2),path3); 169 } 170 171 text_t pathname_cat (text_t path1, text_t path2, text_t path3, text_t path4) { 172 return pathname_cat(pathname_cat(pathname_cat(path1,path2),path3),path4); 173 } 174 175 text_t pathname_cat (text_t path1, text_t path2, text_t path3, text_t path4, 176 text_t path5) { 177 return pathname_cat(pathname_cat(pathname_cat(pathname_cat(path1,path2),path3), 178 path4),path5); 179 } 180 181 text_t pathname_cat (text_t path1, text_t path2, text_t path3, text_t path4, 182 text_t path5, text_t path6) { 183 return pathname_cat(pathname_cat(path1,path2,path3,path4,path5),path6); 184 } 185 186 187 188 189 110 190 // returns true if filename can be opened 111 191 bool file_exists (const text_t &filename) { -
main/trunk/greenstone2/common-src/src/lib/fileutil.h
r1837 r21404 31 31 32 32 33 // returns the proper concatenation of the two paths33 // returns the proper concatenation of directory + directory/filename 34 34 text_t filename_cat (text_t path1, text_t path2); 35 35 text_t filename_cat (text_t path1, text_t path2, text_t path3); … … 38 38 text_t path5); 39 39 text_t filename_cat (text_t path1, text_t path2, text_t path3, text_t path4, 40 text_t path5, text_t path6); 41 42 43 // returns the proper concatenation of the two paths, as in 44 // /usr/bin:/usr/local/bin (for Unix) and c:\usr\bin;c:\usr\local\bin (for windows) 45 text_t pathname_cat (text_t path1, text_t path2); 46 text_t pathname_cat (text_t path1, text_t path2, text_t path3); 47 text_t pathname_cat (text_t path1, text_t path2, text_t path3, text_t path4); 48 text_t pathname_cat (text_t path1, text_t path2, text_t path3, text_t path4, 49 text_t path5); 50 text_t pathhname_cat (text_t path1, text_t path2, text_t path3, text_t path4, 40 51 text_t path5, text_t path6); 41 52
Note:
See TracChangeset
for help on using the changeset viewer.