Repository :
https://github.com/colorer/Colorer-library
On branch : master
Link :
https://github.com/colorer/Colorer-library/commit/2998cfb1c130fa7b09379b266f25053a7ec07631
>---------------------------------------------------------------
commit 2998cfb1c130fa7b09379b266f25053a7ec07631
Author: Aleksey Dobrunov <
cta...@ctapmex.com>
Date: Sat Sep 12 23:40:56 2026 +0500
fix on legacy string
>---------------------------------------------------------------
2998cfb1c130fa7b09379b266f25053a7ec07631
src/colorer/utils/Environment.cpp | 11 ++++++++++-
src/colorer/utils/Environment.h | 2 ++
src/colorer/xml/libxml2/LibXmlReader.cpp | 6 +++---
tests/unit/test_environment.cpp | 1 +
4 files changed, 16 insertions(+), 4 deletions(-)
diff --git a/src/colorer/utils/Environment.cpp b/src/colorer/utils/Environment.cpp
index 96bf79e..7327dc2 100644
--- a/src/colorer/utils/Environment.cpp
+++ b/src/colorer/utils/Environment.cpp
@@ -29,7 +29,7 @@ fs::path Environment::to_filepath(const UnicodeString* str)
#ifdef _WINDOWS
fs::path result = UStr::to_stdwstr(str);
#else
- fs::path result = UStr::to_stdstr(str);
+ fs::path result = to_utf8_path(*str);
#endif
return result;
}
@@ -43,6 +43,15 @@ UnicodeString Environment::from_filepath(const fs::path& path)
#endif
}
+std::string Environment::to_utf8_path(const UnicodeString& str)
+{
+#ifdef COLORER_FEATURE_ICU
+ return UStr::to_stdstr(&str);
+#else
+ return {str.getChars(Encodings::ENC_UTF8)};
+#endif
+}
+
uUnicodeString Environment::getOSEnv(const UnicodeString& name)
{
#ifdef _WINDOWS
diff --git a/src/colorer/utils/Environment.h b/src/colorer/utils/Environment.h
index de122ad..a565b47 100644
--- a/src/colorer/utils/Environment.h
+++ b/src/colorer/utils/Environment.h
@@ -2,6 +2,7 @@
#define COLORER_ENVIRONMENT_H
#include <regex>
+#include <string>
#include <vector>
#include "colorer/Common.h"
#include "colorer/utils/FileSystems.h"
@@ -18,6 +19,7 @@ class Environment
static fs::path getClearFilePath(const UnicodeString* basePath, const UnicodeString* relPath);
static fs::path to_filepath(const UnicodeString* str);
static UnicodeString from_filepath(const fs::path& path);
+ static std::string to_utf8_path(const UnicodeString& str);
static std::vector<UnicodeString> getFilesFromPath(const UnicodeString& path);
static bool isRegularFile(const UnicodeString* basePath, const UnicodeString* relPath, UnicodeString& fullPath);
diff --git a/src/colorer/xml/libxml2/LibXmlReader.cpp b/src/colorer/xml/libxml2/LibXmlReader.cpp
index 9f82491..ef424b5 100644
--- a/src/colorer/xml/libxml2/LibXmlReader.cpp
+++ b/src/colorer/xml/libxml2/LibXmlReader.cpp
@@ -59,7 +59,7 @@ XmlLoadContext* loadContext(xmlParserCtxtPtr ctxt)
UnicodeString decodeFilesystemXmlUrl(const UnicodeString& url)
{
- const auto utf8 = UStr::to_stdstr(&url);
+ const auto utf8 = colorer::Environment::to_utf8_path(url);
char* const unescaped = xmlURIUnescapeString(utf8.c_str(), -1, nullptr);
UnicodeString decoded;
if (unescaped != nullptr) {
@@ -117,7 +117,7 @@ LibXmlReader::LibXmlReader(const UnicodeString& source_file)
const XmlLoadCurrent current(&load);
xmlDocPtr xmldoc =
- xmlCtxtReadFile(ctxt, UStr::to_stdstr(&source_file).c_str(), nullptr, XML_PARSE_NOENT | XML_PARSE_NONET);
+ xmlCtxtReadFile(ctxt, colorer::Environment::to_utf8_path(source_file).c_str(), nullptr, XML_PARSE_NOENT | XML_PARSE_NONET);
parsed = xmldoc != nullptr;
if (xmldoc != nullptr) {
xmlNode* current_node = xmlDocGetRootElement(xmldoc);
@@ -309,7 +309,7 @@ xmlParserInputPtr LibXmlReader::xmlMyExternalEntityLoader(const char* URL, const
}
load->is_first_call = false;
- return xmlNewInputFromFile(ctxt, UStr::to_stdstr(&string_url).c_str());
+ return xmlNewInputFromFile(ctxt, colorer::Environment::to_utf8_path(string_url).c_str());
}
void LibXmlReader::xml_error_func(void* /*ctx*/, const char* msg, ...)
diff --git a/tests/unit/test_environment.cpp b/tests/unit/test_environment.cpp
index 649ea27..70cd0e8 100644
--- a/tests/unit/test_environment.cpp
+++ b/tests/unit/test_environment.cpp
@@ -81,5 +81,6 @@ TEST_CASE("normalizePath and isRegularFile keep Cyrillic and spaces", "[environm
const auto normalized = colorer::Environment::normalizePath(&as_unicode);
REQUIRE(colorer::Environment::isRegularFile(*normalized));
REQUIRE(colorer::Environment::to_filepath(normalized.get()) == fs::path(file).lexically_normal());
+ REQUIRE(colorer::Environment::to_utf8_path(as_unicode) == file.u8string());
}