CS2-Kit
C++23 library for CS2 Metamod:Source plugin development
Loading...
Searching...
No Matches
ChatColors.cpp
Go to the documentation of this file.
1
#include <CS2Kit/Utils/ChatColors.hpp>
2
#include <cctype>
3
#include <unordered_map>
4
5
namespace
CS2Kit::Utils::ChatColors
6
{
7
8
namespace
9
{
10
// Map of color names to their corresponding control codes. Keys are lowercase for case-insensitive lookup.
11
const
std::unordered_map<std::string, std::string_view> kNameTable = {
12
{
"default"
, Default}, {
"white"
, White}, {
"darkred"
, DarkRed}, {
"lightpurple"
, LightPurple},
13
{
"green"
, Green}, {
"olive"
, Olive}, {
"lime"
, Lime}, {
"red"
, Red},
14
{
"gray"
, Gray}, {
"grey"
, Grey}, {
"yellow"
, Yellow}, {
"lightyellow"
, LightYellow},
15
{
"silver"
, Silver}, {
"bluegrey"
, BlueGrey}, {
"lightblue"
, LightBlue}, {
"blue"
, Blue},
16
{
"darkblue"
, DarkBlue}, {
"purple"
, Purple}, {
"magenta"
, Magenta}, {
"lightred"
, LightRed},
17
{
"gold"
, Gold}, {
"orange"
, Orange},
18
};
19
}
// namespace
20
21
std::string_view
ParseNamed
(std::string_view name)
22
{
23
if
(name.empty())
24
return
Default;
25
26
std::string lower;
27
lower.reserve(name.size());
28
for
(
char
c : name)
29
{
30
lower.push_back(
static_cast<
char
>
(std::tolower(
static_cast<
unsigned
char
>
(c))));
31
}
32
33
auto
it = kNameTable.find(lower);
34
return
it != kNameTable.end() ? it->second : Default;
35
}
36
37
std::string
Strip
(std::string_view text)
38
{
39
std::string out;
40
out.reserve(text.size());
41
for
(
char
c : text)
42
{
43
if
(
static_cast<
unsigned
char
>
(c) > 0x10)
44
out.push_back(c);
45
}
46
return
out;
47
}
48
49
}
// namespace CS2Kit::Utils::ChatColors
CS2Kit::Utils::ChatColors
Definition
ChatColors.cpp:6
CS2Kit::Utils::ChatColors::ParseNamed
std::string_view ParseNamed(std::string_view name)
Definition
ChatColors.cpp:21
CS2Kit::Utils::ChatColors::Strip
std::string Strip(std::string_view text)
Definition
ChatColors.cpp:37
src
Utils
ChatColors.cpp
Generated by
1.9.8