Thoth
A functional, expressive, asynchronous C++26 webdev library
Loading...
Searching...
No Matches
Utils.hpp
Go to the documentation of this file.
1#pragma once
2#include <bitset>
3#include <string_view>
4#include <string>
5
6namespace Thoth::String {
7 struct CharSequences {
8 struct Http {
9 static constexpr std::string_view whitespace { " \t" };
10
11 static constexpr std::string_view tchar {
12 "abcdefghijklmnopqrstuvwxyz"
13 "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
14 "0123456789"
15 "!#$%&'*+-.^_`|~"
16 };
17
18 static constexpr std::string_view url {
19 "abcdefghijklmnopqrstuvwxyz"
20 "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
21 "0123456789"
22 "-._~"
23 "!$&'()*+,;="
24 };
25
26 static constexpr std::string_view delimiters { "\"(),/:;<=>?@[\\]{}" };
27 };
28
30 static constexpr std::string_view linearWhitespace { " \t" };
31 static constexpr std::string_view whitespace { " \t\n\v\f\r" };
32 static constexpr std::string_view newlines { "\r\n" };
34
36 static constexpr std::string_view digits { "0123456789" };
37 static constexpr std::string_view alphaLower { "abcdefghijklmnopqrstuvwxyz" };
38 static constexpr std::string_view alphaUpper { "ABCDEFGHIJKLMNOPQRSTUVWXYZ" };
39 static constexpr std::string_view alpha { "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ" };
40 static constexpr std::string_view alphanumeric { "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789" };
42
44 static constexpr std::string_view hex { "0123456789abcdefABCDEF" };
45 static constexpr std::string_view hexLower { "0123456789abcdef" };
46 static constexpr std::string_view hexUpper { "0123456789ABCDEF" };
47 static constexpr std::string_view base64 { "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/" };
48 static constexpr std::string_view base64Url { "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_" };
49 static constexpr std::string_view base64Padding { "=" };
51
53 static constexpr std::string_view punctuation { "!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~" };
54 static constexpr std::string_view nonPrintable {
55 "\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f"
56 "\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f\x7f"
57 };
59 };
60
61 bool CaseInsensitiveCompare(char c1, char c2);
62
63 void Trim(std::string_view& str, std::string_view trim = CharSequences::whitespace);
64 void LeftTrim(std::string_view& str, std::string_view trim = CharSequences::whitespace);
65 void RightTrim(std::string_view& str, std::string_view trim = CharSequences::whitespace);
66
67 std::string_view Trimmed(std::string_view str, std::string_view trim = CharSequences::whitespace);
68 std::string_view LeftTrimmed(std::string_view str, std::string_view trim = CharSequences::whitespace);
69 std::string_view RightTrimmed(std::string_view str, std::string_view trim = CharSequences::whitespace);
70
71 std::string TrimmedStr(std::string_view str, std::string_view trim = CharSequences::whitespace);
72 std::string LeftTrimmedStr(std::string_view str, std::string_view trim = CharSequences::whitespace);
73 std::string RightTrimmedStr(std::string_view str, std::string_view trim = CharSequences::whitespace);
74
75 constexpr std::bitset<256> MakeBitset(std::initializer_list<std::string_view> strs);
76
77
78 bool IsVisible(char c);
79}
80
81#include <Thoth/String/Utils.tpp>
Definition _base.hpp:4
std::string TrimmedStr(std::string_view str, std::string_view trim=CharSequences::whitespace)
void RightTrim(std::string_view &str, std::string_view trim=CharSequences::whitespace)
std::string LeftTrimmedStr(std::string_view str, std::string_view trim=CharSequences::whitespace)
bool IsVisible(char c)
std::string_view RightTrimmed(std::string_view str, std::string_view trim=CharSequences::whitespace)
bool CaseInsensitiveCompare(char c1, char c2)
std::string_view LeftTrimmed(std::string_view str, std::string_view trim=CharSequences::whitespace)
void LeftTrim(std::string_view &str, std::string_view trim=CharSequences::whitespace)
std::string RightTrimmedStr(std::string_view str, std::string_view trim=CharSequences::whitespace)
void Trim(std::string_view &str, std::string_view trim=CharSequences::whitespace)
constexpr std::bitset< 256 > MakeBitset(std::initializer_list< std::string_view > strs)
std::string_view Trimmed(std::string_view str, std::string_view trim=CharSequences::whitespace)
static constexpr std::string_view delimiters
Definition Utils.hpp:26
static constexpr std::string_view whitespace
Definition Utils.hpp:9
static constexpr std::string_view tchar
Definition Utils.hpp:11
static constexpr std::string_view url
Definition Utils.hpp:18
Definition Utils.hpp:7
static constexpr std::string_view hexLower
Definition Utils.hpp:45
static constexpr std::string_view alphaUpper
Definition Utils.hpp:38
static constexpr std::string_view base64Url
Definition Utils.hpp:48
static constexpr std::string_view newlines
Definition Utils.hpp:32
static constexpr std::string_view base64
Definition Utils.hpp:47
static constexpr std::string_view punctuation
Special & Filtering.
Definition Utils.hpp:53
static constexpr std::string_view base64Padding
Definition Utils.hpp:49
static constexpr std::string_view alpha
Definition Utils.hpp:39
static constexpr std::string_view hex
Encodings.
Definition Utils.hpp:44
static constexpr std::string_view hexUpper
Definition Utils.hpp:46
static constexpr std::string_view whitespace
Definition Utils.hpp:31
static constexpr std::string_view alphaLower
Definition Utils.hpp:37
static constexpr std::string_view digits
Numbers & Letters.
Definition Utils.hpp:36
static constexpr std::string_view nonPrintable
Definition Utils.hpp:54
static constexpr std::string_view alphanumeric
Definition Utils.hpp:40
static constexpr std::string_view linearWhitespace
Whitespace & Control.
Definition Utils.hpp:30