public int ForEachByte(IByteProcessor visitor) { var thisLength = this.length; if (0u >= (uint)thisLength) { return(IndexNotFound); } return(SpanHelpers.ForEachByte(ref this.value[this.offset], visitor, thisLength)); }
public static void IndexOfAnyStrings_Byte1(string raw, string search, char expectResult, int expectIndex) { byte[] buffers = Encoding.UTF8.GetBytes(raw); var span = new Span <byte>(buffers); char[] searchFor = search.ToCharArray(); byte[] searchForBytes = Encoding.UTF8.GetBytes(searchFor); var index = -1; if (searchFor.Length == 1) { //index = span.IndexOf((byte)searchFor[0]); index = SpanHelpers.ForEachByte(ref MemoryMarshal.GetReference(span), new ByteProcessor(x => x != (byte)searchFor[0]), span.Length); } else if (searchFor.Length == 2) { //index = span.IndexOfAny((byte)searchFor[0], (byte)searchFor[1]); index = SpanHelpers.ForEachByte(ref MemoryMarshal.GetReference(span), new ByteProcessor(x => !(x == (byte)searchFor[0] || x == (byte)searchFor[1])), span.Length); } else if (searchFor.Length == 3) { //index = span.IndexOfAny((byte)searchFor[0], (byte)searchFor[1], (byte)searchFor[2]); index = SpanHelpers.ForEachByte(ref MemoryMarshal.GetReference(span), new ByteProcessor(x => !(x == (byte)searchFor[0] || x == (byte)searchFor[1] || x == (byte)searchFor[2])), span.Length); } else { //index = span.IndexOfAny(new ReadOnlySpan<byte>(searchForBytes)); index = SpanHelpers.ForEachByte(ref MemoryMarshal.GetReference(span), new ByteProcessor(x => !searchForBytes.Contains(x)), span.Length); } var found = span[index]; Assert.Equal((byte)expectResult, found); Assert.Equal(expectIndex, index); }
public int ForEachByte(int index, int count, IByteProcessor visitor) { var thisLength = this.length; if (0u >= (uint)thisLength) { return(IndexNotFound); } if (MathUtil.IsOutOfBounds(index, count, thisLength)) { ThrowIndexOutOfRangeException_Index(index, count, thisLength); } var idx = SpanHelpers.ForEachByte(ref this.value[this.offset + index], visitor, count); if ((uint)count > (uint)idx) { return(index + idx); } return(IndexNotFound); }