teditor
1.8.0@@fee5e94
Terminal based editor written in C++
|
Go to the documentation of this file.
8 #include <unordered_map>
13 std::string
format(
const char* fmt, ...);
14 std::string
format(
const char* fmt, va_list& vl);
22 #define THROW(fmt, ...) \
24 std::string msg = format("Exception occured! file=%s line=%d: " \
25 fmt, __FILE__, __LINE__, ##__VA_ARGS__); \
26 throw std::runtime_error(msg); \
35 #define ASSERT(check, fmt, ...) \
37 if(!(check)) THROW(fmt, ##__VA_ARGS__); \
46 return std::all_of(strs.begin(), strs.end(),
47 [](
const std::string& s) { return s.empty(); });
52 bool same(
const std::vector<T>& s1,
const std::vector<T>& s2) {
53 if(s1.size() != s2.size())
return false;
54 return std::equal(s1.begin(), s1.end(), s2.begin());
58 std::string
env(
const std::string& s);
61 bool startsWith(
const char* s1,
int len,
const char* s2);
63 std::string
join(
const Strings& s,
char delim,
int start=0,
int end=-1);
66 int str2num(
const std::string& str);
67 float str2real(
const std::string& str);
86 std::string
urlHexify(
const std::string& url);
89 void downloadUrl(
const std::string& url,
const std::string& file,
90 const std::string& dnldProg =
"curl",
91 const std::string& dnldProgOpts =
"-s");
95 const std::string& dnldProg =
"curl",
96 const std::string& dnldProgOpts =
"-s");
104 bool strFind(
const std::string& line,
const std::string& str);
106 bool iStrFind(
const std::string& line,
const std::string& str);
109 std::string
dos2unix(
const std::string& in);
122 History(
const std::string& f,
int _max);
124 int max()
const {
return maxLen; }
125 const std::string&
getFile()
const {
return file; }
134 void add(
const std::string& elem);
139 virtual bool isDuplicate(
const std::string& a,
const std::string& b)
const;
148 template <
typename K,
typename V>
150 const std::unordered_map<K, V>& map) {
152 for (
auto itr : map) keys.push_back(itr.first);
153 std::sort(keys.begin(), keys.end());
const std::string & getFile() const
Definition: utils.h:125
void store() const
Definition: utils.cpp:276
Strings split(const std::string &str, char delim)
Definition: utils.cpp:48
bool allStringsEmpty(const Strings &strs)
Definition: utils.h:45
int str2num(const std::string &str)
Definition: utils.cpp:73
bool strFind(const std::string &line, const std::string &str)
Definition: utils.cpp:237
void prune()
Definition: utils.cpp:272
char getMatchingParen(char c)
Definition: utils.cpp:205
const Strings & get() const
Definition: utils.h:136
std::string findFirstUpwards(const std::string &dir, const std::string &file)
Definition: file_utils.cpp:158
CmdStatus check_output(const std::string &cmd)
Definition: utils.cpp:110
double str2double(const std::string &str)
Definition: utils.cpp:87
std::string urlHexify(const std::string &url)
Hexify the input url.
Definition: utils.cpp:169
unsigned numThreads()
Definition: utils.cpp:301
std::vector< std::string > Strings
Definition: utils.h:42
std::string join(const Strings &s, char delim, int start, int end)
Definition: utils.cpp:56
void downloadUrl(const std::string &url, const std::string &file, const std::string &dnldProg, const std::string &dnldProgOpts)
Download the content of input url into the given file.
Definition: utils.cpp:179
bool same(const std::vector< T > &s1, const std::vector< T > &s2)
Definition: utils.h:52
bool isCloseParen(char c)
Definition: utils.cpp:199
History(const std::string &f, int _max)
Ctor.
Definition: utils.cpp:265
void dos2unix(std::string &in)
Definition: utils.cpp:249
bool isParen(char c)
Definition: utils.cpp:203
std::string error
Definition: utils.h:77
int status
Definition: utils.h:78
std::string expandEnvVars(const std::string &str)
Definition: utils.cpp:219
#define ASSERT(check, fmt,...)
Macro to assert with runtime_error exception if the check fails.
Definition: utils.h:35
void add(const std::string &elem)
Definition: utils.cpp:285
float str2real(const std::string &str)
Definition: utils.cpp:80
std::string num2str(int num)
Definition: utils.cpp:66
Container to store history (files-visited or command-history, etc)
Definition: utils.h:115
std::string output
Definition: utils.h:77
virtual bool isDuplicate(const std::string &a, const std::string &b) const
Definition: utils.cpp:297
std::string gitBranchName(const std::string &dir)
Definition: utils.cpp:99
bool iStrFind(const std::string &line, const std::string &str)
Definition: utils.cpp:241
bool startsWith(const char *s1, int len1, const char *s2)
Definition: utils.cpp:41
int max() const
Definition: utils.h:124
Strings slurpToArr(const std::string &file)
Definition: file_utils.cpp:97
std::string format(const char *fmt, va_list &vl)
Definition: utils.cpp:22
bool isOpenParen(char c)
Definition: utils.cpp:195
std::vector< K > sortedKeys(const std::unordered_map< K, V > &map)
Definition: utils.h:149
std::string downloadUrlToString(const std::string &url, const std::string &dnldProg, const std::string &dnldProgOpts)
Download the content of input url into a string.
Definition: utils.cpp:187
bool isFile(const std::string &f)
Definition: file_utils.cpp:43
std::string env(const std::string &s)
Definition: utils.cpp:36
bool isUnderGit(const std::string &dir)
Definition: utils.cpp:94