Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
3150_project/ECRow.cpp
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
161 lines (142 sloc)
2.74 KB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// ECRow.cpp | |
// | |
// created by Daniel Backal | |
// 03/04/2020 | |
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | |
#include "ECRow.h" | |
#include "ECTextViewImp.h" | |
#include <iostream> | |
#include <string> | |
using namespace std; | |
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | |
// ECRow Implementation | |
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | |
ECRow :: ECRow() | |
{ | |
SetFirst(false); | |
} | |
ECRow :: ~ECRow() {} | |
void ECRow :: SetFirst(bool first) | |
{ | |
_first = first; | |
return; | |
} | |
bool ECRow :: IsFirst() | |
{ | |
return _first; | |
} | |
int ECRow :: GetSize() | |
{ | |
return _row.size(); | |
} | |
int ECRow :: GetChar(int x) | |
{ | |
return int(_row[x]); | |
} | |
string ECRow :: ShowSelf() | |
{ | |
return _row; | |
} | |
int ECRow :: FirstWord() | |
{ | |
return _firstWord; | |
} | |
void ECRow :: CalculateFirstWord() | |
{ | |
_firstWord = 0; | |
for (int i = 0; i < GetSize(); i++) | |
{ | |
if (( i == 0) && (_row[i] == ' ')) | |
{ | |
_firstWord += 1; | |
} | |
else if (_row[i] != ' ') | |
{ | |
_firstWord += 1; | |
} | |
else | |
{ | |
break; | |
} | |
} | |
return; | |
} | |
void ECRow :: AddCharAt(int pos, int key) | |
{ | |
char letter = static_cast<char>(key); | |
if (GetSize() == pos) | |
{ | |
_row += letter; | |
} | |
else | |
{ | |
string text; | |
text += letter; | |
_row.insert(pos, text); | |
} | |
CalculateFirstWord(); | |
return; | |
} | |
int ECRow :: RemoveCharAt(int pos) | |
{ | |
if (pos == 0) | |
{ | |
// if (_first) | |
// { | |
// return KEY_NULL; | |
// } | |
return BACKSPACE; | |
} | |
_row.erase(_row.begin()+pos-1); | |
return ARROW_LEFT; | |
} | |
string ECRow :: AddEnterAt(int pos) | |
{ | |
string res = ""; | |
if (pos == GetSize()) | |
{ | |
return res; | |
} | |
int todel = 0; | |
for (auto it = _row.begin() + pos; it != _row.end(); it++) | |
{ | |
res += *it; | |
todel += 1; | |
} | |
for (int i = 0; i < todel; i++) | |
{ | |
_row.pop_back(); | |
} | |
return res; | |
} | |
string ECRow :: GetLastWord() | |
{ | |
string res; | |
int i; | |
for (i = GetSize()-1; i > -1; i--) | |
{ | |
if (_row[i] == ' ') | |
{ | |
if (i == GetSize()-1) | |
{ | |
continue; | |
} | |
else | |
{ | |
i += 1; | |
break; | |
} | |
} | |
} | |
res = _row.substr(i); | |
_row.erase(_row.begin()+i, _row.end()); | |
return res; | |
} | |
string ECRow :: GetFirstWord() | |
{ | |
string res = _row.substr(0, _firstWord); | |
_row.erase(0, _firstWord); | |
CalculateFirstWord(); | |
return res; | |
} |