mirror of
https://github.com/ByteWelder/Tactility.git
synced 2026-02-18 19:03:16 +00:00
- Refactor the way apps work: Instead of a C interface, they are now C++ classes. The main reasoning is that attaching data to an app was cumbersome. Having different implementations for different kinds of apps was cumbersome too. (3 or 4 layers of manifest nesting for the TactilityC project) - External apps are still written in C, but they get a createData/destroyData in their manifest, so: - External apps now have their own manifest. - All functions in the original AppManifest are removed and replaced by a single `createApp` function - External apps now automatically register (each app individually!) when they run the first time. As a side-effect they become visible in the `AppList` app! - Adapted all apps for the new interface. - Adapted all internal logic for these changes (Gui, ViewPort, Loader, AppContext, AppInstance, etc.) - Rewrote parts of Loader to use std::shared_ptr to make the code much safer. - Added a refcount check for the `AppInstance` and `App` at the end of their lifecycle. Show warning if refcount is too high.
91 lines
2.2 KiB
C++
91 lines
2.2 KiB
C++
#include "StringUtils.h"
|
|
#include <cstring>
|
|
#include <sstream>
|
|
|
|
namespace tt::string {
|
|
|
|
int findLastIndex(const char* text, size_t from_index, char find) {
|
|
for (int i = (int)from_index; i >= 0; i--) {
|
|
if (text[i] == find) {
|
|
return (int)i;
|
|
}
|
|
}
|
|
return -1;
|
|
}
|
|
|
|
bool getPathParent(const std::string& path, std::string& output) {
|
|
int index = findLastIndex(path.c_str(), path.length() - 1, '/');
|
|
if (index == -1) {
|
|
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 "";
|
|
}
|
|
}
|
|
|
|
std::vector<std::string> split(const std::string&input, const std::string&delimiter) {
|
|
size_t token_index = 0;
|
|
size_t delimiter_index;
|
|
const size_t delimiter_length = delimiter.length();
|
|
std::string token;
|
|
std::vector<std::string> result;
|
|
|
|
while ((delimiter_index = input.find(delimiter, token_index)) != std::string::npos) {
|
|
token = input.substr(token_index, delimiter_index - token_index);
|
|
token_index = delimiter_index + delimiter_length;
|
|
result.push_back(token);
|
|
}
|
|
|
|
auto end_token = input.substr(token_index);
|
|
if (!end_token.empty()) {
|
|
result.push_back(end_token);
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
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;
|
|
}
|
|
}
|
|
|
|
} // namespace
|