1
0
Fork 0
mirror of https://github.com/zeldaret/oot.git synced 2024-11-11 03:39:59 +00:00
oot/tools/ZAPD/ZAPDUtils/Utils/StringHelper.h
EllipticEllipsis 9b67778a00
Building on Macs (#1086)
* git subrepo pull (merge) tools/ZAPD

subrepo:
  subdir:   "tools/ZAPD"
  merged:   "945e6ca1a"
upstream:
  origin:   "https://github.com/zeldaret/ZAPD.git"
  branch:   "master"
  commit:   "50242eca9"
git-subrepo:
  version:  "0.4.3"
  origin:   "https://github.com/ingydotnet/git-subrepo.git"
  commit:   "2f68596"

* Fix extract_assets.py multithreading

* Update binutils doc a bit

* Remove * import, add multiprocessing option
and way to pass arguments to ZAPD

* Update format.sh to be more platform-independent

* git subrepo pull --force tools/ZAPD

subrepo:
  subdir:   "tools/ZAPD"
  merged:   "fd5a7f434"
upstream:
  origin:   "https://github.com/zeldaret/ZAPD.git"
  branch:   "master"
  commit:   "fd5a7f434"
git-subrepo:
  version:  "0.4.3"
  origin:   "https://github.com/ingydotnet/git-subrepo.git"
  commit:   "2f68596"

* Remove ;

* Update formatting script to not just use 11

* Add Python requirements,
move the Mac stuff in the README into its own doc

* Fix readme link

* Minor format thing

* .

* Move ZAPDArgs into its own function

* Update readme and remove requirements.txt

* Dragorn-inspired rewrite of processZAPDArgs

* git subrepo pull --force tools/ZAPD

subrepo:
  subdir:   "tools/ZAPD"
  merged:   "a0d3f7b68"
upstream:
  origin:   "https://github.com/zeldaret/ZAPD.git"
  branch:   "master"
  commit:   "a0d3f7b68"
git-subrepo:
  version:  "0.4.3"
  origin:   "https://github.com/ingydotnet/git-subrepo.git"
  commit:   "2f68596"

* Fix function definition

* Building docs overhaul

* Add Python packages to Mac and Cygwin

* Heading number

* format format.sh (!)

* Replace "currently"

* Remove Debian

* git subrepo pull (merge) --force tools/ZAPD

subrepo:
  subdir:   "tools/ZAPD"
  merged:   "0ba781304"
upstream:
  origin:   "https://github.com/zeldaret/ZAPD.git"
  branch:   "master"
  commit:   "0ba781304"
git-subrepo:
  version:  "0.4.3"
  origin:   "https://github.com/ingydotnet/git-subrepo.git"
  commit:   "2f68596"
2022-01-16 19:43:07 -05:00

114 lines
2.5 KiB
C++

#pragma once
#include <algorithm>
#include <cstdarg>
#include <cstring>
#include <numeric>
#include <string>
#include <vector>
class StringHelper
{
public:
static std::vector<std::string> Split(std::string s, const std::string& delimiter)
{
std::vector<std::string> result;
size_t pos = 0;
std::string token;
while ((pos = s.find(delimiter)) != std::string::npos)
{
token = s.substr(0, pos);
result.push_back(token);
s.erase(0, pos + delimiter.length());
}
if (s.length() != 0)
result.push_back(s);
return result;
}
static std::string Strip(std::string s, const std::string& delimiter)
{
size_t pos = 0;
std::string token;
while ((pos = s.find(delimiter)) != std::string::npos)
{
token = s.substr(0, pos);
s.erase(pos, pos + delimiter.length());
}
return s;
}
static std::string Replace(std::string str, const std::string& from, const std::string& to)
{
size_t start_pos = str.find(from);
if (start_pos == std::string::npos)
return str;
str.replace(start_pos, from.length(), to);
return str;
}
static bool StartsWith(const std::string& s, const std::string& input)
{
return s.rfind(input, 0) == 0;
}
static bool Contains(const std::string& s, const std::string& input)
{
return s.find(input) != std::string::npos;
}
static bool EndsWith(const std::string& s, const std::string& input)
{
size_t inputLen = strlen(input.c_str());
return s.rfind(input) == (s.size() - inputLen);
}
static std::string Sprintf(const char* format, ...)
{
char buffer[32768];
// char buffer[2048];
std::string output;
va_list va;
va_start(va, format);
vsprintf(buffer, format, va);
va_end(va);
output = buffer;
return output;
}
static std::string Implode(std::vector<std::string>& elements, const char* const separator)
{
return std::accumulate(std::begin(elements), std::end(elements), std::string(),
[separator](std::string& ss, std::string& s) {
return ss.empty() ? s : ss + separator + s;
});
}
static int64_t StrToL(const std::string& str, int32_t base = 10)
{
return std::strtoull(str.c_str(), nullptr, base);
}
static std::string BoolStr(bool b) { return b ? "true" : "false"; }
static bool HasOnlyDigits(const std::string& str)
{
return std::all_of(str.begin(), str.end(), ::isdigit);
}
static bool IEquals(const std::string& a, const std::string& b)
{
return std::equal(a.begin(), a.end(), b.begin(), b.end(),
[](char a, char b) { return tolower(a) == tolower(b); });
}
};