35 std::unique_ptr<char, void(*)(void*)> realname(abi::__cxa_demangle(_cxa.data(),
nullptr,
nullptr, &status), &free);
36 if (status != 0) {
return _cxa; }
39 return std::string(realname.get());
45 std::vector<std::string> oldpath =
explode(_name,
'/');
46 std::vector<std::string *> newpath;
47 for (std::string &f : oldpath) {
48 if (f.empty()) {
continue; }
49 if (f==
".." && !newpath.empty() && *newpath.back() !=
"..") {
52 newpath.push_back(&f);
56 for (std::string *f : newpath) {
60 if (!ret.empty()) { ret.pop_back(); }
64 std::vector<std::string>
explode(
const std::string& _string,
const char _delim) {
65 std::vector<std::string> result;
66 std::istringstream iss(_string);
69 while(std::getline(iss, token, _delim)) {
70 result.push_back(std::move(token));
76 void replace(std::string& _string,
const std::string& _search,
const std::string& _replace) {
78 while((pos = _string.find(_search, pos)) != std::string::npos){
79 _string.replace(pos, _search.length(), _replace);
80 pos += _replace.length();
84 std::string
trim(
const std::string& _string,
const std::string& whitespace) {
85 const size_t strBegin = _string.find_first_not_of(whitespace);
86 if (strBegin == std::string::npos) {
89 const size_t strEnd = _string.find_last_not_of(whitespace);
90 return _string.substr(strBegin, strEnd - strBegin + 1);
93 std::string
reduce(
const std::string& _string,
const std::string& whitespace,
const std::string& fill) {
95 auto trimedString =
trim(_string, whitespace);
98 auto beginSpace = trimedString.find_first_of(whitespace);
99 while (beginSpace != std::string::npos) {
100 const auto endSpace = trimedString.find_first_not_of(whitespace, beginSpace);
101 const auto range = endSpace - beginSpace;
103 trimedString.replace(beginSpace, range, fill);
105 const auto newStart = beginSpace + fill.length();
106 beginSpace = trimedString.find_first_of(whitespace, newStart);
The main namespace of xerus.
std::string XERUS_warn_unused trim(const std::string &_string, const std::string &whitespace=" \\")
: Removes all leading and trailing whitespaces from _string.
std::string XERUS_warn_unused reduce(const std::string &_string, const std::string &whitespace=" \\", const std::string &fill=" ")
: Removes all leading and trailing whitespaces from _string, and reduces all double whitespaces to on...
Header file for some elementary string manipulation routines.
std::string XERUS_warn_unused demangle_cxa(const std::string &_cxa)
Demangles the function and class names created by gcc into a more readable format.
std::string XERUS_warn_unused normalize_pathname(const std::string &_name)
Resolves 'folder/..' occurences in pathnames.
void replace(std::string &_string, const std::string &_search, const std::string &_replace)
: Replaces all occurences of _search in _string by _replace.
std::vector< std::string > explode(const std::string &_string, const char _delim)
: Explodes a string at positions indicated by _delim.