2
* Copyright (c) 2002 Robert Collins.
4
* This program is free software; you can redistribute it and/or modify
5
* it under the terms of the GNU General Public License as published by
6
* the Free Software Foundation; either version 2 of the License, or
7
* (at your option) any later version.
9
* A copy of the GNU General Public License can be found at
12
* Written by Robert Collins <robertc@hotmail.com>
18
Path::Path () : _name (), _basename(), _dirname ()
21
Path::Path (Path const &old) : _name (old._name), _basename(old._basename), _dirname (old._dirname)
25
Path::Path (string const &aDir)
33
Path::operator= (string const &aDir)
40
Path::operator= (Path const &old)
43
_basename = old._basename;
44
_dirname = old._dirname;
49
Path::operator + (Path const &rhs) const
53
* case 1) b is relative (does not start with /)
54
* case 2) b is absolute, throw exception.
55
* case 1a) b has more .. elements than a has elements. Throw exception.
56
* XXX if needed, implement the above rules.
57
* for now: concat the full names, and set to string.
59
Path result (_name + "/" + rhs._name);
64
Path::StripSlash (string &aString)
66
if (aString[aString.size() - 1] == '/' && aString.size() > 1)
67
aString.erase (aString.size() - 1);
71
Path::setToString (string const &aDir)
74
throw (string) "Illegal Path \"\"";
78
unsigned int offset = _dirname.rfind ("/");
79
if (offset != string::npos) {
80
_basename = _dirname.substr (offset + 1);
81
_dirname.erase(offset);
82
/* dirname must be '/' at a minimum when a '/' was provided */
92
* 1. If string is //, skip steps 2 to 5.
94
2. If string consists entirely of slash characters, string will be set to a single slash character. In this case, skip steps 3 to 8.
96
3. If there are any trailing slash characters in string, they will be removed.
98
4. If there are no slash characters remaining in string, string will be set to a single period character. In this case, skip steps 5 to 8.
100
5. If there are any trailing non-slash characters in string, they will be removed.
102
6. If the remaining string is //, it is implementation-dependent whether steps 7 and 8 are skipped or processed.
104
7. If there are any trailing slash characters in string, they will be removed.
106
8. If the remaining string is empty, string will be set to a single slash character.
108
The resulting string will be written to standard output.