mirror of
https://github.com/open-goal/jak-project
synced 2026-05-29 08:43:08 -04:00
tests: make the offline tests aware of the current terminals row count (#2105)
This fixes the hideous output when your terminal would be too small to hold all the threads.
This commit is contained in:
@@ -0,0 +1,50 @@
|
||||
#include "string_util.h"
|
||||
|
||||
#include <regex>
|
||||
|
||||
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;
|
||||
}
|
||||
} // namespace str_util
|
||||
Reference in New Issue
Block a user