Fix a bug affecting TerraGear, and extend unit-tests to cover this. (SGPath::file returned an empty string for paths with no directory separator)
This commit is contained in:
@@ -135,6 +135,14 @@ int main(int argc, char* argv[])
|
|||||||
#else
|
#else
|
||||||
COMPARE(d1.str_native(), std::string("/usr/local"));
|
COMPARE(d1.str_native(), std::string("/usr/local"));
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
// paths with only the file components
|
||||||
|
SGPath pf("something.txt.gz");
|
||||||
|
COMPARE(pf.base(), "something.txt");
|
||||||
|
COMPARE(pf.file(), "something.txt.gz");
|
||||||
|
COMPARE(pf.dir(), "");
|
||||||
|
COMPARE(pf.lower_extension(), "gz");
|
||||||
|
COMPARE(pf.complete_lower_extension(), "txt.gz");
|
||||||
|
|
||||||
test_dir();
|
test_dir();
|
||||||
|
|
||||||
|
|||||||
@@ -175,12 +175,13 @@ void SGPath::concat( const string& p ) {
|
|||||||
|
|
||||||
|
|
||||||
// Get the file part of the path (everything after the last path sep)
|
// Get the file part of the path (everything after the last path sep)
|
||||||
string SGPath::file() const {
|
string SGPath::file() const
|
||||||
int index = path.rfind(sgDirPathSep);
|
{
|
||||||
if (index >= 0) {
|
string::size_type index = path.rfind(sgDirPathSep);
|
||||||
return path.substr(index + 1);
|
if (index != string::npos) {
|
||||||
|
return path.substr(index + 1);
|
||||||
} else {
|
} else {
|
||||||
return "";
|
return path;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user