More work on command parser
This commit is contained in:
@@ -5,6 +5,7 @@
|
||||
#include <set>
|
||||
#include <algorithm>
|
||||
#include <sstream>
|
||||
#include <ostream>
|
||||
#include <tuple>
|
||||
#include <utility>
|
||||
|
||||
@@ -13,44 +14,40 @@ namespace util {
|
||||
using stringvec = std::vector<std::string>;
|
||||
using stringset = std::set<std::string>;
|
||||
|
||||
// trim from start
|
||||
static inline std::string ltrim(std::string s) {
|
||||
s.erase(s.begin(), std::find_if(s.begin(), s.end(),
|
||||
std::not1(std::ptr_fun<int, int>(std::isspace))));
|
||||
return s;
|
||||
}
|
||||
// String to integer. Returns errval if the number is not parseable.
|
||||
int64_t strtoint(const std::string &value, int64_t errval);
|
||||
|
||||
// trim from end
|
||||
static inline std::string rtrim(std::string s) {
|
||||
s.erase(std::find_if(s.rbegin(), s.rend(),
|
||||
std::not1(std::ptr_fun<int, int>(std::isspace))).base(), s.end());
|
||||
return s;
|
||||
}
|
||||
// Trim strings: left end, right end, both ends.
|
||||
std::string ltrim(std::string s);
|
||||
std::string rtrim(std::string s);
|
||||
std::string trim(std::string s);
|
||||
|
||||
// trim from both ends
|
||||
static inline std::string trim(std::string s) {
|
||||
return ltrim(rtrim(s));
|
||||
}
|
||||
// Read a file as one big string.
|
||||
std::string get_file_contents(const std::string &path);
|
||||
|
||||
const stringvec read_lines(const std::string &path);
|
||||
const stringvec trim_and_uncomment(const stringvec &lines);
|
||||
// Read a file as a vector of lines.
|
||||
stringvec get_file_lines(const std::string &path);
|
||||
|
||||
// Get a file's fingerprint - ie, size and modification time.
|
||||
std::string get_file_fingerprint(const std::string &path);
|
||||
std::string get_file_contents(const std::string &fn);
|
||||
|
||||
// Calculate distance between two points
|
||||
double distance_squared(double x1, double y1, double x2, double y2);
|
||||
|
||||
// Return a pseudorandom number which is a hash function of A,B,C.
|
||||
uint32_t hash3(uint32_t a, uint32_t b, uint32_t c);
|
||||
|
||||
// Returns a floating point value between lo and hi inclusive.
|
||||
// Return a pseudorandom float between lo and hi inclusive.
|
||||
double hash_to_float(double lo, double hi, uint32_t a, uint32_t b, uint32_t c);
|
||||
|
||||
// An XYZ coordinate, general purpose.
|
||||
struct XYZ {
|
||||
float x, y, z;
|
||||
XYZ() { x=0; y=0; z=0; }
|
||||
XYZ(float ix, float iy, float iz) { x=ix; y=iy; z=iz; }
|
||||
bool operator ==(const XYZ &o) { return x==o.x && y == o.y && z==o.z; }
|
||||
};
|
||||
|
||||
std::ostream & operator << (std::ostream &out, const XYZ &xyz);
|
||||
|
||||
} // namespace util
|
||||
#endif // UTIL_HPP
|
||||
|
||||
Reference in New Issue
Block a user