4 #include <symengine/printers/stringbox.h>
8 #define U8(x) reinterpret_cast<const char *>(u8##x)
15 auto diff = new_width - width_;
26 void StringBox::add_below(StringBox &other)
28 if (other.width_ > width_) {
29 pad_lines(other.width_);
30 width_ = other.width_;
31 }
else if (width_ > other.width_) {
32 other.pad_lines(width_);
33 other.width_ = width_;
35 lines_.insert(lines_.end(), other.lines_.begin(), other.lines_.end());
38 void StringBox::add_below_unicode_line(StringBox &other)
40 auto new_width =
std::max(width_, other.width_);
42 for (
unsigned i = 0; i < new_width; i++) {
45 StringBox barbox(bar, new_width);
50 void StringBox::add_right(StringBox &other)
53 auto this_size = lines_.size();
54 auto other_size = other.lines_.size();
55 if (other_size > this_size) {
65 for (
unsigned i = 0; i < half; i++) {
66 smaller->lines_.push_back(pad);
67 smaller->lines_.insert(smaller->lines_.begin(), pad);
70 smaller->lines_.insert(smaller->lines_.begin(), pad);
72 for (
unsigned i = 0; i < lines_.size(); i++) {
73 lines_[i].append(other.lines_[i]);
75 width_ += other.width_;
78 void StringBox::add_power(StringBox &other)
84 lines_.insert(lines_.begin(),
std::string(width_,
' ') + line);
86 width_ += other.width_;
89 void StringBox::enclose_abs()
92 line.
insert(0, U8(
"\u2502"));
98 void StringBox::enclose_parens()
104 void StringBox::enclose_sqbrackets()
106 add_left_sqbracket();
107 add_right_sqbracket();
110 void StringBox::enclose_curlies()
116 void StringBox::add_left_parens()
118 if (lines_.size() == 1) {
119 lines_[0].insert(0,
"(");
121 lines_[0].insert(0, U8(
"\u239B"));
122 lines_.back().insert(0, U8(
"\u239D"));
123 for (
unsigned i = 1; i < lines_.size() - 1; i++) {
124 lines_[i].insert(0, U8(
"\u239C"));
130 void StringBox::add_right_parens()
132 if (lines_.size() == 1) {
133 lines_[0].append(
")");
135 lines_[0].append(U8(
"\u239E"));
136 lines_.back().append(U8(
"\u23A0"));
137 for (
unsigned i = 1; i < lines_.size() - 1; i++) {
138 lines_[i].append(U8(
"\u239F"));
144 void StringBox::add_left_sqbracket()
146 if (lines_.size() == 1) {
147 lines_[0].insert(0,
"[");
149 lines_[0].insert(0, U8(
"\u23A1"));
150 lines_.back().insert(0, U8(
"\u23A3"));
151 for (
unsigned i = 1; i < lines_.size() - 1; i++) {
152 lines_[i].insert(0, U8(
"\u23A2"));
158 void StringBox::add_left_curly()
160 if (lines_.size() == 1) {
161 lines_[0].insert(0,
"{");
162 }
else if (lines_.size() == 2) {
163 lines_[0].insert(0, U8(
"\u23A7"));
164 lines_[1].insert(0, U8(
"\u23A9"));
165 lines_.insert(lines_.begin() + 1,
168 lines_[0].insert(0, U8(
"\u23A7"));
169 lines_.back().insert(0, U8(
"\u23A9"));
171 for (
std::size_t i = 1; i < lines_.size() - 1; i++) {
173 lines_[i].insert(0, U8(
"\u23A8"));
175 lines_[i].insert(0, U8(
"\u23AA"));
182 void StringBox::add_right_curly()
184 if (lines_.size() == 1) {
185 lines_[0].append(
"}");
186 }
else if (lines_.size() == 2) {
187 lines_[0].append(U8(
"\u23AB"));
188 lines_[1].append(U8(
"\u23AD"));
189 lines_.insert(lines_.begin() + 1,
192 lines_[0].append(U8(
"\u23AB"));
193 lines_.back().append(U8(
"\u23AD"));
195 for (
std::size_t i = 1; i < lines_.size() - 1; i++) {
197 lines_[i].append(U8(
"\u23AC"));
199 lines_[i].append(U8(
"\u23AA"));
206 void StringBox::add_right_sqbracket()
208 if (lines_.size() == 1) {
209 lines_[0].append(
"]");
211 lines_[0].append(U8(
"\u23A4"));
212 lines_.back().append(U8(
"\u23A5"));
213 for (
unsigned i = 1; i < lines_.size() - 1; i++) {
214 lines_[i].append(U8(
"\u23A6"));
220 void StringBox::enclose_floor()
222 lines_.back().insert(0, U8(
"\u230A"));
223 lines_.back().append(U8(
"\u230B"));
224 for (
unsigned i = 0; i < lines_.size() - 1; i++) {
225 lines_[i].insert(0, U8(
"\u2502"));
226 lines_[i].append(U8(
"\u2502"));
231 void StringBox::enclose_ceiling()
233 lines_[0].insert(0, U8(
"\u2308"));
234 lines_[0].append(U8(
"\u2309"));
235 for (
unsigned i = 1; i < lines_.size(); i++) {
236 lines_[i].insert(0, U8(
"\u2502"));
237 lines_[i].append(U8(
"\u2502"));
242 void StringBox::enclose_sqrt()
255 lines_.insert(lines_.begin(),
263 auto b =
begin(lines_), e =
end(lines_);
Main namespace for SymEngine package.