Refactor new editor boundaries and test ownership
This commit is contained in:
@@ -1,7 +1,5 @@
|
||||
#include "ProjectBrowserModelInternal.h"
|
||||
|
||||
#include "Internal/StringEncoding.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <cctype>
|
||||
#include <cwctype>
|
||||
@@ -10,6 +8,28 @@
|
||||
|
||||
namespace XCEngine::UI::Editor::App::ProjectBrowserModelInternal {
|
||||
|
||||
namespace {
|
||||
|
||||
std::string BuildUtf8String(std::u8string_view value) {
|
||||
std::string result = {};
|
||||
result.reserve(value.size());
|
||||
for (const char8_t character : value) {
|
||||
result.push_back(static_cast<char>(character));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
std::u8string BuildU8String(std::string_view value) {
|
||||
std::u8string result = {};
|
||||
result.reserve(value.size());
|
||||
for (const char character : value) {
|
||||
result.push_back(static_cast<char8_t>(character));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
std::string ToLowerCopy(std::string value) {
|
||||
std::transform(
|
||||
value.begin(),
|
||||
@@ -22,7 +42,11 @@ std::string ToLowerCopy(std::string value) {
|
||||
}
|
||||
|
||||
std::string PathToUtf8String(const std::filesystem::path& path) {
|
||||
return App::Internal::WideToUtf8(path.native());
|
||||
return BuildUtf8String(path.u8string());
|
||||
}
|
||||
|
||||
std::filesystem::path BuildPathFromUtf8(std::string_view value) {
|
||||
return std::filesystem::path(BuildU8String(value));
|
||||
}
|
||||
|
||||
std::string NormalizePathSeparators(std::string value) {
|
||||
@@ -168,14 +192,14 @@ std::filesystem::path MakeUniqueFolderPath(
|
||||
const std::filesystem::path& parentPath,
|
||||
std::string_view preferredName) {
|
||||
std::filesystem::path candidatePath =
|
||||
parentPath / App::Internal::Utf8ToWide(std::string(preferredName));
|
||||
parentPath / BuildPathFromUtf8(preferredName);
|
||||
if (!std::filesystem::exists(candidatePath)) {
|
||||
return candidatePath;
|
||||
}
|
||||
|
||||
for (std::size_t suffix = 1u;; ++suffix) {
|
||||
candidatePath =
|
||||
parentPath / App::Internal::Utf8ToWide(
|
||||
parentPath / BuildPathFromUtf8(
|
||||
std::string(preferredName) + " " + std::to_string(suffix));
|
||||
if (!std::filesystem::exists(candidatePath)) {
|
||||
return candidatePath;
|
||||
@@ -212,7 +236,7 @@ std::string BuildRenamedEntryName(
|
||||
}
|
||||
|
||||
const std::filesystem::path requestedPath =
|
||||
App::Internal::Utf8ToWide(std::string(requestedName));
|
||||
BuildPathFromUtf8(requestedName);
|
||||
if (requestedPath.has_extension()) {
|
||||
return PathToUtf8String(requestedPath.filename());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user