This repository has been archived by the owner on Mar 27, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSlide.cpp
106 lines (98 loc) · 2.85 KB
/
Slide.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
#include "Slide.h"
#include <iostream>
#include <utility>
#include "string"
#include <vector>
#include <sstream>
#include "utils/config_parser.h"
#include <iterator>
const int FULL_SIZE_LENGTH = std::stoi(parse().at("line_length"));
using namespace std;
Slide::Slide(string title, string content) {
this->title = move(title);
// If number is not even correct this to ensure it's centered correctly
if (this->title.length()%2!=0)
this->title += " ";
this->content = move(content);
}
void Slide::showSlide() const {
// Print header
for (int i = 0; i < FULL_SIZE_LENGTH; i++)
cout << "#";
// Print spacer
cout << endl << "#";
for (int i = 0; i < FULL_SIZE_LENGTH - 2; i++)
cout << " ";
cout << "#" << endl;
// Print beginning of line
cout << "#";
// Calculate center position
int to_center = Slide::calculate_center(title);
// Print first half
for (int i = 0; i < to_center; i++)
cout << " ";
// Print text
cout << title;
// Print second half
for (int i = 0; i < to_center; i++)
cout << " ";
cout << "#" << endl;
// Print spacer
cout << "#";
for (int i = 0; i < FULL_SIZE_LENGTH - 2; i++)
cout << " ";
cout << "#" << endl;
vector<string> words;
Slide::split_sentence(content, words);
string final_content = "# ";
int line_size = 0;
int l = 1;
for (auto & word : words) {
line_size += word.length() + 1;
if (line_size > FULL_SIZE_LENGTH - 4) {
for (int s = 0; s < (FULL_SIZE_LENGTH - (line_size - word.length()) - 2); s++)
final_content += " ";
final_content += "#\n# ";
line_size = 1 + word.length();
}
if (l == words.size()) {
final_content += word;
int left = (FULL_SIZE_LENGTH - 2) - line_size;
for (int s = 0; s < left; s++)
final_content += " ";
final_content += "#";
}
else {
final_content += word + " ";
}
l++;
}
cout << final_content << endl;
// Print spacer
cout << "#";
for (int i = 0; i < FULL_SIZE_LENGTH - 2; i++)
cout << " ";
cout << "#" << endl;
// Print footer
for (int i = 0; i < FULL_SIZE_LENGTH; i++)
cout << "#";
}
int Slide::calculate_center(const string& text) {
int len = text.length();
return (FULL_SIZE_LENGTH - len - 2) / 2;
}
void Slide::split_sentence(const string& str, vector<string>& cont)
{
istringstream iss(str);
copy(istream_iterator<string>(iss),
istream_iterator<string>(),
back_inserter(cont));
for(auto & i : cont){
string word = i;
for(int j = 0, len = word.length(); j < len; j++){
if(ispunct(word[j])){
i = word.substr(0, word.length() - 1);
}
}
}
}