introduce string_view

This commit is contained in:
Chunting Gu
2021-06-17 18:58:53 +08:00
parent 751a3539ae
commit 26bb6b341a
38 changed files with 404 additions and 344 deletions
+11 -5
View File
@@ -4,7 +4,7 @@
#include <string>
#include <vector>
#include "boost/utility/string_view.hpp"
#include "webcc/globals.h" // for string_view
namespace webcc {
@@ -15,15 +15,21 @@ std::string RandomString(std::size_t length);
// Just a wrapper of std::stoul.
bool ToSizeT(const std::string& str, int base, std::size_t* size);
void Trim(string_view& sv, const char* spaces = " ");
// Split string without copy.
// |compress_token| is the same as boost::token_compress_on for boost::split.
void Split(boost::string_view input, char delim, bool compress_token,
std::vector<boost::string_view>* output);
void Split(string_view input, char delim, bool compress_token,
std::vector<string_view>* output);
// Split a key-value string.
// E.g., split "Connection: Keep-Alive".
// TODO: Use string_view (blocked by trim)
bool SplitKV(const std::string& input, char delim, bool trim_spaces,
bool SplitKV(string_view input, char delim, bool trim_spaces, string_view* key,
string_view* value);
// Split a key-value string.
// E.g., split "Connection: Keep-Alive".
bool SplitKV(string_view input, char delim, bool trim_spaces,
std::string* key, std::string* value);
} // namespace webcc