The Battle for Wesnoth  1.19.0-dev
player_network.cpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2003 - 2024
3  by David White <dave@whitevine.net>, Tomasz Sniatowski <kailoran@gmail.com>
4  Part of the Battle for Wesnoth Project https://www.wesnoth.org/
5 
6  This program is free software; you can redistribute it and/or modify
7  it under the terms of the GNU General Public License as published by
8  the Free Software Foundation; either version 2 of the License, or
9  (at your option) any later version.
10  This program is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY.
12 
13  See the COPYING file for more details.
14 */
15 
17 #include "log.hpp"
19 
21 #define WRN_CONFIG LOG_STREAM(warn, log_config_pn)
22 
23 namespace wesnothd {
24 
25 namespace chat_message {
26 
27 const std::size_t max_message_length = 256;
28 
30 {
31  // testing for msg.size() is not sufficient but we're not getting false negatives
32  // and it's cheaper than always converting to std::u32string.
33  if(str.size() > static_cast<int>(chat_message::max_message_length)) {
34  std::string tmp(str.begin(), str.end());
35  // The string can contain utf-8 characters so truncate as std::u32string otherwise
36  // a corrupted utf-8 string can be returned.
38  message.set_attr_dup("message", tmp.c_str());
39  }
40 }
41 
42 } // end chat_message namespace
43 
44 } //end namespace wesnothd
const char * begin() const
Definition: simple_wml.hpp:90
const char * end() const
Definition: simple_wml.hpp:91
Standard logging facilities (interface).
void chat_message(const std::string &caption, const std::string &msg)
Displays a message in the chat window.
void truncate_as_ucs4(std::string &str, const std::size_t size)
Truncates a UTF-8 string to the specified number of characters.
Definition: unicode.cpp:121
void truncate_message(const simple_wml::string_span &str, simple_wml::node &message)
Function to ensure a text message is within the allowed length.
const std::size_t max_message_length
lg::log_domain log_config_pn("config")