Implemented fallback to lesser terminators for line splitting

This commit is contained in:
lumpn 2023-04-20 13:43:17 +08:00
parent 4805f49ccb
commit c20d1113c1
2 changed files with 19 additions and 2 deletions

View File

@ -208,16 +208,32 @@ bool UTypewriterTextWidget::IsSentenceTerminator(TCHAR Letter)
return Letter == '.' || Letter == '!' || Letter == '?';
}
bool UTypewriterTextWidget::IsClauseTerminator(TCHAR Letter)
{
return Letter == ',' || Letter == ';';
}
int UTypewriterTextWidget::FindLastTerminator(const FString& CurrentLineString, int Count)
{
// TODO Jonas: Find lesser terminators like commas or spaces if no sentence terminator can be found.
int TerminatorIndex = CurrentLineString.FindLastCharByPredicate(IsSentenceTerminator, Count);
if (TerminatorIndex != INDEX_NONE)
{
return TerminatorIndex;
}
return Count;
TerminatorIndex = CurrentLineString.FindLastCharByPredicate(IsClauseTerminator, Count);
if (TerminatorIndex != INDEX_NONE)
{
return TerminatorIndex;
}
TerminatorIndex = CurrentLineString.FindLastCharByPredicate(FText::IsWhitespace, Count);
if (TerminatorIndex != INDEX_NONE)
{
return TerminatorIndex;
}
return (Count - 1);
}
int UTypewriterTextWidget::CalculateMaxLength(int MaxNumberOfLines)

View File

@ -131,6 +131,7 @@ protected:
private:
void PlayNextLetter();
static bool IsSentenceTerminator(TCHAR Letter);
static bool IsClauseTerminator(TCHAR Letter);
static int FindLastTerminator(const FString& CurrentLineString, int Count);
int CalculateMaxLength(int MaxNumberOfLines);