HikoGUI
A low latency retained GUI
Loading...
Searching...
No Matches
skeleton_string_node.hpp
1// Copyright Take Vos 2020-2021.
2// Distributed under the Boost Software License, Version 1.0.
3// (See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt)
4
5#pragma once
6
7#include "skeleton_node.hpp"
8#include "../macros.hpp"
9
10namespace hi::inline v1 {
11
13 std::string text;
14
15 skeleton_string_node(parse_location location, std::string text) : skeleton_node(std::move(location)), text(std::move(text)) {}
16
17 [[nodiscard]] bool should_left_align() const noexcept override
18 {
19 return false;
20 }
21
22 void left_align() noexcept override
23 {
24 // first check if there are only spaces and tabs after the last line feed.
25 auto new_text_length = ssize(text);
26 for (auto i = text.crbegin(); i != text.crend(); ++i, --new_text_length) {
27 if (*i == ' ' || *i == '\t') {
28 // Strip spaces and tabs.
29 continue;
30 } else if (*i == '\n') {
31 // Stop here, we are stripping a line upto the last line feed.
32 break;
33 } else {
34 // If there are characters after the last line feed, we do not want to strip the line.
35 return;
36 }
37 }
38 text.resize(new_text_length);
39 }
40
41 std::string string() const noexcept override
42 {
43 return std::format("<text {}>", text);
44 }
45
46 datum evaluate(formula_evaluation_context &context) override
47 {
48 context.write(text);
49 return {};
50 }
51};
52
53} // namespace hi::inline v1
DOXYGEN BUG.
Definition algorithm.hpp:16
constexpr Out narrow_cast(In const &rhs) noexcept
Cast numeric values without loss of precision.
Definition cast.hpp:377
Definition parse_location.hpp:18
Definition skeleton_node.hpp:16
Definition skeleton_string_node.hpp:12
void left_align() noexcept override
Remove any trailing spaces or tabs after a new-line.
Definition skeleton_string_node.hpp:22
datum evaluate(formula_evaluation_context &context) override
Evaluate the template.
Definition skeleton_string_node.hpp:46
bool should_left_align() const noexcept override
Should any spaces on the left side of a statement be removed?
Definition skeleton_string_node.hpp:17
T move(T... args)