Browse Source

Merge branch 'cameron'

grissess
Cameron Weinfurt 4 years ago
parent
commit
e8376ac8d1
  1. 55
      src/Buffer.cpp
  2. 2
      src/Buffer.h
  3. BIN
      src/Buffer.o
  4. BIN
      src/FileBrowser
  5. 6
      src/FileBrowser.cpp
  6. 3
      src/FileBrowser.h
  7. BIN
      src/FileBrowser.o
  8. BIN
      src/main.o
  9. 5
      test.txt

55
src/Buffer.cpp

@ -24,9 +24,58 @@ bool Buffer::open(const string & new_file_name)
// Note: the vector is cleared only after we know the file
// opened successfully.
string line;
while (getline(file, line))
v_lines_.push_back(line);
int curr_link = 0;
std::string curr_p, line;
while(getline(file, line))
{
// Remove any newlines that are in the file.
for(auto char_loc = line.find_first_of('\n'); char_loc != -1; char_loc = line.find_first_of('\n'))
line.erase(char_loc, 1);
// Replace break tags with newlines.
for(auto char_loc = line.find("<br>"); char_loc != -1; char_loc = line.find("<br>"))
line.replace(char_loc, 4, "\n");
// Find link tags and process them.
for(auto tag_loc = line.find("<a "); tag_loc != -1; tag_loc = line.find("<a", tag_loc + 1))
{
++curr_link;
auto tag_len = line.find_first_of('>', tag_loc) - tag_loc;
std::string link_tag = line.substr(tag_loc + 3, tag_len - 3);
auto second_space_loc = link_tag.find_first_of(' ', 0);
std::string file_name = link_tag.substr(0, second_space_loc - 1);
std::string link_name = link_tag.substr(second_space_loc + 1);
v_links_.push_back({file_name, link_name});
line.replace(tag_loc, tag_len + 1, "<" + link_name + ">[" + to_string(curr_link) + "]");
}
// Search for all paragraphs in the line and add them to the v_lines vector.
for(auto p_tag = line.find("<p>"); p_tag != -1; p_tag = line.find("<p>"))
{
std::string extra_text = line.substr(p_tag + 4);
line.erase(p_tag);
curr_p += line;
// However, if the paragraph is empty, then it shouldn't be added.
if(curr_p != "")
{
v_lines_.push_back(curr_p);
curr_p = "";
}
line = extra_text;
}
// Append any data left on this line to the current paragraph being read.
curr_p += line;
}
// Push the contents of curr_p as it has the last paragraph in the file.
v_lines_.push_back(curr_p);
file_name_ = new_file_name;
ix_top_line_ = 0;

2
src/Buffer.h

@ -5,6 +5,7 @@
#include <fstream>
#include <iomanip>
#include <sstream>
#include <iostream>
#include <string>
#include <vector>
@ -21,6 +22,7 @@ public:
private:
std::vector<std::string> v_lines_;
std::vector<std::pair<std::string, std::string>> v_links_;
int ix_top_line_ = 0;
std::string file_name_;
int window_height_;

BIN
src/Buffer.o

BIN
src/FileBrowser

6
src/FileBrowser.cpp

@ -9,7 +9,7 @@ void FileBrowser::display()
const string long_separator(50, '-');
const string short_separator(8, '-');
system(clear_command);
system("cls || clear");
if (!error_message_.empty()) {
cout << "ERROR: " + error_message_ << endl;
@ -33,7 +33,7 @@ void FileBrowser::display()
void FileBrowser::execute_command(char command, bool & done)
{
switch (command) {
case 'b': {
/*case 'b': {
buffer_.back();
break;
}
@ -53,7 +53,7 @@ void FileBrowser::execute_command(char command, bool & done)
}
buffer_.go(link);
break;
}
}*/
case 'n': {
buffer_.move_to_next_page();
break;

3
src/FileBrowser.h

@ -10,9 +10,6 @@
#include "Buffer.h"
const char clear_command[] = "cls"; // for Windows
//const char clear_command[] = "clear"; // for Linux and possibly Mac's
class FileBrowser
{
public:

BIN
src/FileBrowser.o

BIN
src/main.o

5
test.txt

@ -0,0 +1,5 @@
<p> This is the first line in the file.
<p> This is the second <br> and third line of the file.
<p> This line has a link to the <a docs/specification.txt specification> file.
<p> This line is split into <p> two paragraph tags.
<p> This line contains some<br> problematic<p> tags.
Loading…
Cancel
Save