#include
#include
#include
#include
#include
#include
#include
#include
namespace LFortran
{
bool startswith(const std::string &s, const std::string &e)
{
if (s.size() < e.size()) return false;
return s.substr(0, e.size()) == e;
}
bool endswith(const std::string &s, const std::string &e)
{
if (s.size() < e.size()) return false;
return s.substr(s.size()-e.size()) == e;
}
std::string to_lower(const std::string &s) {
std::string res = s;
std::transform(res.begin(), res.end(), res.begin(),
[](unsigned char c){ return std::tolower(c); });
return res;
}
char *s2c(Allocator &al, const std::string &s) {
Str x; x.from_str_view(s);
return x.c_str(al);
}
std::vector<:string> split(const std::string &s)
{
std::vector<:string> result;
std::string split_chars = " \n";
size_t old_pos = 0;
size_t new_pos;
while ((new_pos = s.find_first_of(split_chars, old_pos)) != std::string::npos) {
std::string substr = s.substr(old_pos, new_pos-old_pos);
if (substr.size() > 0) result.push_back(substr);
old_pos = new_pos+1;
}
result.push_back(s.substr(old_pos));
return result;
}
std::string join(const std::string j, const std::vector<:string> &l)
{
std::string result;
for (size_t i=0; i slice(const std::vector<:string>& v, int start, int end)
{
int oldlen = v.size();
int newlen;
if ((end == -1) || (end >= oldlen)) {
newlen = oldlen-start;
} else {
newlen = end-start;
}
std::vector<:string> nv(newlen);
for (int i=0; i bytes(filesize);
ifs.read(&bytes[0], filesize);
return std::string(&bytes[0], filesize);
}
} // namespace LFortran