]> git.mxchange.org Git - simgear.git/commitdiff
#479: avoid issues due to trailing path separators
authorThorstenB <brehmt@gmail.com>
Sun, 18 Dec 2011 16:04:31 +0000 (17:04 +0100)
committerThorstenB <brehmt@gmail.com>
Sun, 18 Dec 2011 16:04:31 +0000 (17:04 +0100)
Cut trailing separators when converting from string to sgpath.
Also, SGPath::fix does NOT replace ":". It only replaces "\" with "/",
so the "i!=1" check for Windows made no sense (rule #9: never believe
a source code comment).

simgear/debug/debug_types.h
simgear/misc/sg_path.cxx

index 03863f75d270d8b08b956be1bb6eb9586e61fe55..0a36c1ebf2fb0dd597745559fe01df8364d3fbfa 100644 (file)
@@ -1,5 +1,5 @@
 /** \file debug_types.h
- *  Define the various logging classes and prioritiess
+ *  Define the various logging classes and priorities
  */
 
 /** 
@@ -30,7 +30,7 @@ typedef enum {
     SG_AI          = 0x00080000,
     SG_ENVIRONMENT = 0x00100000,
     SG_SOUND       = 0x00200000,
-    SG_UNDEFD      = 0x00400000, // For range checkingng
+    SG_UNDEFD      = 0x00400000, // For range checking
 
     SG_ALL         = 0xFFFFFFFF
 } sgDebugClass;
index 46e8022831b7a966c8fdc227438e774ea135cfa2..92a16945db57bd94b6d8bdefdebc8df3e2a2ca27 100644 (file)
@@ -53,22 +53,20 @@ static const char sgSearchPathSep = ':';
 #endif
 
 
-// If Unix, replace all ":" with "/".  In windoze, allow the
-// second character to be a ":" for things like c:\foo\bar
-
+// For windows, replace "\" by "/".
 void
 SGPath::fix()
 {
-    for ( string::size_type i = 0; i < path.size(); ++i ) {
-#if defined( WIN32 )
-    // for windoze, don't replace the ":" for the second character
-    if ( i == 1 ) {
-        continue;
-    }
-#endif
-    if ( path[i] == sgDirPathSepBad ) {
-        path[i] = sgDirPathSep;
+    string::size_type sz = path.size();
+    for ( string::size_type i = 0; i < sz; ++i ) {
+        if ( path[i] == sgDirPathSepBad ) {
+            path[i] = sgDirPathSep;
+        }
     }
+    // drop trailing "/"
+    while ((sz>1)&&(path[sz-1]==sgDirPathSep))
+    {
+        path.resize(--sz);
     }
 }