You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

38 lines
1.1 KiB
C++

#ifndef WEBCC_STRING_H_
#define WEBCC_STRING_H_
#include <string>
#include <vector>
#include "webcc/globals.h" // for string_view
namespace webcc {
// Get a randomly generated string with the given length.
std::string RandomString(std::size_t length);
// Convert string to size_t.
// 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(string_view input, char delim, bool compress_token,
std::vector<string_view>* output);
// Split a key-value string.
// E.g., split "Connection: Keep-Alive".
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
#endif // WEBCC_STRING_H_