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

neon-sunset / U8String / 5950717515

23 Aug 2023 11:30AM UTC coverage: 23.255% (-0.8%) from 24.028%
5950717515

push

github

neon-sunset
feat: implement .Replace() variants, clean up searching overloads

154 of 856 branches covered (17.99%)

Branch coverage included in aggregate %.

86 of 86 new or added lines in 4 files covered. (100.0%)

499 of 1952 relevant lines covered (25.56%)

42232.97 hits per line

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

3.64
/src/U8String.Searching.cs
1
using System.Text;
2

3
using U8Primitives.InteropServices;
4

5
namespace U8Primitives;
6

7
public readonly partial struct U8String
8
{
9
    public bool Contains(byte value) => U8Searching.Contains(this, value);
×
10

11
    public bool Contains(char value) => U8Searching.Contains(this, value);
1,402✔
12

13
    public bool Contains(Rune value) => U8Searching.Contains(this, value);
642✔
14

15
    public bool Contains(U8String value) => U8Searching.Contains(this, value);
×
16

17
    public bool Contains(ReadOnlySpan<byte> value) => U8Searching.Contains(this, value);
×
18

19
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
20
    public bool StartsWith(byte value)
21
    {
22
        var span = AsSpan();
×
23
        return span.Length > 0 && span[0] == value;
×
24
    }
25

26
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
27
    public bool StartsWith(char value) => char.IsAscii(value)
×
28
        ? StartsWith((byte)value)
×
29
        : StartsWith(new Rune(value));
×
30

31
    public bool StartsWith(Rune value)
32
    {
33
        return AsSpan().StartsWith(U8Scalar.Create(value).AsSpan());
×
34
    }
35

36
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
37
    public bool StartsWith(U8String value) => AsSpan().StartsWith(value);
×
38

39
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
40
    public bool StartsWith(ReadOnlySpan<byte> value) => AsSpan().StartsWith(value);
×
41

42
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
43
    public bool StartsWith<T>(U8String value, T comparer)
44
        where T : IEqualityComparer<U8String>
45
    {
46
        var deref = this;
×
47
        if (deref.Length >= value.Length)
×
48
        {
49
            return U8Marshal
×
50
                .Slice(deref, 0, value.Length)
×
51
                .Equals(value, comparer);
×
52
        }
53

54
        return false;
×
55
    }
56

57
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
58
    public bool EndsWith(byte value)
59
    {
60
        var span = AsSpan();
×
61
        return span.Length > 0 && span[^1] == value;
×
62
    }
63

64
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
65
    public bool EndsWith(char value) => char.IsAscii(value)
×
66
        ? EndsWith((byte)value)
×
67
        : EndsWith(new Rune(value));
×
68

69
    public bool EndsWith(Rune value)
70
    {
71
        return AsSpan().EndsWith(U8Scalar.Create(value).AsSpan());
×
72
    }
73

74
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
75
    public bool EndsWith(U8String value) => AsSpan().EndsWith(value);
×
76

77
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
78
    public bool EndsWith(ReadOnlySpan<byte> value) => AsSpan().EndsWith(value);
×
79

80
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
81
    public bool EndsWith<T>(U8String value, T comparer)
82
        where T : IEqualityComparer<U8String>
83
    {
84
        var deref = this;
×
85
        if (deref.Length >= value.Length)
×
86
        {
87
            return U8Marshal
×
88
                .Slice(deref, deref.Length - value.Length)
×
89
                .Equals(value, comparer);
×
90
        }
91

92
        return false;
×
93
    }
94

95
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
96
    public int IndexOf(byte value) => U8Searching.IndexOf(this, value);
×
97

98
    public int IndexOf(char value) => U8Searching.IndexOf(this, value);
×
99

100
    public int IndexOf(Rune value) => U8Searching.IndexOf(this, value);
×
101

102
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
103
    public int IndexOf(U8String value) => U8Searching.IndexOf(this, value);
×
104

105
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
106
    public int IndexOf(ReadOnlySpan<byte> value) => U8Searching.IndexOf(this, value);
×
107

108
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
109
    public int LastIndexOf(byte value) => AsSpan().LastIndexOf(value);
×
110

111
    public int LastIndexOf(char value)
112
    {
113
        return AsSpan().LastIndexOf(U8Scalar.Create(value).AsSpan());
×
114
    }
115

116
    public int LastIndexOf(Rune value)
117
    {
118
        return AsSpan().LastIndexOf(U8Scalar.Create(value).AsSpan());
×
119
    }
120

121
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
122
    public int LastIndexOf(U8String value) => AsSpan().LastIndexOf(value);
×
123

124
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
125
    public int LastIndexOf(ReadOnlySpan<byte> value) => AsSpan().LastIndexOf(value);
×
126
}
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