This commit is contained in:
MarcUs7i 2025-05-10 22:58:56 +02:00
parent e487452b18
commit 0e72a5eb05
9 changed files with 146 additions and 57 deletions

View file

@ -8,9 +8,8 @@ namespace Numbers.NumberString;
/// <inheritdoc cref="IEnumerator{T}"/>
public sealed class DigitEnumerator : IEnumerator<int>
{
// TODO
// private readonly string _text;
// private int _index;
private readonly string _text;
private int _index;
/// <summary>
/// Creates a new instance of <see cref="DigitEnumerator"/> based on the given text.
@ -19,35 +18,42 @@ public sealed class DigitEnumerator : IEnumerator<int>
/// <param name="text">The text to iterate over (containing both letters and digits)</param>
public DigitEnumerator(string text)
{
// TODO
_text = text;
_index = -1;
}
public bool MoveNext()
{
// TODO
while (++_index < _text.Length)
{
if (char.IsDigit(_text[_index]))
{
return true;
}
}
return false;
}
public void Reset()
{
// TODO
_index = -1;
}
public int Current
{
get
{
// TODO
return -1;
//static int GetDigit(char c) => c - '0';
if (_index < 0 || _index >= _text.Length || !char.IsDigit(_text[_index]))
{
return -1;
}
return GetDigit(_text[_index]);
static int GetDigit(char c) => c - '0';
}
}
object IEnumerator.Current => null!; // TODO
object IEnumerator.Current => Current;
public void Dispose()
{
// TODO?
}
public void Dispose() { }
}