mirror of
https://github.com/open-goal/jak-project.git
synced 2024-10-20 21:27:52 -04:00
00ac12094e
- lets you split up your `startup.gc` file into two sections - one that runs on initial startup / reloads - the other that runs when you listen to a target - allows for customization of the keybinds added a month or so ago - removes a useless flag (--startup-cmd) and marks others for deprecation. - added another help prompt that lists all the keybinds and what they do Co-authored-by: water <awaterford111445@gmail.com>
61 lines
1.4 KiB
C++
61 lines
1.4 KiB
C++
#include "string_util.h"
|
|
|
|
#include <regex>
|
|
|
|
#include "common/util/diff.h"
|
|
|
|
namespace str_util {
|
|
|
|
const std::string WHITESPACE = " \n\r\t\f\v";
|
|
|
|
bool contains(const std::string& s, const std::string& substr) {
|
|
return s.find(substr) != std::string::npos;
|
|
}
|
|
|
|
bool starts_with(const std::string& s, const std::string& prefix) {
|
|
return s.rfind(prefix) == 0;
|
|
}
|
|
|
|
std::string ltrim(const std::string& s) {
|
|
size_t start = s.find_first_not_of(WHITESPACE);
|
|
return (start == std::string::npos) ? "" : s.substr(start);
|
|
}
|
|
|
|
std::string rtrim(const std::string& s) {
|
|
size_t end = s.find_last_not_of(WHITESPACE);
|
|
return (end == std::string::npos) ? "" : s.substr(0, end + 1);
|
|
}
|
|
|
|
std::string trim(const std::string& s) {
|
|
return rtrim(ltrim(s));
|
|
}
|
|
|
|
int line_count(const std::string& str) {
|
|
int result = 0;
|
|
for (auto& c : str) {
|
|
if (c == '\n') {
|
|
result++;
|
|
}
|
|
}
|
|
return result;
|
|
}
|
|
|
|
// NOTE - this won't work running within gk.exe!
|
|
bool valid_regex(const std::string& regex) {
|
|
try {
|
|
std::regex re(regex);
|
|
} catch (const std::regex_error& e) {
|
|
return false;
|
|
}
|
|
return true;
|
|
}
|
|
|
|
std::string diff(const std::string& lhs, const std::string& rhs) {
|
|
return google_diff::diff_strings(lhs, rhs);
|
|
}
|
|
/// Default splits on \n characters
|
|
std::vector<std::string> split(const ::std::string& str, char delimiter) {
|
|
return google_diff::split_string(str, delimiter);
|
|
}
|
|
} // namespace str_util
|