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 hi::inline v1 {
10
12 std::string text;
13
14 skeleton_string_node(parse_location location, std::string text) : skeleton_node(std::move(location)), text(std::move(text)) {}
15
16 [[nodiscard]] bool should_left_align() const noexcept override
17 {
18 return false;
19 }
20
21 void left_align() noexcept override
22 {
23 // first check if there are only spaces and tabs after the last line feed.
24 auto new_text_length = ssize(text);
25 for (auto i = text.crbegin(); i != text.crend(); ++i, --new_text_length) {
26 if (*i == ' ' || *i == '\t') {
27 // Strip spaces and tabs.
28 continue;
29 } else if (*i == '\n') {
30 // Stop here, we are stripping a line upto the last line feed.
31 break;
32 } else {
33 // If there are characters after the last line feed, we do not want to strip the line.
34 return;
35 }
36 }
37 text.resize(new_text_length);
38 }
39
40 std::string string() const noexcept override
41 {
42 return std::format("<text {}>", text);
43 }
44
46 {
47 context.write(text);
48 return {};
49 }
50};
51
52} // namespace hi::inline v1
A dynamic data type.
Definition datum.hpp:209
Definition formula_evaluation_context.hpp:16
void write(std::string_view text) noexcept
Write data to the output.
Definition formula_evaluation_context.hpp:50
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:21
datum evaluate(formula_evaluation_context &context) override
Evaluate the template.
Definition skeleton_string_node.hpp:45
bool should_left_align() const noexcept override
Should any spaces on the left side of a statement be removed?
Definition skeleton_string_node.hpp:16
T move(T... args)