45 lines
1.6 KiB
C#
45 lines
1.6 KiB
C#
using System;
|
|
|
|
namespace MathInterpreter.Core;
|
|
|
|
/// <summary>
|
|
/// Result object of scan operations
|
|
/// </summary>
|
|
/// <typeparam name="T">Type of the parsed value</typeparam>
|
|
public readonly ref struct ScanResult<T> where T : struct
|
|
{
|
|
/// <summary>
|
|
/// Creates a new scan result based on a successfully parsed value - if parsing failed an Exception
|
|
/// would have been thrown and this constructor would not be called
|
|
/// </summary>
|
|
/// <param name="value">Parsed value</param>
|
|
/// <param name="length">Number of characters (digits) of the parsed value</param>
|
|
/// <param name="remainingExpression">Remaining part of the expression after extracting and parsing the value</param>
|
|
/// <exception cref="ArgumentOutOfRangeException">Thrown if an invalid argument is provided</exception>
|
|
public ScanResult(T value, int length, ReadOnlySpan<char> remainingExpression)
|
|
{
|
|
if (length < 0)
|
|
{
|
|
throw new ArgumentOutOfRangeException(nameof(length), "Length must be non-negative");
|
|
}
|
|
|
|
Value = value;
|
|
Length = length;
|
|
RemainingExpression = remainingExpression;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Gets the parsed value
|
|
/// </summary>
|
|
public T Value { get; }
|
|
|
|
/// <summary>
|
|
/// Gets the number of characters (digits) of the parsed value
|
|
/// </summary>
|
|
public int Length { get; }
|
|
|
|
/// <summary>
|
|
/// Gets the remaining part of the expression after extracting and parsing the value
|
|
/// </summary>
|
|
public ReadOnlySpan<char> RemainingExpression { get; }
|
|
}
|