Check if Dir is Subset of a path Topic is solved

If you have a cool piece of software to share, but you are not hosting it officially yet, please dump it in here. If you have code snippets that are useful, please donate!
User avatar
eranon
Can't get richer than this
Can't get richer than this
Posts: 867
Joined: Sun May 13, 2012 11:42 pm
Location: France
Contact:

Re: Check if Dir is Subset of a path

Post by eranon »

I've tried and it works well on my side (under Windows 7 Pro 64-bit FR edition) using this function (to be sure we talk about the same one) :

Code: Select all

bool IsSubDir(wxString strRefPath, wxString strPathToTest)
{
    wxFileName fn(strPathToTest);
    if (!fn.MakeRelativeTo(strRefPath))
        return false;
    if (fn.GetFullPath().Find("..") == 0)
        return false;
    return true;
}
Here are some test results :
snap_0000194.png
snap_0000194.png (12.88 KiB) Viewed 3797 times
[Ind. dev. - wxWidgets 3.0/3.1 under "Win 7 64-bit, TDM64-GCC" + "OS X 10.9, LLVM Clang"]
User avatar
evstevemd
Part Of The Furniture
Part Of The Furniture
Posts: 2408
Joined: Wed Jan 28, 2009 11:57 am
Location: United Republic of Tanzania

Re: Check if Dir is Subset of a path

Post by evstevemd »

eranon wrote:I've tried and it works well on my side (under Windows 7 Pro 64-bit FR edition) using this function (to be sure we talk about the same one) :

Code: Select all

bool IsSubDir(wxString strRefPath, wxString strPathToTest)
{
    wxFileName fn(strPathToTest);
    if (!fn.MakeRelativeTo(strRefPath))
        return false;
    if (fn.GetFullPath().Find("..") == 0)
        return false;
    return true;
}
Here are some test results :
snap_0000194.png
Well I will try it again may be something else was wrong than what I thought.
I use linux, Ubuntu to be specific!
Chief Justice: We have trouble dear citizens!
Citizens: What it is his honor?
Chief Justice:Our president is an atheist, who will he swear to?
User avatar
eranon
Can't get richer than this
Can't get richer than this
Posts: 867
Joined: Sun May 13, 2012 11:42 pm
Location: France
Contact:

Re: Check if Dir is Subset of a path

Post by eranon »

Nothing urgent, but I think it would be nice if you could push the test (maybe related to MakeRelativeTo's underlying code against Linux), evstevemd. On my side, my dev. env. are currently only under Windows and OS X. I'm using Linux too (Ubuntu, Fedora and CentOS), but without any up and running dev environment and wxWidgets right now.
[Ind. dev. - wxWidgets 3.0/3.1 under "Win 7 64-bit, TDM64-GCC" + "OS X 10.9, LLVM Clang"]
User avatar
evstevemd
Part Of The Furniture
Part Of The Furniture
Posts: 2408
Joined: Wed Jan 28, 2009 11:57 am
Location: United Republic of Tanzania

Re: Check if Dir is Subset of a path

Post by evstevemd »

Ah! I found that my code messed up the paths and so the code works fine! :D
Chief Justice: We have trouble dear citizens!
Citizens: What it is his honor?
Chief Justice:Our president is an atheist, who will he swear to?
Post Reply