Can now parse HTTP responses.

This commit is contained in:
2022-04-25 13:43:11 -04:00
parent d2c81e640d
commit bd389c7815
4 changed files with 766 additions and 153 deletions

View File

@@ -51,12 +51,14 @@ inline bool ascii_isspace(char c) { return (c==' ')||(c=='\t')||(c=='\r')||(c=='
inline bool isnull(string_view v) { return v.data() == nullptr; }
// Check if numbers can be parsed as int64/double
bool valid_int64(string_view v);
bool valid_double(string_view v);
bool valid_int64(string_view v);
bool valid_hex64(string_view v);
// Parse numbers as int64/double. Returns errval on failure.
int64_t to_int64(string_view v, int64_t errval = std::numeric_limits<int64_t>::min());
// Parse numbers as int32, int64, or double. Returns errval on failure.
double to_double(string_view v, double errval = std::numeric_limits<double>::quiet_NaN());
int64_t to_int64(string_view v, int64_t errval = std::numeric_limits<int64_t>::min());
uint64_t to_hex64(string_view v, uint64_t errval = std::numeric_limits<uint64_t>::max());
// Trim whitspace from a string_view.
string_view ltrim(string_view v);
@@ -81,6 +83,12 @@ bool is_lua_id(string_view s);
// Return true if the line of code is a lua comment.
bool is_lua_comment(string_view s);
// Return the first character, but if the view is empty,
// return zero.
inline char zfront(string_view &s) {
return s.empty() ? char(0) : s.front();
}
// Read from a string_view until separator is reached.
//
// If the separator appears in the source, returns everything
@@ -114,6 +122,13 @@ string_view read_to_line(string_view &source);
//
string_view read_to_space(string_view &source);
// Read up to nbytes from a string_view.
//
string_view read_nbytes(string_view &source, int nbytes);
// Return true if the string is valid utf-8.
bool valid_utf8(string_view s);
} // namespace sv
namespace util {
@@ -233,6 +248,22 @@ public:
int overflow(int c) { return c; }
};
// send_to_stream: send all arguments to the specified stream.
inline void send_to_stream(std::ostream &os) {}
template <class ARG, class... REST>
inline void send_to_stream(std::ostream &os, ARG arg, REST & ... rest) {
os << arg;
send_to_stream(os, rest...);
}
// ss: convert all arguments to a string by sending them to a stringstream.
template <class... ARGS>
inline eng::string ss(ARGS & ... args) {
eng::ostringstream oss;
send_to_stream(oss, args...);
return oss.str();
}
} // namespace util
std::ostream &operator<<(std::ostream &oss, const util::hex64 &v);