mirror of
https://github.com/ByteWelder/Tactility.git
synced 2026-02-18 19:03:16 +00:00
- Added `AppHub` app - Added `AppHubDetails` app - Added `cJSON` dependency - Renamed `AppSim` module to `FirmwareSim` - Added extra `tt::app::alertdialg::start()` - Renamed `addApp()`, `removeApp()`, `findAppById()` and `getApps()` to `addAppManifest()`, `removeAppManifest()`, `findAppManifestById()` and `getAppManifests()` - Added `tt::lvgl::toolbar_clear_actions()` - Added `tt::network::EspHttpClient` as a thread-safe wrapper around `esp_http_client` - Added `tt::network::http::download()` to download files - Added `tt::network::ntp::isSynced()` - When time is synced, the timestamp is stored in NVS flash. On boot, it is restored. This helps SSL connections when doing a quick reset: when WiFi reconnects, the user doesn't have to wait for NTP sync before SSL works. - Added `tt::json::Reader` as a `cJSON` wrapper - Added `int64_t` support for `Preferences` - Added `int64_t` support for `Bundle` - Added dependencies: `cJSON`, `esp-tls` - When time is synced via NTP, disable time sync. - Added docs to 'tt::file::` functions - Added `tt::string::join()` that works with `std::vector<const char*>` - Fixed `tt::file::getLastPathSegment()` for the scenario when a path was passed with only a single segment - Set `CONFIG_ESP_MAIN_TASK_STACK_SIZE=5120` (from about 3k) for all boards - Set `CONFIG_MBEDTLS_SSL_PROTO_TLS1_3=y` for all boards
136 lines
3.5 KiB
C++
136 lines
3.5 KiB
C++
#include "Tactility/StringUtils.h"
|
|
|
|
#include <cstring>
|
|
#include <ranges>
|
|
#include <sstream>
|
|
#include <string>
|
|
|
|
namespace tt::string {
|
|
|
|
bool getPathParent(const std::string& path, std::string& output) {
|
|
auto index = path.find_last_of('/');
|
|
if (index == std::string::npos) {
|
|
return false;
|
|
} else if (index == 0) {
|
|
output = "/";
|
|
return true;
|
|
} else {
|
|
output = path.substr(0, index);
|
|
return true;
|
|
}
|
|
}
|
|
|
|
std::string getLastPathSegment(const std::string& path) {
|
|
auto index = path.find_last_of('/');
|
|
if (index != std::string::npos) {
|
|
return path.substr(index + 1);
|
|
} else {
|
|
return "";
|
|
}
|
|
}
|
|
|
|
void split(const std::string& input, const std::string& delimiter, std::function<void(const std::string&)> callback) {
|
|
size_t token_index = 0;
|
|
size_t delimiter_index;
|
|
const size_t delimiter_length = delimiter.length();
|
|
|
|
while ((delimiter_index = input.find(delimiter, token_index)) != std::string::npos) {
|
|
std::string token = input.substr(token_index, delimiter_index - token_index);
|
|
token_index = delimiter_index + delimiter_length;
|
|
callback(token);
|
|
}
|
|
|
|
auto end_token = input.substr(token_index);
|
|
if (!end_token.empty()) {
|
|
callback(end_token);
|
|
}
|
|
}
|
|
|
|
std::vector<std::string> split(const std::string&input, const std::string&delimiter) {
|
|
std::vector<std::string> result;
|
|
split(input, delimiter, [&result](const std::string& token) {
|
|
result.push_back(token);
|
|
});
|
|
return result;
|
|
}
|
|
|
|
std::string join(const std::vector<const char*>& input, const std::string& delimiter) {
|
|
std::stringstream stream;
|
|
size_t size = input.size();
|
|
|
|
if (size == 0) {
|
|
return "";
|
|
} else if (size == 1) {
|
|
return input.front();
|
|
} else {
|
|
auto iterator = input.begin();
|
|
while (iterator != input.end()) {
|
|
stream << *iterator;
|
|
iterator++;
|
|
if (iterator != input.end()) {
|
|
stream << delimiter;
|
|
}
|
|
}
|
|
}
|
|
|
|
return stream.str();
|
|
}
|
|
|
|
std::string join(const std::vector<std::string>& input, const std::string& delimiter) {
|
|
std::stringstream stream;
|
|
size_t size = input.size();
|
|
|
|
if (size == 0) {
|
|
return "";
|
|
} else if (size == 1) {
|
|
return input.front();
|
|
} else {
|
|
auto iterator = input.begin();
|
|
while (iterator != input.end()) {
|
|
stream << *iterator;
|
|
iterator++;
|
|
if (iterator != input.end()) {
|
|
stream << delimiter;
|
|
}
|
|
}
|
|
}
|
|
|
|
return stream.str();
|
|
}
|
|
|
|
std::string removeFileExtension(const std::string& input) {
|
|
auto index = input.find('.');
|
|
if (index != std::string::npos) {
|
|
return input.substr(0, index);
|
|
} else {
|
|
return input;
|
|
}
|
|
}
|
|
|
|
bool isAsciiHexString(const std::string& input) {
|
|
// Find invalid characters
|
|
return std::ranges::views::filter(input, [](char character){
|
|
if (
|
|
(('0' <= character) && ('9' >= character)) ||
|
|
(('a' <= character) && ('f' >= character)) ||
|
|
(('A' <= character) && ('F' >= character))
|
|
) {
|
|
return false;
|
|
} else {
|
|
return true;
|
|
}
|
|
}).empty();
|
|
}
|
|
|
|
std::string trim(const std::string& input, const std::string& characters) {
|
|
auto index = input.find_first_not_of(characters);
|
|
if (index == std::string::npos) {
|
|
return "";
|
|
} else {
|
|
auto end_index = input.find_last_not_of(characters);
|
|
return input.substr(index, end_index - index + 1);
|
|
}
|
|
}
|
|
|
|
} // namespace
|