• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

neon-sunset / U8String / 5868414274

pending completion
5868414274

push

github

neon-sunset
feat: consolidate CopyTo/ToArray/List logic, naming and Rune methods

105 of 704 branches covered (14.91%)

Branch coverage included in aggregate %.

46 of 46 new or added lines in 6 files covered. (100.0%)

372 of 1547 relevant lines covered (24.05%)

460.03 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/src/U8String.Indexing.cs
1
using System.Buffers;
2
using System.Text;
3

4
namespace U8Primitives;
5

6
public readonly partial struct U8String
7
{
8
    /// <summary>
9
    /// Gets a UTF-8 code unit represented as <see cref="byte"/> at the specified index.
10
    /// </summary>
11
    /// <param name="index">The index.</param>
12
    /// <exception cref="ArgumentOutOfRangeException">
13
    /// Thrown when <paramref name="index"/> is less than zero or greater than or equal to <see cref="Length"/>.
14
    /// </exception>
15
    /// <exception cref="NullReferenceException">Thrown when <see cref="Length"/> is zero.</exception>
16
    /// <returns>The <see cref="byte"/> at the specified index.</returns>
17
    /// <remarks>
18
    /// When iterating over the contents of <see cref="U8String"/>, consider using <see cref="AsSpan()"/> instead
19
    /// for best indexing performance.
20
    /// </remarks>
21
    public ref readonly byte this[int index]
22
    {
23
        // This will throw NRE on empty, there is nothing we can do about it
24
        // without sacrificing codegen quality.
25
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
26
        get => ref UnsafeSpan[index];
×
27
    }
28

29
    /// <inheritdoc cref="this[int]"/>
30
    byte IList<byte>.this[int index]
31
    {
32
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
33
        get => this[index];
×
34
        set => throw new NotImplementedException();
×
35
    }
36

37
    // TODO: Naming? Other options are ugly or long, or even more confusing.
38
    public bool IsRuneBoundary(int index)
39
    {
40
        return (uint)index < (uint)Length && !U8Info.IsContinuationByte(this[index]);
×
41
    }
42

43
    public int NextRuneIndex(int index)
44
    {
45
        var deref = this;
×
46
        if ((uint)index >= (uint)deref.Length)
×
47
        {
48
            return Length;
×
49
        }
50

51
        var span = deref.UnsafeSpan;
×
52
        while (index < span.Length && U8Info.IsContinuationByte(span[index]))
×
53
        {
54
            index++;
×
55
        }
56

57
        return index;
×
58
    }
59

60
    public bool TryGetRuneAt(int index, out Rune rune)
61
    {
62
        var deref = this;
×
63
        if ((uint)index < (uint)deref.Length)
×
64
        {
65
            return Rune.DecodeFromUtf8(
×
66
                deref.UnsafeSpan.SliceUnsafe(index),
×
67
                out rune,
×
68
                out _) is OperationStatus.Done;
×
69
        }
70

71
        rune = default;
×
72
        return false;
×
73
    }
74
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc