-
Notifications
You must be signed in to change notification settings - Fork 0
/
EditorModel.cpp
84 lines (62 loc) · 1.31 KB
/
EditorModel.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
// EditorModel.cpp
//
// ICS 45C Spring 2022
// Project #4: People Just Love to Play with Words
//
// Implementation of the EditorModel class
#include "EditorModel.hpp"
#include "EditorException.hpp"
EditorModel::EditorModel()
: row{1}, col{1}
{
totalLines.push_back("");
}
int EditorModel::cursorLine() const
{
return row;
}
int EditorModel::cursorColumn() const
{
return col;
}
int EditorModel::lineCount() const
{
return totalLines.size();
}
const std::string& EditorModel::line(int lineNumber) const
{
return totalLines[lineNumber-1];
}
const std::string& EditorModel::currentErrorMessage() const
{
return errormessage;
}
void EditorModel::setErrorMessage(const std::string& errorMessage)
{
errormessage = errorMessage;
}
void EditorModel::clearErrorMessage()
{
errormessage = "";
}
void EditorModel::setCol(unsigned int newCol)
{
col = newCol;
}
void EditorModel::setRow(unsigned int newRow)
{
row = newRow;
}
void EditorModel::setText(std::string& newText, unsigned int row)
{
totalLines[row-1] = newText;
}
void EditorModel::createNewLine(std::string& text, unsigned int row)
{
auto iterator = totalLines.begin() + row;
totalLines.insert(iterator, text);
}
void EditorModel::deleteLine(unsigned int row)
{
totalLines.erase(totalLines.begin() + row-1);
}