OpenTTD Source 20260721-master-g25ec12c62d
label.cpp
Go to the documentation of this file.
1/*
2 * This file is part of OpenTTD.
3 * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
4 * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
5 * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <https://www.gnu.org/licenses/old-licenses/gpl-2.0>.
6 */
7
9
10#include "../stdafx.h"
11#include "label_type.hpp"
12#include "../string_func.h"
13
14#include "../safeguards.h"
15
22std::string BaseLabel::AsString() const
23{
24 if (std::ranges::all_of(*this, [](uint8_t c) { return std::isgraph(c); })) {
25 return std::string{reinterpret_cast<const char *>(this->data()), this->size()};
26 }
27
28 return FormatArrayAsHex(*this);
29}
A type for 4 character labels/tags/ids in files that should be read/shown as is.
A number of safeguards to prevent using unsafe methods.
Definition of base types and functions in a cross-platform compatible way.
std::string FormatArrayAsHex(std::span< const uint8_t > data)
Format a byte array into a continuous hex string.
Definition string.cpp:77
Functions related to low-level strings.
std::string AsString() const
Get the label as a std::string.
Definition label.cpp:22