Steppable 0.0.1
A CAS project written from scratch in C++
Loading...
Searching...
No Matches
symbols.hpp
1/**************************************************************************************************
2 * Copyright (c) 2023-2025 NWSOFT *
3 * *
4 * Permission is hereby granted, free of charge, to any person obtaining a copy *
5 * of this software and associated documentation files (the "Software"), to deal *
6 * in the Software without restriction, including without limitation the rights *
7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell *
8 * copies of the Software, and to permit persons to whom the Software is *
9 * furnished to do so, subject to the following conditions: *
10 * *
11 * The above copyright notice and this permission notice shall be included in all *
12 * copies or substantial portions of the Software. *
13 * *
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE *
17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER *
18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, *
19 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE *
20 * SOFTWARE. *
21 **************************************************************************************************/
22
32
33#pragma once
34
35#include <array>
36#include <cstddef>
37#include <string>
38#include <string_view>
39#include <vector>
40
46{
50 struct Position
51 {
52 long long x = 0;
53 long long y = 0;
54 };
55
56 // // Not currently in use.
57 // enum PrintingAlignment
58 // {
59 // BASELINE = 0,
60 // MIDDLE = 1
61 // };
62
63 // struct PrintingObj
64 // {
65 // std::string str;
66 // PrintingAlignment alignment;
67 // };
68
73 {
74 private:
77
79 std::vector<std::vector<char>> buffer;
80
82 size_t height = 10;
83
85 size_t width = 10;
86
87 public:
94 ConsoleOutput(size_t height, size_t width);
95
104 void write(char c, long long dLine, long long dCol, bool updatePos = false);
105
113 void write(char c, const Position& pos, bool updatePos = false);
114
122 void write(const std::string& s, const Position& pos, bool updatePos = false);
123
128 [[nodiscard]] std::string asString() const;
129 };
130
137 size_t getStringWidth(const std::string& s);
138
145 size_t getStringHeight(const std::string& s);
146} // namespace steppable::prettyPrint
147
158{
160 constexpr std::string_view BECAUSE = "\u2235";
162 constexpr std::string_view THEREFORE = "\u2234";
163
165 constexpr std::string_view MULTIPLY = "\u00D7";
167 constexpr std::string_view DIVIDED_BY = "\u00F7";
168
169 constexpr std::string_view SURD = "\u221A";
170 constexpr std::string_view COMBINE_MACRON = "\u0305";
171
173 constexpr std::string_view LARGE_DOT = "\u25C9";
174 constexpr std::string_view ABOVE_DOT = "\u02D9";
175
176 // Subscripts
181 constexpr std::string_view SUB_0 = "\u2080";
186 constexpr std::string_view SUB_Z = "\u1D69";
191 constexpr int SUB_MAGIC_NUMBER = 8272;
192
194 extern const std::array<std::string, 10>& SUPERSCRIPTS;
195
202 std::string makeSubscript(const std::string& normal);
203
210 std::string makeSubscript(int normal);
211
212 // Superscripts
217 constexpr std::string_view SUP_0 = "\u2070";
222 constexpr std::string_view SUP_Z = "\u1DBB";
227 constexpr int SUP_MAGIC_NUMBER = 8304;
228
235 std::string makeSuperscript(const std::string& normal);
236
243 std::string makeSuperscript(char normal);
244
251 std::string makeSurd(const std::string& radicand);
252} // namespace steppable::__internals::symbols
253
259{
267 std::string ppRoot(const std::string& radicand, const std::string& index = "2");
268
277 std::string ppFraction(const std::string& top, const std::string& bottom, bool inLine = false);
278
286 std::string ppSubscript(const std::string& base, const std::string& subscript);
287
295 std::string ppSuperscript(const std::string& base, const std::string& superscript);
296} // namespace steppable::prettyPrint::printers
Position curPos
The current position.
Definition symbols.hpp:76
size_t height
The height of the buffer.
Definition symbols.hpp:82
std::vector< std::vector< char > > buffer
The buffer object.
Definition symbols.hpp:79
std::string asString() const
Gets the buffer as a string.
Definition symbols.cpp:99
size_t width
The width of the buffer.
Definition symbols.hpp:85
void write(char c, long long dLine, long long dCol, bool updatePos=false)
Writes a character to the buffer.
Definition symbols.cpp:55
ConsoleOutput(size_t height, size_t width)
Creates a new console output buffer.
Definition symbols.cpp:40
The namespace containing various unicode symbols.
Definition symbols.cpp:124
constexpr std::string_view SUB_Z
The subscript z (Unicode U+2098)
Definition symbols.hpp:186
constexpr std::string_view LARGE_DOT
The large dot symbol (Unicode U+25C9)
Definition symbols.hpp:173
constexpr std::string_view SUP_Z
The superscript z (Unicode U+1DBB)
Definition symbols.hpp:222
constexpr std::string_view THEREFORE
The therefore symbol (3 dots in a triangle, Unicode U+2234)
Definition symbols.hpp:162
constexpr std::string_view BECAUSE
The because symbol (3 dots in a triangle, Unicode U+2235)
Definition symbols.hpp:160
const std::array< std::string, 10 > & SUPERSCRIPTS
A list of subscript characters.
Definition symbols.cpp:128
constexpr int SUB_MAGIC_NUMBER
The subscript magic number (8272)
Definition symbols.hpp:191
constexpr std::string_view SUB_0
The subscript 0 (Unicode U+2080)
Definition symbols.hpp:181
constexpr std::string_view MULTIPLY
The multiply symbol (Unicode U+00D7)
Definition symbols.hpp:165
std::string makeSubscript(const std::string &normal)
Create a subscript string from a normal string.
Definition symbols.cpp:131
std::string makeSurd(const std::string &radicand)
Makes a surd expression from a radicand.
Definition symbols.cpp:164
std::string makeSuperscript(const std::string &normal)
Create a superscript string from a normal string.
Definition symbols.cpp:144
constexpr std::string_view SURD
Definition symbols.hpp:169
constexpr std::string_view ABOVE_DOT
Definition symbols.hpp:174
constexpr std::string_view COMBINE_MACRON
Definition symbols.hpp:170
constexpr std::string_view SUP_0
The superscript 0 (Unicode U+2070)
Definition symbols.hpp:217
constexpr int SUP_MAGIC_NUMBER
The superscript magic number (8304)
Definition symbols.hpp:227
constexpr std::string_view DIVIDED_BY
The divide symbol (Unicode U+00F7)
Definition symbols.hpp:167
The custom-implemented printer engines for outputting expressions.
Definition baseConvert.cpp:50
std::string ppFraction(const std::string &top, const std::string &bottom, const bool inLine)
Pretty print a fraction.
Definition fraction.cpp:52
std::string ppSubscript(const std::string &base, const std::string &subscript)
Pretty print a base expression, (aka, subscript).
Definition baseConvert.cpp:51
std::string ppRoot(const std::string &radicand, const std::string &index)
Pretty print a root expression.
Definition root.cpp:59
std::string ppSuperscript(const std::string &base, const std::string &superscript)
Pretty print a power expression, (aka, superscript).
Definition power.cpp:47
The namespace containing utilities for pretty printing.
Definition baseConvert.cpp:50
size_t getStringWidth(const std::string &s)
Gets the minimal width needed to print a string.
Definition symbols.cpp:111
size_t getStringHeight(const std::string &s)
Gets the minimal height needed to print a string.
Definition symbols.cpp:120
Represents a position in the console.
Definition symbols.hpp:51
long long x
Definition symbols.hpp:52
long long y
Definition symbols.hpp:53
Untitled