Skip to content

Commit

Permalink
added the const qualifier to methods that do not change the object (#275
Browse files Browse the repository at this point in the history
)

* added the const qualifier to methods that do not change the object

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
  • Loading branch information
TobiasWallner and pre-commit-ci[bot] authored Jul 21, 2023
1 parent f9cf771 commit c3cadc4
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 58 deletions.
12 changes: 6 additions & 6 deletions cpp-terminal/event.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,21 @@

#include "cpp-terminal/platforms/conversion.hpp"

bool Term::Event::empty()
bool Term::Event::empty() const
{
if(m_Type == Type::Empty) return true;
else
return false;
}

Term::Event::operator std::string()
Term::Event::operator std::string() const
{
if(m_Type == Type::CopyPaste) return m_str;
else
return std::string();
}

Term::Event::operator Term::Screen()
Term::Event::operator Term::Screen() const
{
if(m_Type == Type::Screen) return m_Screen;
else
Expand All @@ -27,7 +27,7 @@ Term::Event::Event(const Term::Screen& screen) : m_Type(Type::Screen), m_Screen(

Term::Event::Event(const Term::Key& key) : m_Type(Type::Key), m_Key(key) {}

Term::Event::Type Term::Event::type() { return m_Type; }
Term::Event::Type Term::Event::type() const { return m_Type; }

Term::Event::Event(const std::string& str) : m_Type(Type::CopyPaste), m_str(str) { parse(); }

Expand Down Expand Up @@ -208,14 +208,14 @@ void Term::Event::parse()
}
}

Term::Event::operator Term::Key()
Term::Event::operator Term::Key() const
{
if(m_Type == Type::Key) return m_Key;
else
return Key();
}

Term::Event::operator Term::Cursor()
Term::Event::operator Term::Cursor() const
{
if(m_Type == Type::Cursor) return m_Cursor;
else
Expand Down
12 changes: 6 additions & 6 deletions cpp-terminal/event.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@ class Event
Event(const std::string&);
Event(const Term::Key&);
Event(const Term::Screen& screen);
bool empty();
Type type();
bool empty() const;
Type type() const;

operator Term::Key();
operator Term::Screen();
operator Term::Cursor();
operator std::string();
operator Term::Key() const;
operator Term::Screen() const;
operator Term::Cursor() const;
operator std::string() const;

private:
void parse();
Expand Down
38 changes: 19 additions & 19 deletions cpp-terminal/key.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

#include "cpp-terminal/platforms/conversion.hpp"

std::string Term::Key::str()
std::string Term::Key::str() const
{
std::string ret;
if(m_value >= 0x10FFFF) return std::string();
Expand All @@ -15,122 +15,122 @@ std::string Term::Key::str()

Term::Key::Key(const Term::Key::Value& value) : m_value(value) {}

Term::Key::operator Term::Key::Value() { return m_value; }
Term::Key::operator Term::Key::Value() const { return m_value; }

bool Term::Key::isASCII()
bool Term::Key::isASCII() const
{
if(m_value >= NUL && m_value <= DEL) return true;
else
return false;
}

bool Term::Key::isExtendedASCII()
bool Term::Key::isExtendedASCII() const
{
if(m_value >= NUL && m_value <= 255) return true;
else
return false;
}

bool Term::Key::isCTRL()
bool Term::Key::isCTRL() const
{
// Need to suppress the TAB etc...
if(iscntrl() && m_value != Key::BACKSPACE && m_value != Key::TAB && m_value != ESC && m_value != ENTER && m_value != DEL) return true;
else
return false;
}

bool Term::Key::isALT()
bool Term::Key::isALT() const
{
if(m_value >= Key::ALT && Key::ALT < (Key::ALT << 1)) return true;
else
return false;
}

bool Term::Key::empty()
bool Term::Key::empty() const
{
if(m_value == NO_KEY) return true;
else
return false;
}

bool Term::Key::iscntrl()
bool Term::Key::iscntrl() const
{
if((m_value >= NUL && m_value <= CTRL_UNDERSCORE) || m_value == DEL) return true;
else
return false;
}

bool Term::Key::isblank()
bool Term::Key::isblank() const
{
if(m_value == TAB || m_value == SPACE) return true;
else
return false;
}

bool Term::Key::isspace()
bool Term::Key::isspace() const
{
if(isblank() || (m_value >= CTRL_J && m_value <= ENTER)) return true;
else
return false;
}

bool Term::Key::isupper()
bool Term::Key::isupper() const
{
if(m_value >= A && m_value <= Z) return true;
else
return false;
}

bool Term::Key::islower()
bool Term::Key::islower() const
{
if(m_value >= a && m_value <= z) return true;
else
return false;
}

bool Term::Key::isalpha()
bool Term::Key::isalpha() const
{
if(isupper() || islower()) return true;
else
return false;
}

bool Term::Key::isdigit()
bool Term::Key::isdigit() const
{
if(m_value >= ZERO && m_value <= NINE) return true;
else
return false;
}

bool Term::Key::isxdigit()
bool Term::Key::isxdigit() const
{
if(isdigit() || (m_value >= A && m_value <= F) || (m_value >= a && m_value <= f)) return true;
else
return false;
}

bool Term::Key::isalnum()
bool Term::Key::isalnum() const
{
if(isdigit() || isalpha()) return true;
else
return false;
}

bool Term::Key::ispunct()
bool Term::Key::ispunct() const
{
if((m_value >= EXCLAMATION_MARK && m_value <= SLASH) || (m_value >= COLON && m_value <= AROBASE) || (m_value >= OPEN_BRACKET && m_value <= GRAVE_ACCENT) || (m_value >= OPEN_BRACE && m_value <= TILDE)) return true;
else
return false;
}

bool Term::Key::isgraph()
bool Term::Key::isgraph() const
{
if(isalnum() || ispunct()) return true;
else
return false;
}

bool Term::Key::isprint()
bool Term::Key::isprint() const
{
if(isgraph() || m_value == SPACE) return true;
else
Expand Down
38 changes: 19 additions & 19 deletions cpp-terminal/key.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -196,36 +196,36 @@ class Key
Key() = default;
explicit Key(const Term::Key::Value& value);
// clang-format off
operator Term::Key::Value();
operator Term::Key::Value() const;
// clang-format on

bool iscntrl();
bool isblank();
bool isspace();
bool isupper();
bool islower();
bool isalpha();
bool isdigit();
bool isxdigit();
bool isalnum();
bool ispunct();
bool isgraph();
bool isprint();
bool iscntrl() const;
bool isblank() const;
bool isspace() const;
bool isupper() const;
bool islower() const;
bool isalpha() const;
bool isdigit() const;
bool isxdigit() const;
bool isalnum() const;
bool ispunct() const;
bool isgraph() const;
bool isprint() const;

char tolower();
char toupper();

// Detect if Key is convertible to ANSII
bool isASCII();
bool isASCII() const;
// Detect if Key is convertible to Extended ANSII
bool isExtendedASCII();
bool isExtendedASCII() const;
// Detect if Key is CTRL+*
bool isCTRL();
bool isCTRL() const;
// Detect if Key is ALT+*
bool isALT();
bool empty();
bool isALT() const;
bool empty() const;

std::string str();
std::string str() const;

private:
Value m_value{NO_KEY};
Expand Down
8 changes: 4 additions & 4 deletions cpp-terminal/screen.cpp
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
#include "cpp-terminal/screen.hpp"

std::size_t Term::Screen::rows() { return m_size.first; }
std::size_t Term::Screen::rows() const { return m_size.first; }

std::size_t Term::Screen::columns() { return m_size.second; }
std::size_t Term::Screen::columns() const { return m_size.second; }

bool Term::Screen::empty()
bool Term::Screen::empty() const
{
if(m_size.second == 0 && m_size.first == 0) return true;
else
return false;
}

std::pair<std::size_t, std::size_t> Term::Screen::size() { return m_size; }
std::pair<std::size_t, std::size_t> Term::Screen::size() const { return m_size; }

std::string Term::clear_screen() { return "\x1b[2J"; }

Expand Down
8 changes: 4 additions & 4 deletions cpp-terminal/screen.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ class Screen
public:
Screen() = default;
Screen(const std::size_t& rows, const std::size_t& columns) { m_size = {rows, columns}; }
std::size_t rows();
std::size_t columns();
std::pair<std::size_t, std::size_t> size();
bool empty();
std::size_t rows() const;
std::size_t columns() const;
std::pair<std::size_t, std::size_t> size() const;
bool empty() const;

private:
std::pair<std::size_t, std::size_t> m_size{0, 0};
Expand Down

0 comments on commit c3cadc4

Please sign in to comment.