Skip to content

Commit

Permalink
Refactor Consume function to separate consuming tag part and consum…
Browse files Browse the repository at this point in the history
…ing raw char part
  • Loading branch information
majecty committed Jan 12, 2020
1 parent 0364097 commit b45d416
Showing 1 changed file with 7 additions and 9 deletions.
16 changes: 7 additions & 9 deletions Assets/RichTextHelper/RichTextHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -108,21 +108,19 @@ public bool Consume()
{
Debug.Assert(IsConsumable());
var peekedOriginChar = PeekNextOriginChar();
if (peekedOriginChar == '<')
// Only consume the start tag if a tag closing bracket (>) was found.
var isStartTag = peekedOriginChar == '<' && IsNextTagBracketClosing(consumedLength + 1);
var isEndTag = peekedOriginChar == '<' && PeekNextNextOriginChar() == '/';
if (isStartTag || isEndTag)
{
if (PeekNextNextOriginChar() == '/')
if (isEndTag)
{
ConsumeEndTag();
}
else if (IsNextTagBracketClosing(consumedLength + 1)) //Only consume the start tag if a tag closing bracket (>) was found.
else if (isStartTag)
{
ConsumeStartTag();
}
else
{
ConsumeRawChar();
return true;
}

if (IsConsumable())
{
Expand Down Expand Up @@ -154,7 +152,7 @@ private char PeekNextOriginChar()
return originalText[consumedLength];
}

//Returns if the first tag bracket found in the string is '>', as opposed to '<'
// Returns if the first tag bracket found in the string is '>', as opposed to '<'
private bool IsNextTagBracketClosing(int charIndexToStartSearch = 0)
{
int bracketIndex = originalText.IndexOfAny(tagBrackets, charIndexToStartSearch);
Expand Down

0 comments on commit b45d416

Please sign in to comment.