Browse Source

Made split_line push to v_lines_ rather than return a vector to immediately be concated. Fixed issue with breaks circumventing split_line

stew^2
Cameron Weinfurt 3 years ago
parent
commit
5b7c5aae52
  1. 2
      build.sh
  2. 102
      src/Buffer.cpp
  3. 3
      src/Buffer.h
  4. BIN
      src/Buffer.h.gch
  5. BIN
      src/FileBrowser.h.gch

2
build.sh

@ -3,7 +3,7 @@ if [ ! -d obj ]; then
mkdir obj
fi
cd obj
g++ ../src/*.cpp -c
g++ ../src/*.cpp -c -g
cd ..
if [ ! -d bin ]; then
mkdir bin

102
src/Buffer.cpp

@ -16,58 +16,52 @@ void Buffer::display() const
}
//Pass the string by copy because I don't want to change the original, but still need to manipulate it
vector<string> Buffer::split_line(string str) {
vector<string> v = {};
//Split up the lines
void Buffer::split_line(string str)
{
// Split up the lines and then push them onto the line vector
while (str.length() > maximum_length_)
{
//Initialize the substring and set the positions in the string where they need to exist
string str_part = str;
size_t curr_pos = str_part.find(" ");
size_t total_pos = curr_pos;
bool searching = true;
//While searching for the next space in a string
while (searching)
//Initialize the substring and set the positions in the string where they need to exist
string str_part = str;
size_t curr_pos = str_part.find(" ");
size_t total_pos = curr_pos;
bool searching = true;
//While searching for the next space in a string
while (searching)
{
str_part = str_part.substr(curr_pos + 1, str_part.length());
curr_pos = str_part.find(" ");
if (curr_pos == -1)
{
searching = false;
str_part = str_part.substr(curr_pos + 1, str_part.length());
curr_pos = str_part.find(" ");
if (curr_pos == -1)
{
searching = false;
}
else if (total_pos + curr_pos + 1 > maximum_length_)
{
searching = false;
else if (total_pos + curr_pos + 1 > maximum_length_)
{
searching = false;
}
else
{
total_pos += curr_pos + 1;
}
else
{
total_pos += curr_pos + 1;
}
}
//Check if the string part can still be chopped
if (str_part.length() != str.length()) {
}
//Check if the string part can still be chopped
if (str_part.length() != str.length())
{
str_part = str.substr(0, total_pos);
cout << str_part << endl;
str = str.substr(total_pos + 1, str.length());
v.push_back(str_part);
str = str.substr(total_pos + 1, str.length());
v_lines_.push_back(str_part);
}
//Break out of the loop because there is no way to make the string shorter
//I also didn't see why I can't use break and would have to use a boolean
else {
break;
}
}
v.push_back(str);
//for (auto e: v)
// cout << e << endl;
return v;
//Break out of the loop because there is no way to make the string shorter
//I also didn't see why I can't use break and would have to use a boolean
else
{
break;
}
}
v_lines_.push_back(str);
}
size_t Buffer::get_tag_(const string & line)
{
size_t p_tag = line.find("<p>");
@ -131,8 +125,7 @@ bool Buffer::open(const string & new_file_name)
//However, if the tag is located at the start of the file, there will be no data, so it shouldn't be added as it will be an empty line.
if(curr_line != "")
{
//TODO This is causing some issues
v_lines_.push_back(curr_line);
split_line(curr_line);
curr_line = "";
if(is_p)
@ -145,22 +138,11 @@ bool Buffer::open(const string & new_file_name)
line = extra_text;
}
curr_line += line;
//Checks if the current line length is greater than the max,
//then splits it up and adds it to the vector if it is
if (curr_line.length() > maximum_length_) {
vector<string> v_split_line = split_line(curr_line);
for (auto e: v_split_line) {
v_lines_.push_back(e);
}
curr_line = "";
}
}
//Push the contents of curr_p as it has the last line in the file.
v_lines_.push_back(curr_line);
ix_top_line_ = 0;
// Push the contents of curr_line as it has the last line in the file.
split_line(curr_line);
ix_top_line_ = 0;
file_name_ = new_file_name;
return true;

3
src/Buffer.h

@ -26,8 +26,9 @@ public:
private:
std::size_t get_tag_(const std::string & line);
void split_line(std::string str);
std::string file_name_;
std::vector<std::string> split_line(std::string str);
std::vector<std::string> v_lines_;
std::vector<std::pair<std::string, std::string>> v_links_;
int ix_top_line_ = 0;

BIN
src/Buffer.h.gch

BIN
src/FileBrowser.h.gch

Loading…
Cancel
Save