40 #include <unordered_set>
60 auto it = std::find(vec.begin(), vec.end(), element);
80 if (vec_1.size() != vec_2.size())
85 std::sort(vec_1.begin(), vec_1.end());
86 std::sort(vec_2.begin(), vec_2.end());
88 return vec_1 == vec_2;
100 return (value >> index) & 1;
112 return value | ((
u64)1 << index);
124 return value & ~((
u64)1 << index);
136 return value ^ ((
u64)1 << index);
149 if (s.length() >= end.length())
151 return (0 == s.compare(s.length() - end.length(), end.length(), end));
169 if (s.length() >= start.length())
171 return (0 == s.compare(0, start.length(), start));
188 return std::all_of(s.begin(), s.end(), ::isdigit);
200 if (s.empty() || ((!isdigit(s[0])) && (s[0] !=
'-') && (s[0] !=
'+')))
206 strtol(s.c_str(), &p, 10);
220 std::stringstream ss(s.c_str());
223 return (ss.eof() && !ss.fail());
237 CORE_API std::vector<T>
split(
const T& s,
const char delim,
bool obey_brackets =
false)
239 std::vector<T> result;
244 int bracket_level = 0;
246 for (
size_t i = 0; i < s.length(); ++i)
264 if (bracket_level < 0)
271 if (bracket_level == 0)
273 result.push_back(item);
288 result.push_back(item);
293 std::stringstream ss(s);
294 while (std::getline(ss, item, delim))
296 result.push_back(item);
299 if (s.back() == delim)
301 result.push_back(
"");
316 size_t start = s.find_first_not_of(to_remove);
318 if (start != std::string::npos)
320 return s.substr(start, s.size() - start);
338 size_t end = s.find_last_not_of(to_remove);
340 if (end != std::string::npos)
342 return s.substr(0, end + 1);
360 size_t start = s.find_first_not_of(to_remove);
361 size_t end = s.find_last_not_of(to_remove);
363 if (start != T::npos)
365 return s.substr(start, end - start + 1);
392 while ((pos = s.find(search, pos)) != T::npos)
394 s.replace(pos, search.length(),
replace);
411 template<
typename Iterator,
class Transform>
412 CORE_API std::string
join(
const std::string& joiner,
const Iterator& begin,
const Iterator& end,
const Transform& transform)
414 std::stringstream ss;
416 for (
auto it = begin; it != end; ++it)
423 ss << transform(*it);
437 template<
typename T,
class Transform>
438 CORE_API std::string
join(
const std::string& joiner,
const T& items,
const Transform& transform)
440 return join(joiner, items.begin(), items.end(), transform);
453 return join(joiner, items.begin(), items.end(), [](
const auto& v) { return v; });
466 std::transform(result.begin(), result.end(), result.begin(), [](
char c) { return std::toupper(c); });
480 std::transform(result.begin(), result.end(), result.begin(), [](
char c) { return std::tolower(c); });
495 auto position = s.find(substr, 0);
497 while (position != std::string::npos)
500 position = s.find(substr, position + 1);
512 template<
typename T,
template<
typename,
typename...>
class Container,
typename... Args>
515 return std::vector<T>(container.begin(), container.end());
524 template<
typename T,
template<
typename,
typename...>
class Container,
typename... Args>
527 return std::set<T>(container.begin(), container.end());
538 template<
typename T1,
typename T2>
541 for (
const auto& element : subset)
543 if (std::find(std::begin(superset), std::end(superset), element) == std::end(superset))
574 CORE_API std::filesystem::path
which(
const std::string&
name,
const std::string& path =
"");
669 CORE_API std::filesystem::path
get_file(std::string file_name, std::vector<std::filesystem::path> path_hints);
693 using iterator = std::filesystem::recursive_directory_iterator;
712 return std::filesystem::recursive_directory_iterator(p_);
722 return std::filesystem::recursive_directory_iterator();
726 std::filesystem::path p_;
735 using iterator = std::filesystem::directory_iterator;
755 return std::filesystem::directory_iterator(p_);
765 return std::filesystem::directory_iterator();
769 std::filesystem::path p_;
782 Color(
int _h = 0,
int _s = 0,
int _v = 0) : h(_h), s(_s), v(_v)
788 return "h=" + std::to_string(h) +
" s=" + std::to_string(s) +
" v=" + std::to_string(v);
DirectoryRange(std::filesystem::path path)
std::filesystem::directory_iterator iterator
std::filesystem::recursive_directory_iterator iterator
RecursiveDirectoryRange(std::filesystem::path path)
CORE_API T replace(const T &str, const T &search, const T &replace)
CORE_API bool ends_with(const T &s, const T &end)
CORE_API bool is_digits(const T &s)
CORE_API T ltrim(const T &s, const char *to_remove=" \t\r\n")
CORE_API bool starts_with(const T &s, const T &start)
std::filesystem::path get_config_directory()
CORE_API u64 set_bit(const u64 value, const u64 index)
std::filesystem::path get_user_share_directory()
bool vectors_have_same_content(std::vector< T > vec_1, std::vector< T > vec_2)
CORE_API T trim(const T &s, const char *to_remove=" \t\r\n")
std::filesystem::path get_first_directory_exists(std::vector< std::filesystem::path > path_hints)
CORE_API std::vector< T > split(const T &s, const char delim, bool obey_brackets=false)
CORE_API std::set< T > to_set(const Container< T, Args... > &container)
CORE_API u32 num_of_occurrences(const T &s, const T &substr)
CORE_API T rtrim(const T &s, const char *to_remove=" \t\r\n")
CORE_API u64 toggle_bit(const u64 value, const u64 index)
std::filesystem::path get_share_directory()
Result< std::filesystem::path > get_unique_temp_directory(const std::string &prefix, const u32 max_attmeps)
CORE_API u64 get_bit(const u64 value, const u64 index)
CORE_API std::string join(const std::string &joiner, const Iterator &begin, const Iterator &end, const Transform &transform)
std::vector< std::filesystem::path > get_gate_library_directories()
std::filesystem::path get_base_directory()
std::string get_open_source_licenses()
std::filesystem::path get_library_directory()
Result< u64 > wrapped_stoull(const std::string &s, const u32 base)
std::filesystem::path get_user_config_directory()
Result< u32 > wrapped_stoul(const std::string &s, const u32 base)
CORE_API bool is_integer(const T &s)
CORE_API T to_lower(const T &s)
CORE_API bool unordered_vector_erase(std::vector< T > &vec, T element)
CORE_API u64 clear_bit(const u64 value, const u64 index)
std::vector< std::filesystem::path > get_plugin_directories()
std::filesystem::path which(const std::string &name, const std::string &path)
CORE_API bool is_floating_point(const T &s)
CORE_API T to_upper(const T &s)
std::filesystem::path get_default_log_directory(std::filesystem::path source_file)
CORE_API std::vector< T > to_vector(const Container< T, Args... > &container)
bool folder_exists_and_is_accessible(const std::filesystem::path &folder)
bool file_exists(const std::string &filename)
std::filesystem::path get_binary_directory()
std::filesystem::path get_file(std::string file_name, std::vector< std::filesystem::path > path_hints)
CORE_API bool is_subset(const T1 &subset, const T2 &superset)
Color(int _h=0, int _s=0, int _v=0)