[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-core-devel
Subject: patch: kurl
From: Simon Hausmann <sh () caldera ! de>
Date: 2000-08-28 7:43:49
[Download RAW message or body]
Hi,
There is a small problem with the isParentOf() method of KURL. It
currently breaks when checking if /blah/foo is a parent of /blah/foo2 .
The current isParentOf method returns true, which however is not correct
;-) . The attached patch fixes it, but I'm not sure if that's the correct
way of doing it. Please review it :-) (some KURL expert)
Thanks.
Bye,
Simon
["kurl_patch.txt" (TEXT/PLAIN)]
Index: kurl.cpp
===================================================================
RCS file: /home/kde/kdelibs/kdecore/kurl.cpp,v
retrieving revision 1.137
diff -u -b -p -r1.137 kurl.cpp
--- kurl.cpp 2000/08/14 20:01:01 1.137
+++ kurl.cpp 2000/08/28 07:30:55
@@ -746,8 +746,18 @@ bool KURL::isParentOf( const KURL& _u )
//kdDebug(126) << "p2=" << p2 << endl;
//kdDebug(126) << "p1.length()=" << p1.length() << endl;
//kdDebug(126) << "p2.left(!$)=" << p2.left( p1.length() ) << endl;
- if ( p1 == p2.left( p1.length() ) )
- return true;
+
+ // faster than p1 == p2.left( p1.length() ) because it doesn't need a memcpy
+ bool res = p2.startsWith( p1 );
+
+ if ( res && p1.length() < p2.length() ) // handle the case /path/blah vs. /path/blah2
+ res = p2.mid( p1.length() ).contains( '/' ); // does the text after ".../blah" contain
+ // a slash? if yes, then there's a
+ // subdir -> p1 is parent of p2
+ // otherwise -> different paths, with a
+ // similar naming though
+
+ return res;
}
return false;
}
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic