Skip to content

Commit

Permalink
[SUTK] Implemented SUTK::Text::remove
Browse files Browse the repository at this point in the history
  • Loading branch information
ravi688 committed Aug 8, 2024
1 parent b11889e commit c9fc45c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
3 changes: 3 additions & 0 deletions sutk/include/sutk/Text.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ namespace SUTK
else
m_data.insert(col, chars);
}

std::size_t size() const noexcept { return m_data.size(); }
};

class LineText : public GfxDriverRenderable
Expand All @@ -91,6 +93,7 @@ namespace SUTK
LineCountType getColPosFromCoord(f32 coord) noexcept;
f32 getCoordFromColPos(LineCountType col) noexcept;
void setData(const std::string& data) noexcept;
const LineTextData& getData() const noexcept { return m_data; }
void removeRange(std::size_t pos, std::size_t len = std::string::npos) noexcept;
void append(const std::string& data) noexcept;
std::string substr(std::size_t pos, std::size_t len) noexcept { return m_data.substr(pos, len); }
Expand Down
7 changes: 7 additions & 0 deletions sutk/source/Text.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,14 @@ namespace SUTK

void Text::remove(const CursorPosition<LineCountType>& position, LineCountType numChars) noexcept
{
if(position.getLine() >= m_lines.size())
return;

LineText* lineText = m_lines[position.getLine()];
if((position.getColumn() + numChars) > lineText->getData().size())
return;

lineText->removeRange(position.getColumn(), numChars);
}

void Text::set(const std::string& str) noexcept
Expand Down

0 comments on commit c9fc45c

Please sign in to comment.