]> git.mxchange.org Git - simgear.git/commitdiff
Fix a bug affecting TerraGear, and extend unit-tests to cover this. (SGPath::file...
authorJames Turner <zakalawe@mac.com>
Fri, 28 Oct 2011 11:57:07 +0000 (12:57 +0100)
committerJames Turner <zakalawe@mac.com>
Fri, 28 Oct 2011 11:57:07 +0000 (12:57 +0100)
simgear/misc/path_test.cxx
simgear/misc/sg_path.cxx

index cda488590c42d2921aba99e0fb13273c75e3ce6b..459f064cdd78a3464851863b5badecfda75db4c6 100644 (file)
@@ -135,6 +135,14 @@ int main(int argc, char* argv[])
 #else
     COMPARE(d1.str_native(), std::string("/usr/local"));
 #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();
     
index ed31e18b8a590457924fcec65dcaac3fb31d2b54..46e8022831b7a966c8fdc227438e774ea135cfa2 100644 (file)
@@ -175,12 +175,13 @@ void SGPath::concat( const string& p ) {
 
 
 // Get the file part of the path (everything after the last path sep)
-string SGPath::file() const {
-    int index = path.rfind(sgDirPathSep);
-    if (index >= 0) {
-    return path.substr(index + 1);
+string SGPath::file() const
+{
+    string::size_type index = path.rfind(sgDirPathSep);
+    if (index != string::npos) {
+        return path.substr(index + 1);
     } else {
-    return "";
+        return path;
     }
 }