public void StartsWithCodeUnit(string s, char c) { Utf8String u8s = new Utf8String(s); byte codeUnit = (byte)c; Assert.Equal(s.StartsWith(c.ToString()), u8s.StartsWith(codeUnit)); }
public void StartsWithUtf8String(string s, string pattern) { Utf8String u8s = new Utf8String(s); Utf8String u8pattern = new Utf8String(pattern); Assert.Equal(s.StartsWith(pattern), u8s.StartsWith(u8pattern)); }
public static void Searching_StandaloneSurrogate_Fails() { Utf8String utf8String = u8("\ud800\udfff"); Assert.False(utf8String.Contains('\ud800')); Assert.False(utf8String.Contains('\udfff')); Assert.Equal(-1, utf8String.IndexOf('\ud800')); Assert.Equal(-1, utf8String.IndexOf('\udfff')); Assert.False(utf8String.StartsWith('\ud800')); Assert.False(utf8String.StartsWith('\udfff')); Assert.False(utf8String.EndsWith('\ud800')); Assert.False(utf8String.EndsWith('\udfff')); }
public static void StartsWith_And_EndsWith_CharRune_Ordinal(Utf8String utf8String, Rune searchValue, int expectedIndex) { // StartsWith if (searchValue.IsBmp) { Assert.Equal(expectedIndex == 0, utf8String.StartsWith((char)searchValue.Value)); } Assert.Equal(expectedIndex == 0, utf8String.StartsWith(searchValue)); // EndsWith bool endsWithExpectedValue = (expectedIndex >= 0) && (expectedIndex + searchValue.Utf8SequenceLength) == utf8String.Length; if (searchValue.IsBmp) { Assert.Equal(endsWithExpectedValue, utf8String.EndsWith((char)searchValue.Value)); } Assert.Equal(endsWithExpectedValue, utf8String.EndsWith(searchValue)); }
internal static bool TryParseMethod(ReadOnlySpan <byte> buffer, out HttpMethod method, out int parsedBytes) { var bufferString = new Utf8String(buffer); if (bufferString.StartsWith(s_Get)) { method = HttpMethod.Get; parsedBytes = s_Get.Length; return(true); } if (bufferString.StartsWith(s_Post)) { method = HttpMethod.Post; parsedBytes = s_Post.Length; return(true); } if (bufferString.StartsWith(s_Put)) { method = HttpMethod.Put; parsedBytes = s_Put.Length; return(true); } if (bufferString.StartsWith(s_Delete)) { method = HttpMethod.Delete; parsedBytes = s_Delete.Length; return(true); } method = HttpMethod.Unknown; parsedBytes = 0; return(false); }
internal static bool TryParseMethod(ReadOnlySpan<byte> buffer, out HttpMethod method, out int parsedBytes) { var bufferString = new Utf8String(buffer); if(bufferString.StartsWith(s_Get)) { method = HttpMethod.Get; parsedBytes = s_Get.Length; return true; } if (bufferString.StartsWith(s_Post)) { method = HttpMethod.Post; parsedBytes = s_Post.Length; return true; } if (bufferString.StartsWith(s_Put)) { method = HttpMethod.Put; parsedBytes = s_Put.Length; return true; } if (bufferString.StartsWith(s_Delete)) { method = HttpMethod.Delete; parsedBytes = s_Delete.Length; return true; } method = HttpMethod.Unknown; parsedBytes = 0; return false; }
public void StartsWithCodeUnit(string s, char c) { Utf8String u8s = new Utf8String(s); Utf8CodeUnit codeUnit = (Utf8CodeUnit)(byte)c; Assert.Equal(s.StartsWith(c.ToString()), u8s.StartsWith(codeUnit)); }