Code to implement HTTP requests done. Also, rewrote str_to_int64, str_to_double

This commit is contained in:
2022-04-15 17:24:07 -04:00
parent 453809b65c
commit b6d603034e
17 changed files with 3705 additions and 99 deletions

View File

@@ -38,6 +38,19 @@ using LuaSourceVec = eng::vector<StringPair>;
using LuaSourcePtr = std::unique_ptr<LuaSourceVec>;
using HashValue = std::pair<uint64_t, uint64_t>;
using IdVector = eng::vector<int64_t>;
using OptionalInt64 = std::optional<int64_t>;
// This value is sometimes used to represent 'bad integer'
const int64_t BADINT64 = std::numeric_limits<int64_t>::min();
// Test character class ignoring 'current locale'.
inline bool ascii_isupper(char c) { return (c >= 'A') && (c <= 'Z'); }
inline bool ascii_islower(char c) { return (c >= 'a') && (c <= 'z'); }
inline bool ascii_isdigit(char c) { return (c >= '0') && (c <= '9'); }
inline bool ascii_isalpha(char c) { return ascii_isupper(c) || ascii_islower(c); }
inline bool ascii_isalnum(char c) { return ascii_isalpha(c) || ascii_isdigit(c); }
eng::string ascii_tolower(const eng::string &c);
eng::string ascii_toupper(const eng::string &c);
// Return seconds elapsed, for profiling purposes.
double profiling_clock();
@@ -99,28 +112,39 @@ eng::string toupper(eng::string input);
bool has_prefix(const eng::string &s, const eng::string &prefix);
bool has_suffix(const eng::string &s, const eng::string &suffix);
// Return true if the string can be parsed as an integer.
bool validinteger(const eng::string &value);
// Check if numbers can be parsed as int64/double
bool valid_int64(std::string_view v);
bool valid_double(std::string_view v);
// String to integer. Returns errval if the number is not parseable.
int64_t strtoint(const eng::string &value, int64_t errval);
// String to double. Returns NAN if the number is not parseable.
double strtodouble(const eng::string &value);
// Parse numbers as int64/double. Returns errval on failure.
int64_t str_to_int64(std::string_view v, int64_t errval = INT64_MIN);
double str_to_double(std::string_view v, double errval = std::numeric_limits<double>::quiet_NaN());
// Trim a string_view
std::string_view sv_ltrim(std::string_view v);
std::string_view sv_rtrim(std::string_view v);
std::string_view sv_trim(std::string_view v);
std::string_view sv_ltrim(std::string_view v, char c);
std::string_view sv_rtrim(std::string_view v, char c);
std::string_view sv_trim(std::string_view v, char c);
// sv_is_null is different from checking for empty.
inline bool sv_is_null(const std::string_view &v) { return v.data() == nullptr; }
// Split a string view into stuff before and after separator.
// If the separator doesn't occur, returns a null string view
// and doesn't modify the source.
std::string_view sv_split_one(std::string_view &source, char sep);
// Read a line from a string_view.
std::string_view sv_read_line(std::string_view &source);
// Trim strings: left end, right end, both ends.
eng::string ltrim(std::string_view s);
eng::string rtrim(std::string_view s);
eng::string trim(std::string_view s);
// Read a line from a string_view
std::string_view sv_read_line(std::string_view &source);
// Calculate distance between two points
double distance_squared(double x1, double y1, double x2, double y2);