Files
UnrealEngineUWP/Engine/Source/Runtime/Slate/Private/Framework/Text/TextRange.cpp
Ben Marsh 20bf0eb6a1 Updating copyright notices to 2017 (copying from //Tasks/UE4/Dev-Copyright-2017).
#rb none
#lockdown Nick.Penwarden

[CL 3226823 by Ben Marsh in Main branch]
2016-12-08 08:52:44 -05:00

35 lines
1.2 KiB
C++

// Copyright 1998-2017 Epic Games, Inc. All Rights Reserved.
#include "Framework/Text/TextRange.h"
void FTextRange::CalculateLineRangesFromString(const FString& Input, TArray<FTextRange>& LineRanges)
{
int32 LineBeginIndex = 0;
// Loop through splitting at new-lines
const TCHAR* const InputStart = *Input;
for(const TCHAR* CurrentChar = InputStart; CurrentChar && *CurrentChar; ++CurrentChar)
{
// Handle a chain of \r\n slightly differently to stop the FChar::IsLinebreak adding two separate new-lines
const bool bIsWindowsNewLine = (*CurrentChar == '\r' && *(CurrentChar + 1) == '\n');
if(bIsWindowsNewLine || FChar::IsLinebreak(*CurrentChar))
{
const int32 LineEndIndex = (CurrentChar - InputStart);
check(LineEndIndex >= LineBeginIndex);
LineRanges.Emplace(FTextRange(LineBeginIndex, LineEndIndex));
if(bIsWindowsNewLine)
{
++CurrentChar; // skip the \n of the \r\n chain
}
LineBeginIndex = (CurrentChar - InputStart) + 1; // The next line begins after the end of the current line
}
}
// Process any remaining string after the last new-line
if(LineBeginIndex <= Input.Len())
{
LineRanges.Emplace(FTextRange(LineBeginIndex, Input.Len()));
}
}