Skip to content

Commit

Permalink
remove casting used to bypass const
Browse files Browse the repository at this point in the history
  • Loading branch information
Santiago committed Sep 16, 2023
1 parent a5d12a0 commit 62490a2
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions TextEditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1655,7 +1655,8 @@ TextEditor::Coordinates TextEditor::FindWordStart(const Coordinates& aFrom) cons
if (aFrom.mLine >= (int)mLines.size())
return aFrom;

auto& line = mLines[aFrom.mLine];
int lineIndex = aFrom.mLine;
auto& line = mLines[lineIndex];
int charIndex = GetCharacterIndexL(aFrom);

if (charIndex >= (int)line.size())
Expand All @@ -1664,15 +1665,15 @@ TextEditor::Coordinates TextEditor::FindWordStart(const Coordinates& aFrom) cons
bool initialIsWordChar = CharIsWordChar(line[charIndex].mChar);
bool initialIsSpace = isspace(line[charIndex].mChar);
char initialChar = line[charIndex].mChar;
while (Move((int)aFrom.mLine, charIndex, true, true))
while (Move(lineIndex, charIndex, true, true))
{
bool isWordChar = CharIsWordChar(line[charIndex].mChar);
bool isSpace = isspace(line[charIndex].mChar);
if (initialIsSpace && !isSpace ||
initialIsWordChar && !isWordChar ||
!initialIsWordChar && !initialIsSpace && initialChar != line[charIndex].mChar)
{
Move((int)aFrom.mLine, charIndex, false, true); // one step to the right
Move(lineIndex, charIndex, false, true); // one step to the right
break;
}
}
Expand All @@ -1684,7 +1685,8 @@ TextEditor::Coordinates TextEditor::FindWordEnd(const Coordinates& aFrom) const
if (aFrom.mLine >= (int)mLines.size())
return aFrom;

auto& line = mLines[aFrom.mLine];
int lineIndex = aFrom.mLine;
auto& line = mLines[lineIndex];
auto charIndex = GetCharacterIndexL(aFrom);

if (charIndex >= (int)line.size())
Expand All @@ -1693,7 +1695,7 @@ TextEditor::Coordinates TextEditor::FindWordEnd(const Coordinates& aFrom) const
bool initialIsWordChar = CharIsWordChar(line[charIndex].mChar);
bool initialIsSpace = isspace(line[charIndex].mChar);
char initialChar = line[charIndex].mChar;
while (Move((int)aFrom.mLine, charIndex, false, true))
while (Move(lineIndex, charIndex, false, true))
{
if (charIndex == line.size())
break;
Expand All @@ -1704,7 +1706,7 @@ TextEditor::Coordinates TextEditor::FindWordEnd(const Coordinates& aFrom) const
!initialIsWordChar && !initialIsSpace && initialChar != line[charIndex].mChar)
break;
}
return { aFrom.mLine, GetCharacterColumn(aFrom.mLine, charIndex) };
return { lineIndex, GetCharacterColumn(aFrom.mLine, charIndex) };
}

int TextEditor::GetCharacterIndexL(const Coordinates& aCoordinates) const
Expand Down

0 comments on commit 62490a2

Please sign in to comment.