Make get_line DRY
This commit is contained in:
parent
ac45e6d47c
commit
ea7db7ef4e
1 changed files with 4 additions and 5 deletions
9
main.cpp
9
main.cpp
|
@ -23,16 +23,15 @@ position clp;
|
|||
treap selection;
|
||||
|
||||
// Accessing the file
|
||||
string get_line(count_type r) {
|
||||
string get_line(count_type r, bool clean = true) {
|
||||
string line = (*file.find(file_offset+r)).text;
|
||||
if(!clean)
|
||||
return line;
|
||||
for(count_type i = 0; i < line.size(); ++i)
|
||||
if(line[i] == '\t')
|
||||
line[i] = ' ';
|
||||
return line;
|
||||
}
|
||||
string get_line_raw(count_type r) {
|
||||
return file.find(file_offset+r)->text;
|
||||
}
|
||||
char get(position p) { return get_line(file_offset+p.r)[p.c]; }
|
||||
void set(position p, char ch) { file.find(file_offset+p.r)->text[p.c] = ch; }
|
||||
void new_line(count_type r, string text = "") { file.insert(file_offset+r, text); }
|
||||
|
@ -70,7 +69,7 @@ bool save(string filename) {
|
|||
return 1;
|
||||
|
||||
for(count_type i = 0; i < file.size(); ++i)
|
||||
outfile << get_line_raw(i-file_offset) << std::endl;
|
||||
outfile << get_line(i-file_offset, 0) << std::endl;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue