userver: userver/utils/text_light.hpp Source File
Loading...
Searching...
No Matches
text_light.hpp
Go to the documentation of this file.
1#pragma once
2
6
7#include <string>
8#include <string_view>
9#include <vector>
10
11USERVER_NAMESPACE_BEGIN
12
14namespace utils::text {
15
17[[nodiscard]]
18std::string Trim(std::string_view str);
19
21[[nodiscard]]
22std::string Trim(std::string&& str);
23
25[[nodiscard]]
26std::string_view TrimView(std::string_view str);
27
28enum class SplitFlags {
29 kNone = 0,
30 kCompressAdjacentSeparators = 1 << 0,
31};
32
36std::vector<std::string> Split(
37 std::string_view str,
38 std::string_view separators,
39 SplitFlags split_flags = SplitFlags::kCompressAdjacentSeparators
40);
41
47std::vector<std::string_view> SplitIntoStringViewVector(std::string_view str, std::string_view separators);
48
50std::string Join(const std::vector<std::string>& strs, std::string_view sep);
51
53std::string Format(double value, int ndigits);
54
57constexpr bool StartsWith(std::string_view hay, std::string_view needle) noexcept { return hay.starts_with(needle); }
58
61constexpr bool EndsWith(std::string_view hay, std::string_view needle) noexcept { return hay.ends_with(needle); }
62
64bool ICaseStartsWith(std::string_view hay, std::string_view needle) noexcept;
65
67bool ICaseEndsWith(std::string_view hay, std::string_view needle) noexcept;
68
78std::string RemoveQuotes(std::string_view str);
79
81bool IsAscii(char ch) noexcept;
82
84bool IsAsciiSpace(char ch) noexcept;
85
87bool IsAscii(std::string_view text) noexcept;
88
90namespace utf8 {
91
93std::size_t CodePointLengthByFirstByte(char c) noexcept;
94
96bool IsWellFormedCodePoint(std::string_view text) noexcept;
97
99bool IsValid(std::string_view text) noexcept;
100
103std::size_t GetCodePointsCount(std::string_view text);
104
108void TrimTruncatedEnding(std::string& str);
109
112void TrimViewTruncatedEnding(std::string_view& view);
113
117std::size_t GetTextPosByCodePointPos(std::string_view text, std::size_t pos) noexcept;
118
121void RemovePrefix(std::string& text, std::size_t count) noexcept;
122
125void RemoveViewPrefix(std::string_view& text, std::size_t count) noexcept;
126
129void TakePrefix(std::string& text, std::size_t count) noexcept;
130
133void TakeViewPrefix(std::string_view& text, std::size_t count) noexcept;
134
135} // namespace utf8
136
138bool IsUtf8(std::string_view text) noexcept;
139
144bool IsPrintable(std::string_view text, bool ascii_only = true) noexcept;
145
147bool IsCString(std::string_view text) noexcept;
148
150std::string CamelCaseToSnake(std::string_view camel);
151
153std::string SnakeCaseToCamel(std::string_view snake);
154
155} // namespace utils::text
156
157USERVER_NAMESPACE_END