From 3b98f3439e33b15bba2036c402f9925340fdb2b9 Mon Sep 17 00:00:00 2001 From: Ben Longbons Date: Sat, 29 Jun 2013 23:23:43 -0700 Subject: Poison std::string and use the various string classes --- src/common/utils.hpp | 39 +++++++++++++-------------------------- 1 file changed, 13 insertions(+), 26 deletions(-) (limited to 'src/common/utils.hpp') diff --git a/src/common/utils.hpp b/src/common/utils.hpp index ab32948..196bb3e 100644 --- a/src/common/utils.hpp +++ b/src/common/utils.hpp @@ -6,13 +6,15 @@ #include #include -#include #include #include "const_array.hpp" #include "operators.hpp" +#include "strings.hpp" #include "utils2.hpp" +struct IP_String : VString<15> {}; + template struct is_trivially_copyable : std::integral_constant {}; -int remove_control_chars(char *str); -int e_mail_check(const char *email); -int config_switch (const char *str); -const char *ip2str(struct in_addr ip, bool extra_dot = false); +bool e_mail_check(XString email); +int config_switch (ZString str); +IP_String ip2str(struct in_addr ip); +VString<15 + 1> ip2str_extradot(struct in_addr ip); -bool split_key_value(const std::string& line, std::string *w1, std::string *w2); - -inline -void strzcpy(char *dest, const char *src, size_t n) -{ - if (n) - { - // hmph - strncpy(dest, src, n - 1); - dest[n - 1] = '\0'; - } -} +bool split_key_value(const FString& line, SString *w1, TString *w2); inline void really_memcpy(uint8_t *dest, const uint8_t *src, size_t n) @@ -123,13 +114,14 @@ long long& convert_for_scanf(TimeT& t) return t.value; } -typedef char timestamp_seconds_buffer[20]; -typedef char timestamp_milliseconds_buffer[24]; +struct timestamp_seconds_buffer : VString<19> {}; +struct timestamp_milliseconds_buffer : VString<23> {}; void stamp_time(timestamp_seconds_buffer&, const TimeT *t=nullptr); void stamp_time(timestamp_milliseconds_buffer&); -void log_with_timestamp(FILE *out, const_string line); +void log_with_timestamp(FILE *out, XString line); +// TODO VString? #define TIMESTAMP_DUMMY "YYYY-MM-DD HH:MM:SS" static_assert(sizeof(TIMESTAMP_DUMMY) == sizeof(timestamp_seconds_buffer), "timestamp size"); @@ -138,6 +130,7 @@ static_assert(sizeof(TIMESTAMP_DUMMY) == sizeof(timestamp_seconds_buffer), // sizeof: 01234567890123456789012345678 // str + sizeof: ^ // -1: ^ +// there's probably a better way to do this now #define REPLACE_TIMESTAMP(str, t) \ stamp_time( \ reinterpret_cast( \ @@ -146,10 +139,4 @@ static_assert(sizeof(TIMESTAMP_DUMMY) == sizeof(timestamp_seconds_buffer), &t \ ) -template -const T& const_(T& t) -{ - return t; -} - #endif //UTILS_HPP -- cgit v1.2.3-70-g09d2