-
Notifications
You must be signed in to change notification settings - Fork 808
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Rewrite portions of EbrFile handling to use UTF16 #1891
Changes from 2 commits
1725e10
e238a98
e197a9c
387b48b
7570357
210e10f
1b5359a
8e47f6f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,12 +20,11 @@ | |
|
||
#include <algorithm> | ||
#include <list> | ||
#include <regex> | ||
|
||
#include "Platform/EbrPlatform.h" | ||
#include "PathMapper.h" | ||
|
||
// utility function to tokenize string using delmiters | ||
// utility function to tokenize string using delimiters | ||
// d:\src/winobjc ==> d:, src, winobjc | ||
// /src/winobjc ==> "", src, winobjc | ||
// / ==> "" | ||
|
@@ -59,9 +58,9 @@ static void _EscapeIllegalPathCharacters(std::wstring& str) { | |
} | ||
|
||
// normalize relative path | ||
// 1 remove any "." or "" components | ||
// 2 from reverse, remove any ".." and preceeding component | ||
// if components becomes empty, return "." | ||
// 1 remove any "." or "" components | ||
// 2 remove any ".." and preceeding component | ||
// 3 if components becomes empty, return "." | ||
|
||
static void _NormalizeRelativePathComponents(std::list<std::wstring>& components) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same as above There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same as above :). |
||
for (auto it = components.begin(); it != components.end();) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. put ++it in here rather than in last else? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No. continue also goes to ++. |
||
|
@@ -76,6 +75,8 @@ static void _NormalizeRelativePathComponents(std::list<std::wstring>& components | |
break; | ||
} | ||
// we have to do this in case the last component is .. | ||
// erase the previous component first because erase returns the next item | ||
// which would be "..". | ||
it = components.erase(--it); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Are we concerned about reverse-iterating a std::list? I thought they were singly-linked, making There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. They can be double linked I thought, but given how we're using it might make more sense to just use a std::vector. FWIU it's generally better to take a hit every once in a while for resizing if we need to than having to jump around when iterating. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. also don't like this expression it = something(--it), hard to figure out exactly what's going on There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. std::list is bidirectional. Not changing this to vector as sometime in the future when we do properly support > MAX_PATH, there will be several elements here. And leading '.' is pretty common. Since the list is all constructed at the same time, locality of reference should not be a problem. |
||
it = components.erase(it); | ||
} else { | ||
|
@@ -98,15 +99,13 @@ std::wstring _MapPathRoot(const std::wstring& root) { | |
return std::wstring(L".\\home"); | ||
} | ||
|
||
std::wregex drive(L"[a-zA-Z]:"); | ||
|
||
if (std::regex_match(root, drive)) { | ||
if (root.length() == 2 && iswalpha(root[0]) && root[1] == L':') { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||
return root; | ||
} | ||
|
||
for (int i = 0; i < _countof(c_specialFolders); ++i) { | ||
for (auto root : c_specialFolders) { | ||
if (_wcsicmp(root.c_str(), c_specialFolders[i].c_str()) == 0) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since both of these are There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unfortunately, i need it to be case insensitive and == isn't. |
||
return Strings::NarrowToWide<std::wstring>(EbrGetWritableFolder()) + std::wstring(L"\\") + c_specialFolders[i]; | ||
return IwGetWritableFolder() + std::wstring(L"\\") + c_specialFolders[i]; | ||
} | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,10 +17,12 @@ | |
#include <TestFramework.h> | ||
#include "pathmapper.h" | ||
|
||
extern "C" void EbrSetWritableFolder(const char*); | ||
extern "C" void IwSetWritableFolder(const wchar_t*); | ||
extern "C" const wchar_t* IwGetWritableFolder(); | ||
|
||
TEST(PathMapper, pathMapper) { | ||
EbrSetWritableFolder("d:\\temp"); | ||
std::wstring writableFolder = EbrGetWritableFolder(); | ||
IwSetWritableFolder(L"d:\\temp"); | ||
|
||
CPathMapper mapper1("c:/users/winobjc-bot"); | ||
EXPECT_EQ_MSG(0, wcscmp(mapper1, L"c:\\users\\winobjc-bot"), "%S", (const wchar_t*)mapper1); | ||
|
@@ -69,6 +71,8 @@ | |
|
||
CPathMapper mapper16("/AppSupport/.\\?/"); | ||
EXPECT_EQ_MSG(0, wcscmp(mapper16, L"d:\\temp\\AppSupport\\+"), "%S", (const wchar_t*)mapper16); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: for these guys, prefer There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. (it means we don't have to rely on the logging infrastructure in the |
||
|
||
IwSetWritableFolder(writableFolder.c_str()); | ||
} | ||
|
||
TEST(PathMapper, RelativePathTests) { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does the presence of a "" always mean it's an absolute unix path?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. It just means that it was an absolute path.