nanoMMO 0.97.8
Building an MMO: The Engineering Series
Loading...
Searching...
No Matches
chat.cc
Go to the documentation of this file.
1#include "protocol/chat.h"
2
3#include <optional>
4#include <string>
5#include <string_view>
6
7#include "absl/strings/ascii.h"
8
9namespace nanommo {
10
11std::optional<std::string> CleanChat(std::string_view text) {
12 if (text.size() > kMaxChatLength) {
13 return std::nullopt;
14 }
15 std::string clean(text);
16 // UTF-8 writes the characters past ASCII in bytes over 127, which this
17 // leaves alone.
18 for (char& c : clean) {
19 if (absl::ascii_iscntrl(c)) {
20 c = ' ';
21 }
22 }
23 absl::StripAsciiWhitespace(&clean);
24 if (clean.empty()) {
25 return std::nullopt;
26 }
27 return clean;
28}
29
30} // namespace nanommo
Definition chat.cc:9
constexpr std::size_t kMaxChatLength
Definition chat.h:13
std::optional< std::string > CleanChat(std::string_view text)
Definition chat.cc:11