mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-10-17 02:49:19 +02:00
refactor(editor): shared plan geometry and formatting helpers
This commit is contained in:
26
editor/editorFormat.hpp
Normal file
26
editor/editorFormat.hpp
Normal file
@@ -0,0 +1,26 @@
|
||||
/*
|
||||
This Source Code Form is subject to the
|
||||
terms of the Mozilla Public License, v.
|
||||
2.0. If a copy of the MPL was not
|
||||
distributed with this file, You can
|
||||
obtain one at
|
||||
http://mozilla.org/MPL/2.0/.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <cstdio>
|
||||
#include <string>
|
||||
|
||||
// printf-style formatting into a string, for the messages and the data lines of the editor
|
||||
template <typename... Args>
|
||||
std::string format(char const *Format, Args... Arguments)
|
||||
{
|
||||
auto const length{std::snprintf(nullptr, 0, Format, Arguments...)};
|
||||
if (length <= 0)
|
||||
return {};
|
||||
std::string text(static_cast<std::size_t>(length) + 1, '\0');
|
||||
std::snprintf(text.data(), text.size(), Format, Arguments...);
|
||||
text.resize(static_cast<std::size_t>(length));
|
||||
return text;
|
||||
}
|
||||
Reference in New Issue
Block a user