Skip to content

Commit b45d416

Browse files
committed
Refactor Consume function to separate consuming tag part and consuming raw char part
1 parent 0364097 commit b45d416

1 file changed

Lines changed: 7 additions & 9 deletions

File tree

Assets/RichTextHelper/RichTextHelper.cs

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -108,21 +108,19 @@ public bool Consume()
108108
{
109109
Debug.Assert(IsConsumable());
110110
var peekedOriginChar = PeekNextOriginChar();
111-
if (peekedOriginChar == '<')
111+
// Only consume the start tag if a tag closing bracket (>) was found.
112+
var isStartTag = peekedOriginChar == '<' && IsNextTagBracketClosing(consumedLength + 1);
113+
var isEndTag = peekedOriginChar == '<' && PeekNextNextOriginChar() == '/';
114+
if (isStartTag || isEndTag)
112115
{
113-
if (PeekNextNextOriginChar() == '/')
116+
if (isEndTag)
114117
{
115118
ConsumeEndTag();
116119
}
117-
else if (IsNextTagBracketClosing(consumedLength + 1)) //Only consume the start tag if a tag closing bracket (>) was found.
120+
else if (isStartTag)
118121
{
119122
ConsumeStartTag();
120123
}
121-
else
122-
{
123-
ConsumeRawChar();
124-
return true;
125-
}
126124

127125
if (IsConsumable())
128126
{
@@ -154,7 +152,7 @@ private char PeekNextOriginChar()
154152
return originalText[consumedLength];
155153
}
156154

157-
//Returns if the first tag bracket found in the string is '>', as opposed to '<'
155+
// Returns if the first tag bracket found in the string is '>', as opposed to '<'
158156
private bool IsNextTagBracketClosing(int charIndexToStartSearch = 0)
159157
{
160158
int bracketIndex = originalText.IndexOfAny(tagBrackets, charIndexToStartSearch);

0 commit comments

Comments
 (0)