11USERVER_NAMESPACE_BEGIN
14namespace utils::
text {
17std::string Trim(
const std::string& str);
20std::string Trim(std::string&& str);
22enum class SplitFlags {
24 kCompressAdjacentSeparators = 1 << 0,
30std::vector<std::string> Split(
32 std::string_view separators,
33 SplitFlags split_flags = SplitFlags::kCompressAdjacentSeparators
41std::vector<std::string_view> SplitIntoStringViewVector(std::string_view str, std::string_view separators);
44std::string Join(
const std::vector<std::string>& strs, std::string_view sep);
47std::string Format(
double value,
int ndigits);
50constexpr bool StartsWith(std::string_view hay, std::string_view needle)
noexcept {
51 return hay.substr(0, needle.size()) == needle;
55constexpr bool EndsWith(std::string_view hay, std::string_view needle)
noexcept {
56 return hay.size() >= needle.size() && hay.substr(hay.size() - needle.size()) == needle;
60bool ICaseStartsWith(std::string_view hay, std::string_view needle)
noexcept;
63bool ICaseEndsWith(std::string_view hay, std::string_view needle)
noexcept;
74std::string RemoveQuotes(std::string_view str);
77bool IsAscii(
char ch)
noexcept;
80bool IsAsciiSpace(
char ch)
noexcept;
83bool IsAscii(std::string_view text)
noexcept;
89unsigned CodePointLengthByFirstByte(
unsigned char c)
noexcept;
92bool IsWellFormedCodePoint(
const unsigned char* bytes, std::size_t length)
noexcept;
95bool IsValid(
const unsigned char* bytes, std::size_t length)
noexcept;
99std::size_t GetCodePointsCount(std::string_view text);
104void TrimTruncatedEnding(std::string& str);
108void TrimViewTruncatedEnding(std::string_view& view);
113std::size_t GetTextPosByCodePointPos(std::string_view text, std::size_t pos)
noexcept;
117void RemovePrefix(std::string& text, std::size_t count)
noexcept;
121void RemoveViewPrefix(std::string_view& text, std::size_t count)
noexcept;
125void TakePrefix(std::string& text, std::size_t count)
noexcept;
129void TakeViewPrefix(std::string_view& text, std::size_t count)
noexcept;
134bool IsUtf8(std::string_view text)
noexcept;
140bool IsPrintable(std::string_view text,
bool ascii_only =
true)
noexcept;
143bool IsCString(std::string_view text)
noexcept;
146std::string CamelCaseToSnake(std::string_view camel);
149std::string SnakeCaseToCamel(std::string_view snake);