Merge branch 'main' into vec3-models-loader

This commit is contained in:
MihailRis
2024-10-26 12:55:10 +03:00
15 changed files with 181 additions and 27 deletions
+15 -4
View File
@@ -7,12 +7,11 @@
#include <sstream>
#include "typedefs.hpp"
#include "stringutil.hpp"
#ifdef _WIN32
#include <Windows.h>
#include "stringutil.hpp"
void platform::configure_encoding() {
// set utf-8 encoding to console output
SetConsoleOutputCP(CP_UTF8);
@@ -35,7 +34,6 @@ std::string platform::detect_locale() {
.replace(2, 1, "_")
.substr(0, 5);
}
#else
void platform::configure_encoding() {
@@ -49,5 +47,18 @@ std::string platform::detect_locale() {
return preferredLocaleName.substr(0, 5);
}
#endif
void platform::open_folder(const std::filesystem::path& folder) {
if (!std::filesystem::is_directory(folder)) {
return;
}
#ifdef __APPLE__
auto cmd = "open "+util::quote(folder.u8string());
#elif defined(_WIN32)
auto cmd = "start explorer "+util::quote(folder.u8string());
#else
auto cmd = "xdg-open "+util::quote(folder.u8string());
#endif
system(cmd.c_str());
}
+5 -1
View File
@@ -1,9 +1,13 @@
#pragma once
#include <string>
#include <filesystem>
namespace platform {
void configure_encoding();
// @return environment locale in ISO format ll_CC
/// @return environment locale in ISO format ll_CC
std::string detect_locale();
/// @brief Open folder using system file manager asynchronously
/// @param folder target folder
void open_folder(const std::filesystem::path& folder);
}
+11 -1
View File
@@ -128,7 +128,7 @@ inline uint utf8_len(ubyte cp) {
if ((cp & 0xF8) == 0xF0) {
return 4;
}
return 0;
throw std::runtime_error("utf8 decode error");
}
uint32_t util::decode_utf8(uint& size, const char* chr) {
@@ -156,6 +156,16 @@ size_t util::crop_utf8(std::string_view s, size_t maxSize) {
return pos;
}
size_t util::length_utf8(std::string_view s) {
size_t length = 0;
size_t pos = 0;
while (pos < s.length()) {
pos += utf8_len(s[pos]);
length++;
}
return length;
}
template<class C>
std::string xstr2str_utf8(const std::basic_string<C>& xs) {
std::vector<char> chars;
+5
View File
@@ -44,6 +44,11 @@ namespace util {
/// @param maxSize max encoded string length after crop
/// @return cropped string size (less or equal to maxSize)
size_t crop_utf8(std::string_view s, size_t maxSize);
/// @brief Measure utf8-encoded string length
/// @param s source encoded string
/// @return unicode string length (number of codepoints)
size_t length_utf8(std::string_view s);
bool is_integer(const std::string& text);
bool is_integer(const std::wstring& text);