bux API Reference 1.12.5
Static library of whatever are seen required in general purpose but not directly supported from Modern C++. Or whatever reusable originated from my side projects.
Loading...
Searching...
No Matches
StrUtil.h
Go to the documentation of this file.
1#pragma once
2
3#include <functional> // std::function<>
4#include <stdexcept> // std::exception
5#include <string> // std::string
6#include <string_view> // std::string_view
7#include <typeinfo> // return type of typeid()
8
9namespace bux {
10
11//
12// Externs
13//
14const char *ord_suffix(size_t i);
15std::string expand_env(const char *s);
16
17std::string _HRTN(const char *originalName);
18std::string OXCPT(const std::exception &e);
19
20template<typename T>
21void split(std::basic_string_view<T> token_list, std::basic_string_view<T> splitters,
22 const std::function<void(std::basic_string_view<T>)>& apply_token,
23 const std::function<void(std::basic_string_view<T>)>& apply_delim = {})
24{
25 for (size_t start_off = 0; start_off < token_list.size();)
26 {
27 const auto first_not_of_off = token_list.find_first_not_of(splitters, start_off);
28 if (first_not_of_off == std::string::npos)
29 break;
30
31 if (apply_delim && start_off < first_not_of_off)
32 apply_delim(token_list.substr(start_off, first_not_of_off - start_off));
33
34 start_off = first_not_of_off;
35 const auto end_off = token_list.find_first_of(splitters, start_off);
36 if (end_off == std::string::npos)
37 {
38 if (apply_token && start_off < token_list.size())
39 apply_token(token_list.substr(start_off));
40
41 break;
42 }
43 if (apply_token)
44 apply_token(token_list.substr(start_off, end_off - start_off));
45
46 start_off = end_off;
47 }
48}
49
50} // namespace bux
51
54#define HRTN(t) bux::_HRTN(typeid(t).name())
55using bux::OXCPT;
THE common namespace of bux library.
Definition AtomiX.cpp:3
const char * ord_suffix(size_t i)
Definition StrUtil.cpp:25
std::string _HRTN(const char *originalName)
Definition StrUtil.cpp:73
std::string OXCPT(const std::exception &e)
Definition StrUtil.cpp:131
void split(std::basic_string_view< T > token_list, std::basic_string_view< T > splitters, const std::function< void(std::basic_string_view< T >)> &apply_token, const std::function< void(std::basic_string_view< T >)> &apply_delim={})
Definition StrUtil.h:21
std::string expand_env(const char *s)
Definition StrUtil.cpp:46