Add required overloads to logger for handling unicode paths, also add conversion functions from std::filesystem::path to std::string without losing unicode data.

crashfix_debugdraw
Project579 3 years ago
parent b817359bcf
commit 78ab009d5c

@ -1,6 +1,9 @@
#include "debuglog.hpp"
#include <mutex>
#include <components/files/configurationmanager.hpp>
namespace Debug
{
Level CurrentDebugLevel = Level::NoLevel;
@ -8,7 +11,7 @@ namespace Debug
static std::mutex sLock;
Log::Log(Debug::Level level)
Log::Log(Debug::Level level)
: mShouldLog(level <= Debug::CurrentDebugLevel)
{
// No need to hold the lock if there will be no logging anyway
@ -34,3 +37,43 @@ Log::~Log()
std::cout << std::endl;
sLock.unlock();
}
Log& Log::operator<<(std::filesystem::path&& rhs)
{
if (mShouldLog)
std::cout << Files::pathToUnicodeString(std::move(rhs));
return *this;
}
Log& Log::operator<<(const std::filesystem::path& rhs)
{
if (mShouldLog)
std::cout << Files::pathToUnicodeString(rhs);
return *this;
}
Log& Log::operator<<(std::u8string&& rhs)
{
if (mShouldLog)
std::cout << Misc::StringUtils::u8StringToString(std::move(rhs));
return *this;
}
Log& Log::operator<<(const std::u8string& rhs)
{
if (mShouldLog)
std::cout << Misc::StringUtils::u8StringToString(rhs);
return *this;
}
Log& Log::operator<<(const char8_t* rhs)
{
if (mShouldLog)
std::cout << Misc::StringUtils::u8StringToString(rhs);
return *this;
}

@ -2,6 +2,7 @@
#define DEBUG_LOG_H
#include <iostream>
#include <filesystem>
namespace Debug
{
@ -36,6 +37,16 @@ public:
return *this;
}
Log& operator<<(std::filesystem::path&& rhs);
Log& operator<<(const std::filesystem::path& rhs);
Log& operator<<(std::u8string&& rhs);
Log& operator<<(const std::u8string& rhs);
Log& operator<<(const char8_t* rhs);
private:
const bool mShouldLog;
};

@ -460,4 +460,29 @@ PathContainer asPathContainer(const MaybeQuotedPathContainer& MaybeQuotedPathCon
return res;
}
std::string pathToUnicodeString(const std::filesystem::path& path)
{
return Misc::StringUtils::u8StringToString(path.u8string());
}
std::string pathToUnicodeString(std::filesystem::path&& path)
{
return Misc::StringUtils::u8StringToString(path.u8string());
}
std::filesystem::path unicodeStringToPath(const std::string_view path)
{
return Misc::StringUtils::stringToU8String(path);
}
std::filesystem::path unicodeStringToPath(std::string&& path)
{
return Misc::StringUtils::stringToU8String(std::move(path));
}
std::filesystem::path unicodeStringToPath(const char* path)
{
return Misc::StringUtils::stringToU8String(path);
}
} /* namespace Files */

@ -105,6 +105,16 @@ typedef std::vector<MaybeQuotedPath> MaybeQuotedPathContainer;
PathContainer asPathContainer(const MaybeQuotedPathContainer& MaybeQuotedPathContainer);
std::string pathToUnicodeString(const std::filesystem::path& path);
std::string pathToUnicodeString(std::filesystem::path&& path);
std::filesystem::path unicodeStringToPath(const std::string_view path);
std::filesystem::path unicodeStringToPath(std::string&& path);
std::filesystem::path unicodeStringToPath(const char* path);
} /* namespace Files */
#endif /* COMPONENTS_FILES_CONFIGURATIONMANAGER_HPP */

Loading…
Cancel
Save