|
|
@ -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; |
|
|
|