HikoGUI
A low latency retained GUI
Loading...
Searching...
No Matches
skeleton_string_node.hpp
1// Copyright Take Vos 2020.
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
9namespace tt {
10
12 std::string text;
13
15 skeleton_node(std::move(location)), text(std::move(text)) {}
16
17 [[nodiscard]] bool should_left_align() const noexcept override { return false; }
18
19 void left_align() noexcept override {
20 // first check if there are only spaces and tabs after the last line feed.
21 auto new_text_length = std::ssize(text);
22 for (auto i = text.crbegin(); i != text.crend(); ++i, --new_text_length) {
23 if (*i == ' ' || *i == '\t') {
24 // Strip spaces and tabs.
25 continue;
26 } else if (*i == '\n') {
27 // Stop here, we are stripping a line upto the last line feed.
28 break;
29 } else {
30 // If there are characters after the last line feed, we do not want to strip the line.
31 return;
32 }
33 }
34 text.resize(new_text_length);
35 }
36
37 std::string string() const noexcept override {
38 return std::format("<text {}>", text);
39 }
40
42 context.write(text);
43 return {};
44 }
45};
46
47}
Definition formula_evaluation_context.hpp:16
void write(std::string_view text) noexcept
Write data to the output.
Definition formula_evaluation_context.hpp:51
Definition parse_location.hpp:17
Definition skeleton_node.hpp:16
Definition skeleton_string_node.hpp:11
void left_align() noexcept override
Remove any trailing spaces or tabs after a new-line.
Definition skeleton_string_node.hpp:19
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
datum evaluate(formula_evaluation_context &context) override
Evaluate the template.
Definition skeleton_string_node.hpp:41
T move(T... args)