Browse Source

Rename string::U8toU16 to UTF8toUTF16 and U16toU8 to UTF16toUTF8.

tags/v2.0.0
Andrew Belt 4 years ago
parent
commit
ed1842a743
6 changed files with 18 additions and 18 deletions
  1. +2
    -2
      include/string.hpp
  2. +2
    -2
      src/asset.cpp
  3. +1
    -1
      src/common.cpp
  4. +1
    -1
      src/plugin.cpp
  5. +2
    -2
      src/string.cpp
  6. +10
    -10
      src/system.cpp

+ 2
- 2
include/string.hpp View File

@@ -60,8 +60,8 @@ These are only defined on Windows because the implementation uses Windows' API,
std::string and char* variables are considered UTF-8, anywhere in the program. std::string and char* variables are considered UTF-8, anywhere in the program.
See https://utf8everywhere.org/ for more information about VCV Rack's philosophy on string encoding, especially section 10 for rules VCV follows for handling text on Windows. See https://utf8everywhere.org/ for more information about VCV Rack's philosophy on string encoding, especially section 10 for rules VCV follows for handling text on Windows.
*/ */
std::string U16toU8(const std::wstring& w);
std::wstring U8toU16(const std::string& s);
std::string UTF16toUTF8(const std::wstring& w);
std::wstring UTF8toUTF16(const std::string& s);
#endif #endif






+ 2
- 2
src/asset.cpp View File

@@ -67,7 +67,7 @@ static void initSystemDir() {
assert(length > 0); assert(length > 0);
// Get folder of executable // Get folder of executable
PathRemoveFileSpecW(moduleBufW); PathRemoveFileSpecW(moduleBufW);
systemDir = string::U16toU8(moduleBufW);
systemDir = string::UTF16toUTF8(moduleBufW);
#endif #endif
#if defined ARCH_LIN #if defined ARCH_LIN
// Use the current working directory as the default path on Linux. // Use the current working directory as the default path on Linux.
@@ -90,7 +90,7 @@ static void initUserDir() {
wchar_t documentsBufW[MAX_PATH] = L"."; wchar_t documentsBufW[MAX_PATH] = L".";
HRESULT result = SHGetFolderPathW(NULL, CSIDL_MYDOCUMENTS, NULL, SHGFP_TYPE_CURRENT, documentsBufW); HRESULT result = SHGetFolderPathW(NULL, CSIDL_MYDOCUMENTS, NULL, SHGFP_TYPE_CURRENT, documentsBufW);
assert(result == S_OK); assert(result == S_OK);
userDir = system::join(string::U16toU8(documentsBufW), "Rack");
userDir = system::join(string::UTF16toUTF8(documentsBufW), "Rack");
#endif #endif
#if defined ARCH_MAC #if defined ARCH_MAC
// Get home directory // Get home directory


+ 1
- 1
src/common.cpp View File

@@ -6,7 +6,7 @@
#include <windows.h> #include <windows.h>


FILE* fopen_u8(const char* filename, const char* mode) { FILE* fopen_u8(const char* filename, const char* mode) {
return _wfopen(rack::string::U8toU16(filename).c_str(), rack::string::U8toU16(mode).c_str());
return _wfopen(rack::string::UTF8toUTF16(filename).c_str(), rack::string::UTF8toUTF16(mode).c_str());
} }


#endif #endif


+ 1
- 1
src/plugin.cpp View File

@@ -44,7 +44,7 @@ namespace plugin {
static void* loadLibrary(std::string libraryPath) { static void* loadLibrary(std::string libraryPath) {
#if defined ARCH_WIN #if defined ARCH_WIN
SetErrorMode(SEM_NOOPENFILEERRORBOX | SEM_FAILCRITICALERRORS); SetErrorMode(SEM_NOOPENFILEERRORBOX | SEM_FAILCRITICALERRORS);
std::wstring libraryFilenameW = string::U8toU16(libraryPath);
std::wstring libraryFilenameW = string::UTF8toUTF16(libraryPath);
HINSTANCE handle = LoadLibraryW(libraryFilenameW.c_str()); HINSTANCE handle = LoadLibraryW(libraryFilenameW.c_str());
SetErrorMode(0); SetErrorMode(0);
if (!handle) { if (!handle) {


+ 2
- 2
src/string.cpp View File

@@ -206,7 +206,7 @@ bool CaseInsensitiveCompare::operator()(const std::string& a, const std::string&




#if defined ARCH_WIN #if defined ARCH_WIN
std::string U16toU8(const std::wstring& w) {
std::string UTF16toUTF8(const std::wstring& w) {
if (w.empty()) if (w.empty())
return ""; return "";
// Compute length of output buffer // Compute length of output buffer
@@ -221,7 +221,7 @@ std::string U16toU8(const std::wstring& w) {
} }




std::wstring U8toU16(const std::string& s) {
std::wstring UTF8toUTF16(const std::string& s) {
if (s.empty()) if (s.empty())
return L""; return L"";
// Compute length of output buffer // Compute length of output buffer


+ 10
- 10
src/system.cpp View File

@@ -306,7 +306,7 @@ void archiveFolder(const std::string& archivePath, const std::string& folderPath
throw Exception("Archiver could not set filter option: %s", archive_error_string(a)); throw Exception("Archiver could not set filter option: %s", archive_error_string(a));


#if defined ARCH_WIN #if defined ARCH_WIN
r = archive_write_open_filename_w(a, string::U8toU16(archivePath).c_str());
r = archive_write_open_filename_w(a, string::UTF8toUTF16(archivePath).c_str());
#else #else
r = archive_write_open_filename(a, archivePath.c_str()); r = archive_write_open_filename(a, archivePath.c_str());
#endif #endif
@@ -318,7 +318,7 @@ void archiveFolder(const std::string& archivePath, const std::string& folderPath
struct archive* disk = archive_read_disk_new(); struct archive* disk = archive_read_disk_new();
DEFER({archive_read_free(disk);}); DEFER({archive_read_free(disk);});
#if defined ARCH_WIN #if defined ARCH_WIN
r = archive_read_disk_open_w(disk, string::U8toU16(folderPath).c_str());
r = archive_read_disk_open_w(disk, string::UTF8toUTF16(folderPath).c_str());
#else #else
r = archive_read_disk_open(disk, folderPath.c_str()); r = archive_read_disk_open(disk, folderPath.c_str());
#endif #endif
@@ -343,14 +343,14 @@ void archiveFolder(const std::string& archivePath, const std::string& folderPath
// Convert absolute path to relative path // Convert absolute path to relative path
std::string entryPath; std::string entryPath;
#if defined ARCH_WIN #if defined ARCH_WIN
entryPath = string::U16toU8(archive_entry_pathname_w(entry));
entryPath = string::UTF16toUTF8(archive_entry_pathname_w(entry));
#else #else
entryPath = archive_entry_pathname(entry); entryPath = archive_entry_pathname(entry);
#endif #endif
entryPath = getRelativePath(entryPath, folderPath); entryPath = getRelativePath(entryPath, folderPath);
#if defined ARCH_WIN #if defined ARCH_WIN
// FIXME This doesn't seem to set UTF-8 paths on Windows. // FIXME This doesn't seem to set UTF-8 paths on Windows.
archive_entry_copy_pathname_w(entry, string::U8toU16(entryPath).c_str());
archive_entry_copy_pathname_w(entry, string::UTF8toUTF16(entryPath).c_str());
#else #else
archive_entry_set_pathname(entry, entryPath.c_str()); archive_entry_set_pathname(entry, entryPath.c_str());
#endif #endif
@@ -362,7 +362,7 @@ void archiveFolder(const std::string& archivePath, const std::string& folderPath


// Manually copy data // Manually copy data
#if defined ARCH_WIN #if defined ARCH_WIN
std::string entrySourcePath = string::U16toU8(archive_entry_sourcepath_w(entry));
std::string entrySourcePath = string::UTF16toUTF8(archive_entry_sourcepath_w(entry));
#else #else
std::string entrySourcePath = archive_entry_sourcepath(entry); std::string entrySourcePath = archive_entry_sourcepath(entry);
#endif #endif
@@ -389,7 +389,7 @@ void unarchiveToFolder(const std::string& archivePath, const std::string& folder
archive_read_support_format_tar(a); archive_read_support_format_tar(a);
// archive_read_support_format_all(a); // archive_read_support_format_all(a);
#if defined ARCH_WIN #if defined ARCH_WIN
r = archive_read_open_filename_w(a, string::U8toU16(archivePath).c_str(), 1 << 16);
r = archive_read_open_filename_w(a, string::UTF8toUTF16(archivePath).c_str(), 1 << 16);
#else #else
r = archive_read_open_filename(a, archivePath.c_str(), 1 << 14); r = archive_read_open_filename(a, archivePath.c_str(), 1 << 14);
#endif #endif
@@ -420,7 +420,7 @@ void unarchiveToFolder(const std::string& archivePath, const std::string& folder
throw Exception("Unarchiver does not support absolute tar paths: %s", entryPath.c_str()); throw Exception("Unarchiver does not support absolute tar paths: %s", entryPath.c_str());
entryPath = (fs::u8path(folderPath) / fs::u8path(entryPath)).generic_u8string(); entryPath = (fs::u8path(folderPath) / fs::u8path(entryPath)).generic_u8string();
#if defined ARCH_WIN #if defined ARCH_WIN
archive_entry_copy_pathname_w(entry, string::U8toU16(entryPath).c_str());
archive_entry_copy_pathname_w(entry, string::UTF8toUTF16(entryPath).c_str());
#else #else
archive_entry_set_pathname(entry, entryPath.c_str()); archive_entry_set_pathname(entry, entryPath.c_str());
#endif #endif
@@ -621,7 +621,7 @@ void openBrowser(const std::string& url) {
std::system(command.c_str()); std::system(command.c_str());
#endif #endif
#if defined ARCH_WIN #if defined ARCH_WIN
ShellExecuteW(NULL, L"open", string::U8toU16(url).c_str(), NULL, NULL, SW_SHOWDEFAULT);
ShellExecuteW(NULL, L"open", string::UTF8toUTF16(url).c_str(), NULL, NULL, SW_SHOWDEFAULT);
#endif #endif
} }


@@ -636,7 +636,7 @@ void openFolder(const std::string& path) {
std::system(command.c_str()); std::system(command.c_str());
#endif #endif
#if defined ARCH_WIN #if defined ARCH_WIN
ShellExecuteW(NULL, L"explore", string::U8toU16(path).c_str(), NULL, NULL, SW_SHOWDEFAULT);
ShellExecuteW(NULL, L"explore", string::UTF8toUTF16(path).c_str(), NULL, NULL, SW_SHOWDEFAULT);
#endif #endif
} }


@@ -648,7 +648,7 @@ void runProcessDetached(const std::string& path) {
shExInfo.cbSize = sizeof(shExInfo); shExInfo.cbSize = sizeof(shExInfo);
shExInfo.lpVerb = L"runas"; shExInfo.lpVerb = L"runas";


std::wstring pathW = string::U8toU16(path);
std::wstring pathW = string::UTF8toUTF16(path);
shExInfo.lpFile = pathW.c_str(); shExInfo.lpFile = pathW.c_str();
shExInfo.nShow = SW_SHOW; shExInfo.nShow = SW_SHOW;




Loading…
Cancel
Save