summaryrefslogtreecommitdiff
path: root/indra/newview/llluamanager.cpp
diff options
context:
space:
mode:
authorNat Goodspeed <nat@lindenlab.com>2024-09-25 21:38:46 -0400
committerNat Goodspeed <nat@lindenlab.com>2024-09-25 21:38:46 -0400
commitdc0c6d396eb70392f294eea65975646dad662f6a (patch)
tree9a99cb4015a7199c624fe4d726b8ac5bf874fb6d /indra/newview/llluamanager.cpp
parent55df7328c6f8c864ea309c57d73e791e079b3c2c (diff)
Adapt `fsyspath` for C++20 conventions.
In C++20, `std::filesystem::u8path()` (that accepts a UTF-8 encoded `std::string` and returns a `std::filesystem::path`) is deprecated. Instead, to engage UTF-8 coding conversions, we're supposed to pass the `path` constructor a `std::u8string`, i.e. a `std::basic_string<char8_t>`. Since `char8_t` is a type distinct from both `char` and `unsigned char`, we must Do Something to pass a UTF-8 encoded `std::string` into `std::filesystem::path`. To avoid copying characters from a `std::string` into a temporary `std::u8string` and from there into the `std::filesystem::path`, make a `boost::transform_iterator` that accepts a `std::string_view::iterator` and adapts it to dereference `char8_t` characters. Make `fsyspath(std::string_view)` engage the base-class constructor accepting (iterator, iterator), adapting `string_view::begin()` and `end()` to deliver `char8_t` characters. Use the same tactic for `fsyspath::operator=(std::string_view)`, explicitly calling `std::filesystem::path::assign()` with the adapted iterators. To resolve ambiguities, provide both constructors and assignment operators accepting `(const std::string&)` and `(const char*)`, explicitly converting each to `std::string_view`. At the same time, `std::filesystem::path::u8string()` now returns `std::u8string` rather than `std::string`. Since `std::filesystem::path` delivers only that `std::u8string` rather than iterators into its internal representation, we can't avoid capturing it and copying to the returned `std::string`. Remove explicit `.u8string()` calls from a few existing `fsyspath` instances, now that `fsyspath` supports implicit conversion to `std::string`.
Diffstat (limited to 'indra/newview/llluamanager.cpp')
-rw-r--r--indra/newview/llluamanager.cpp8
1 files changed, 4 insertions, 4 deletions
diff --git a/indra/newview/llluamanager.cpp b/indra/newview/llluamanager.cpp
index 7fe5c1ece0..322717fbb9 100644
--- a/indra/newview/llluamanager.cpp
+++ b/indra/newview/llluamanager.cpp
@@ -317,7 +317,7 @@ LLRequireResolver::LLRequireResolver(lua_State *L, const std::string& path) :
void LLRequireResolver::findModule()
{
// If mPathToResolve is absolute, this replaces mSourceDir.
- auto absolutePath = (mSourceDir / mPathToResolve).u8string();
+ fsyspath absolutePath(mSourceDir / mPathToResolve);
// Push _MODULES table on stack for checking and saving to the cache
luaL_findtable(L, LUA_REGISTRYINDEX, "_MODULES", 1);
@@ -333,7 +333,7 @@ void LLRequireResolver::findModule()
// not already cached - prep error message just in case
auto fail{
- [L=L, path=mPathToResolve.u8string()]()
+ [L=L, path=mPathToResolve.string()]()
{ luaL_error(L, "could not find require('%s')", path.data()); }};
if (mPathToResolve.is_absolute())
@@ -348,10 +348,10 @@ void LLRequireResolver::findModule()
{
// if path is already absolute, operator/() preserves it
auto abspath(fsyspath(gDirUtilp->getAppRODataDir()) / path.asString());
- std::string absolutePathOpt = (abspath / mPathToResolve).u8string();
+ fsyspath absolutePathOpt = (abspath / mPathToResolve);
if (absolutePathOpt.empty())
- luaL_error(L, "error requiring module '%s'", mPathToResolve.u8string().data());
+ luaL_error(L, "error requiring module '%s'", mPathToResolve.string().data());
if (findModuleImpl(absolutePathOpt))
return;