/*
Copyright (C) 2014-2019 de4dot@gmail.com
This file is part of dnSpy
dnSpy is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
dnSpy is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with dnSpy. If not, see .
*/
using System;
namespace dnSpy.Contracts.Debugger.DotNet.Code {
///
/// Text span
///
public readonly struct DbgTextSpan : IEquatable {
readonly int start, end;
///
/// Start offset
///
public int Start => start;
///
/// End offset, exclusive
///
public int End => end;
///
/// Length ( - )
///
public int Length => end - start;
///
/// true if it's empty ( is 0)
///
public bool IsEmpty => end == start;
///
/// Constructor
///
/// Start offset
/// Length
public DbgTextSpan(int start, int length) {
if (start < 0)
throw new ArgumentOutOfRangeException(nameof(start));
this.start = start;
end = start + length;
if (end < start)
throw new ArgumentOutOfRangeException(nameof(length));
}
///
/// Creates a new instance
///
/// Start offset
/// End offset
///
public static DbgTextSpan FromBounds(int start, int end) => new DbgTextSpan(start, end - start);
///
/// operator ==()
///
///
///
///
public static bool operator ==(DbgTextSpan left, DbgTextSpan right) => left.Equals(right);
///
/// operator !=()
///
///
///
///
public static bool operator !=(DbgTextSpan left, DbgTextSpan right) => !left.Equals(right);
///
/// Equals()
///
///
///
public bool Equals(DbgTextSpan other) => start == other.start && end == other.end;
///
/// Equals()
///
///
///
public override bool Equals(object? obj) => obj is DbgTextSpan && Equals((DbgTextSpan)obj);
///
/// GetHashCode()
///
///
public override int GetHashCode() => start ^ ((end << 16) | (end >> 16));
///
/// ToString()
///
///
public override string ToString() => "[" + start.ToString() + "," + end.ToString() + ")";
}
}