123456789101112131415161718192021222324252627282930313233 |
- #include "utils.h"
- #include <algorithm>
- bool 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 false;
- str.replace(start_pos, from.length(), to);
- return true;
- }
- bool replace(std::string &str, const char *from, const char *to) {
- size_t start_pos = str.find(from);
- if (start_pos == std::string::npos)
- return false;
- str.replace(start_pos, strlen(from), to);
- return true;
- }
- bool file_exists(const std::string &name) {
- std::ifstream f(name.c_str());
- return f.good();
- }
- bool file_exists(const char *name) {
- std::ifstream f(name);
- return f.good();
- }
- void string_toupper(std::string &str) {
- std::transform(str.begin(), str.end(), str.begin(), ::toupper);
- }
|