// Copyright (c) 2012-2021 Wojciech Figat. All rights reserved.
using System;
namespace FlaxEngine
{
partial struct TextRange
{
///
/// Gets the range length.
///
public int Length => EndIndex - StartIndex;
///
/// Initializes a new instance of the struct.
///
/// The start index.
/// The end index.
public TextRange(int startIndex, int endIndex)
{
StartIndex = startIndex;
EndIndex = endIndex;
}
///
/// Gets a value indicating whether range is empty.
///
public bool IsEmpty => (EndIndex - StartIndex) <= 0;
///
/// Determines whether this range contains the character index.
///
/// The index.
/// true if range contains the specified character index; otherwise, false.
public bool Contains(int index) => index >= StartIndex && index < EndIndex;
///
/// Determines whether this range intersects with the other range.
///
/// The other text range.
/// true if range intersects with the specified range index;, false.
public bool Intersect(ref TextRange other) => Math.Min(EndIndex, other.EndIndex) > Math.Max(StartIndex, other.StartIndex);
///
public override string ToString()
{
return string.Format("Range: [{0}, {1}), Length: {2}", StartIndex, EndIndex, Length);
}
}
}