Created
February 27, 2014 22:58
-
-
Save Bigpet/9261457 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//previous non-STL version: | |
u32 vfsDevice::CmpLocalPath(const wxString& local_path) | |
{ | |
wxFileName path0(m_local_path); | |
path0.Normalize(); | |
const wxString full_local_path = path0.GetFullPath(); | |
if (local_path.Len() < full_local_path.Len()) | |
return 0; | |
wxArrayString arr0 = wxSplit(path0.GetFullPath(), '\\'); | |
wxArrayString arr1 = wxSplit(local_path, '\\'); | |
const u32 lim = min(arr0.GetCount(), arr1.GetCount()); | |
u32 ret = 0; | |
for(u32 i=0; i<lim; ret += arr0[i++].Len() + 1) | |
{ | |
if(arr0[i].CmpNoCase(arr1[i]) != 0) | |
{ | |
break; | |
} | |
} | |
return ret; | |
} | |
//half STL-version, <filesystem> in c++14 or c++17 should make this a little better | |
u32 vfsDevice::CmpLocalPath(const wxString& local_path) | |
{ | |
wxFileName path0(m_local_path); | |
path0.Normalize(); | |
const wxString full_local_path = path0.GetFullPath(); | |
if (local_path.Len() < full_local_path.Len()) | |
return 0; | |
std::locale loc; | |
auto charType = *local_path.begin(); | |
auto pos = std::mismatch( | |
std::begin(full_local_path), | |
std::end(full_local_path), | |
std::begin(local_path), | |
[&loc](decltype(charType) &a, decltype(charType) &b) | |
{ | |
return std::tolower(a, loc) == std::tolower(b, loc); | |
}); | |
if (pos.first == std::end(full_local_path)) | |
{ | |
return full_local_path.size(); | |
} | |
else | |
{ | |
const char *seperators = "/\\"; | |
auto last_sep = std::find_first_of(std::reverse_iterator<wxString::const_iterator>(pos.first), | |
std::reverse_iterator<wxString::const_iterator>(std::begin(full_local_path)), | |
seperators, seperators+3); | |
if (last_sep == std::reverse_iterator<wxString::const_iterator>(std::begin(full_local_path))) | |
{ | |
//Path without slashes? | |
return 0; | |
} | |
else | |
{ | |
return last_sep.base()-std::begin(full_local_path); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment