static ICharSequence CommaSeparateEscapedValues(ICharSequence currentValue, ICharSequence value) { var builder = new StringBuilderCharSequence(currentValue.Count + 1 + value.Count); builder.Append(currentValue); builder.Append(Comma); builder.Append(value); return(builder); }
static ICharSequence CommaSeparate(IEnumerable <ICharSequence> values) { StringBuilderCharSequence sb = values is ICollection collection ? new StringBuilderCharSequence(collection.Count * ValueLengthEstimate) : new StringBuilderCharSequence(); foreach (ICharSequence value in values) { if (sb.Count > 0) { sb.Append(Comma); } sb.Append(EscapeCsv(value)); } return(sb); }
ICharSequence CommaSeparate(IEnumerable <object> values) { StringBuilderCharSequence sb = values is ICollection collection ? new StringBuilderCharSequence(collection.Count * ValueLengthEstimate) : new StringBuilderCharSequence(); foreach (object value in values) { if (sb.Count > 0) { sb.Append(Comma); } sb.Append(EscapeCsv(this.ValueConverter.ConvertObject(value))); } return(sb); }
/// <inheritdoc /> protected internal override void EncodeInitialLine(IByteBuffer buf, IHttpRequest request) { ByteBufferUtil.Copy(request.Method.AsciiName, buf); string uri = request.Uri; if (string.IsNullOrEmpty(uri)) { // Add / as absolute path if no is present. // See http://tools.ietf.org/html/rfc2616#section-5.1.2 _ = buf.WriteMedium(SpaceSlashAndSpaceMedium); } else { var uriCharSequence = new StringBuilderCharSequence(); uriCharSequence.Append(uri); bool needSlash = false; int start = uri.IndexOf("://", StringComparison.Ordinal); if (start != -1 && uri[0] != Slash) { start += 3; // Correctly handle query params. // See https://github.com/netty/netty/issues/2732 int index = uri.IndexOf(QuestionMark, start); if (index == -1) { if (uri.LastIndexOf(Slash) < start) { needSlash = true; } } else { if (uri.LastIndexOf(Slash, index) < start) { uriCharSequence.Insert(index, Slash); } } } _ = buf.WriteByte(HorizontalSpace).WriteCharSequence(uriCharSequence, Encoding.UTF8); if (needSlash) { // write "/ " after uri _ = buf.WriteShort(SlashAndSpaceShort); } else { _ = buf.WriteByte(HorizontalSpace); } } request.ProtocolVersion.Encode(buf); _ = buf.WriteShort(CrlfShort); }
static void DoCaseSensitivity(int len) { // Build an upper case and lower case string const int UpperA = 'A'; const int UpperZ = 'Z'; const int UpperToLower = (int)'a' - UpperA; var lowerCaseBytes = new byte[len]; var upperCaseBuilder = new StringBuilderCharSequence(len); for (int i = 0; i < len; ++i) { char upper = (char)(Rand.Next((UpperZ - UpperA) + 1) + UpperA); upperCaseBuilder.Append(upper); lowerCaseBytes[i] = (byte)(upper + UpperToLower); } var upperCaseString = (StringCharSequence)upperCaseBuilder.ToString(); var lowerCaseString = (StringCharSequence) new string(lowerCaseBytes.Select(x => (char)x).ToArray()); var lowerCaseAscii = new AsciiString(lowerCaseBytes, false); var upperCaseAscii = new AsciiString(upperCaseString); // Test upper case hash codes are equal int upperCaseExpected = upperCaseAscii.GetHashCode(); Assert.Equal(upperCaseExpected, AsciiString.GetHashCode(upperCaseBuilder)); Assert.Equal(upperCaseExpected, AsciiString.GetHashCode(upperCaseString)); Assert.Equal(upperCaseExpected, upperCaseAscii.GetHashCode()); // Test lower case hash codes are equal int lowerCaseExpected = lowerCaseAscii.GetHashCode(); Assert.Equal(lowerCaseExpected, AsciiString.GetHashCode(lowerCaseAscii)); Assert.Equal(lowerCaseExpected, AsciiString.GetHashCode(lowerCaseString)); Assert.Equal(lowerCaseExpected, lowerCaseAscii.GetHashCode()); // Test case insensitive hash codes are equal int expectedCaseInsensitive = lowerCaseAscii.GetHashCode(); Assert.Equal(expectedCaseInsensitive, AsciiString.GetHashCode(upperCaseBuilder)); Assert.Equal(expectedCaseInsensitive, AsciiString.GetHashCode(upperCaseString)); Assert.Equal(expectedCaseInsensitive, AsciiString.GetHashCode(lowerCaseString)); Assert.Equal(expectedCaseInsensitive, AsciiString.GetHashCode(lowerCaseAscii)); Assert.Equal(expectedCaseInsensitive, AsciiString.GetHashCode(upperCaseAscii)); Assert.Equal(expectedCaseInsensitive, lowerCaseAscii.GetHashCode()); Assert.Equal(expectedCaseInsensitive, upperCaseAscii.GetHashCode()); // Test that opposite cases are equal Assert.Equal(lowerCaseAscii.GetHashCode(), AsciiString.GetHashCode(upperCaseString)); Assert.Equal(upperCaseAscii.GetHashCode(), AsciiString.GetHashCode(lowerCaseString)); }