Skip to content

Commit

Permalink
talipot-core/TlpTools: Remove use of codecvt deprecated in C++20
Browse files Browse the repository at this point in the history
  • Loading branch information
anlambert committed Mar 19, 2024
1 parent 2193c1b commit 9c25f62
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 14 deletions.
4 changes: 3 additions & 1 deletion library/talipot-core/include/talipot/TlpTools.h
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,9 @@ TLP_SCOPE std::istream *getZstdInputFileStream(const std::string &filename);
TLP_SCOPE std::ostream *getZstdOutputFileStream(const std::string &filename,
int compressionLevel = 3);

TLP_SCOPE std::wstring utf8to16(const std::string &s);
#ifdef WIN32
TLP_SCOPE std::wstring winPath(const std::string &path);
#endif

TLP_SCOPE std::vector<std::string> tokenize(const std::string &str,
const std::string &delimiter = " ");
Expand Down
17 changes: 8 additions & 9 deletions library/talipot-core/src/TlpTools.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,6 @@
*
*/

#include <locale>
#include <codecvt>

#ifndef _WIN32
#include <unistd.h>
#endif
Expand Down Expand Up @@ -384,7 +381,7 @@ int tlp::statPath(const std::string &pathname, tlp_stat_t *buf) {
#ifndef WIN32
return stat(pathname.c_str(), buf);
#else
std::wstring utf16pathname = utf8to16(pathname);
std::wstring utf16pathname = winPath(pathname);
return _wstat(utf16pathname.c_str(), buf);
#endif
}
Expand Down Expand Up @@ -429,7 +426,7 @@ std::ostream *tlp::getOutputFileStream(const std::string &filename, std::ios_bas

std::istream *tlp::getZlibInputFileStream(const std::string &filename) {
#if defined(WIN32) && ZLIB_VERNUM >= 0x1270
std::wstring utf16filename = utf8to16(filename);
std::wstring utf16filename = winPath(filename);
return new igzstream(utf16filename.c_str(), ios::in | ios::binary);
#else
return new igzstream(filename.c_str(), ios::in | ios::binary);
Expand All @@ -440,7 +437,7 @@ std::istream *tlp::getZlibInputFileStream(const std::string &filename) {

std::ostream *tlp::getZlibOutputFileStream(const std::string &filename) {
#if defined(WIN32) && ZLIB_VERNUM >= 0x1270
std::wstring utf16filename = utf8to16(filename);
std::wstring utf16filename = winPath(filename);
return new ogzstream(utf16filename.c_str(), ios::out | ios::binary);
#else
return new ogzstream(filename.c_str(), ios::out | ios::binary);
Expand All @@ -461,10 +458,12 @@ std::ostream *tlp::getZstdOutputFileStream(const std::string &filename, int comp

//=========================================================

wstring tlp::utf8to16(const string &s) {
wstring_convert<codecvt_utf8_utf16<wchar_t>, wchar_t> conv;
return conv.from_bytes(s);
#ifdef WIN32
wstring tlp::winPath(const string &path) {
auto u8path = std::u8string(path.begin(), path.end());
return filesystem::path(u8path.begin(), u8path.end()).wstring();
}
#endif

//=========================================================

Expand Down
4 changes: 2 additions & 2 deletions library/talipot-python/src/PythonInterpreter.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
*
* Copyright (C) 2019-2023 The Talipot developers
* Copyright (C) 2019-2024 The Talipot developers
*
* Talipot is a fork of Tulip, created by David Auber
* and the Tulip development Team from LaBRI, University of Bordeaux
Expand Down Expand Up @@ -181,7 +181,7 @@ PythonInterpreter::PythonInterpreter()
QString pythonHome = PythonVersionChecker::getPythonHome();
static const std::string tlpPythonHome =
QStringToTlpString(QDir(tlpStringToQString(tlp::TalipotLibDir + "/..")).absolutePath());
static const std::wstring tlpPythonHomeW = utf8to16(tlpPythonHome);
static const std::wstring tlpPythonHomeW = winPath(tlpPythonHome);
if (QDir(tlpStringToQString(tlpPythonHome) + "/lib/python" + _pythonVersion).exists() ||
QDir(tlpStringToQString(tlpPythonHome) + "/DLLs").exists()) {
// Adjust Python home when Talipot has been installed through a Windows installer,
Expand Down
4 changes: 2 additions & 2 deletions plugins/import/Graphviz/GraphvizImport.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
*
* Copyright (C) 2019-2023 The Talipot developers
* Copyright (C) 2019-2024 The Talipot developers
*
* Talipot is a fork of Tulip, created by David Auber
* and the Tulip development Team from LaBRI, University of Bordeaux
Expand Down Expand Up @@ -86,7 +86,7 @@ class GraphvizImport : public ImportModule {
#ifndef WIN32
FILE *fd = fopen(fn.c_str(), "r");
#else
wstring wfn = utf8to16(fn);
wstring wfn = winPath(fn);
FILE *fd = _wfopen(reinterpret_cast<const wchar_t *>(wfn.c_str()), L"r");
#endif

Expand Down

0 comments on commit 9c25f62

Please sign in to comment.