34 void delay_ms(
int delay);
49 bool exists(std::string path);
55 off_t
size(std::string path);
63 void rm_rf(std::string path);
67 void rm_f(std::string path);
74 bool create(std::string path);
80 void write(std::string path, std::string contents);
91 bool isFile(std::string path);
98 std::vector<std::string>
ls(std::string path);
120 std::string
basename(std::string path);
155 template <
typename T>
156 inline std::string toString(T
const& x)
158 std::ostringstream o;
160 throw std::runtime_error(
"Utils::String::toString");
171 template <
typename T>
172 inline void convert(std::string
const& s, T& x,
173 bool failIfLeftOverChars=
true)
175 std::istringstream i(s);
177 if (!(i >> x) || (failIfLeftOverChars && i.get(c)))
178 throw std::runtime_error(
"Utils::String::convert");
183 template <
typename T>
184 inline T to(std::string
const& s,
185 bool failIfLeftOverChars=
true)
188 convert(s, x, failIfLeftOverChars);
196 char back(std::string& str);
201 char front(std::string& str);
206 void pop_back(std::string* str);
210 std::string pop_back(std::string& str);
213 std::string ltrim(
const std::string &str);
216 std::string rtrim(
const std::string& str);
219 std::string trim(
const std::string& str);
225 std::vector<std::string> split(
const std::string& str,
char delim);
230 bool caseInsensitiveSmallerChar(
const char x,
const char y);
244 bool caseInsensitiveSmallerString(
const std::string &a,
const std::string &b);
251 std::string
encode(std::string str);
254 std::string
decode(std::string
const& s);
261#define SAFE_DELETE(pointer) \
272#define UNUSED(thing) \
std::string encode(std::string str)
Transforms #str into a Base64 equivalent.
std::string decode(std::string const &s)
Transforms a Base64-encoded #str into it's regular string equivalent.
bool isFile(std::string path)
Tells if #path is a regular file (not a directory, socket, FIFO device or whatever).
std::string getHome()
Gets the full path of the home directory for the user running this program.
std::string dropBasename(std::string path)
Returns the full pathname up to the last component.
std::vector< std::string > ls(std::string path)
Lists all files withing #path.
void rm_rf(std::string path)
Removes recursively all files within directory at #path, just like UNIX command rm -rf.
bool create(std::string path)
Creates empty file #path.
std::string basename(std::string path)
Returns the component of a pathname (file name and extension).
void rm_f(std::string path)
Forcibly removes file within #path.
std::string extension(std::string path)
Returns the extension of a file.
void write(std::string path, std::string contents)
Writes #contents to #path.
off_t size(std::string path)
Returns the file size of #path in bytes.
bool exists(std::string path)
Tells if #path exists.
std::string getUser()
Gets the user name of the person running this program.
bool isDirectory(std::string path)
Tells if #path is a directory.
std::string dropExtension(std::string path)
Returns the filename without it's extension.
void mkdir_p(std::string path)
Creates #path directory hierarchy recursively, just like UNIX command mkdir -p.
bool boolean()
Random boolean.
bool booleanWithChance(float percent)
Random boolean with chance of #percent.
int between(int min, int max)
Random number between min and max.
void seed()
Must be called before any of those.
Random useful things accumulated over the years.