Files
UnrealEngineUWP/Engine/Source/Runtime/Slate/Private/Framework/Text/TextRange.cpp
Matthew Griffin bb70b349ce Merging CL 2804086 from //UE4/Release-4.11 to Dev-Main (//UE4/Dev-Main) to isolate copyright update
#lockdown Nick.Penwarden

[CL 2819020 by Matthew Griffin in Main branch]
2016-01-07 08:17:16 -05:00

36 lines
1.2 KiB
C++

// Copyright 1998-2016 Epic Games, Inc. All Rights Reserved.
#include "SlatePrivatePCH.h"
#include "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()));
}
}