OSDN Git Service

fix shapePath function.
authorvisor <visor@users.sourceforge.jp>
Sun, 15 Nov 2009 07:34:39 +0000 (16:34 +0900)
committervisor <visor@users.sourceforge.jp>
Sun, 15 Nov 2009 07:34:39 +0000 (16:34 +0900)
lib/util_file.cc

index 2aed8f4..0b337e4 100644 (file)
@@ -109,6 +109,7 @@ void  makeSubdir (ustring& top, const ustring& sub) {
 void  shapePath (ustring& path) {
     static uregex  re1 ("//+");
     static uregex  re2 ("[^/]+/\\.\\.(/|$)");
+    static uregex  re3 ("(/|^)\\.(/|$)");
     umatch  m;
     uiterator  b, e;
 
@@ -126,6 +127,25 @@ void  shapePath (ustring& path) {
            path = ustring (b, m[0].first).append (m[0].second, e);
        }
     }
+    while (usearch (path, m, re3)) {
+       switch (m[0].second - m[0].first) {
+       case 1:
+           goto Bp1;
+       case 2:
+           b = path.begin ();
+           e = path.end ();
+           path = ustring (b, m[0].first).append (m[0].second, e);
+           break;
+       case 3:
+           b = path.begin ();
+           e = path.end ();
+           path = ustring (b, m[0].first).append (m[2].first, e);
+           break;
+       default:;
+           assert (0);
+       }
+    }
+ Bp1:;
 }
 
 bool  isAbsolutePath (const ustring& path) {