From 221df714258668603319e75828e9546eaa13926d Mon Sep 17 00:00:00 2001 From: Ryan Nowak Date: Thu, 8 Oct 2015 16:01:20 -0700 Subject: [PATCH] Incorporate StringSegment from primitives --- src/Microsoft.AspNet.Http/ParsingHelpers.cs | 146 -------------------- 1 file changed, 146 deletions(-) diff --git a/src/Microsoft.AspNet.Http/ParsingHelpers.cs b/src/Microsoft.AspNet.Http/ParsingHelpers.cs index ef8c526945..9f6feb3d75 100644 --- a/src/Microsoft.AspNet.Http/ParsingHelpers.cs +++ b/src/Microsoft.AspNet.Http/ParsingHelpers.cs @@ -361,152 +361,6 @@ namespace Microsoft.AspNet.Http.Internal } } - [System.CodeDom.Compiler.GeneratedCode("App_Packages", "")] - internal struct StringSegment : IEquatable - { - private readonly string _buffer; - private readonly int _offset; - private readonly int _count; - - // - // Initializes a new instance of the class. - // - public StringSegment(string buffer, int offset, int count) - { - _buffer = buffer; - _offset = offset; - _count = count; - } - - public string Buffer - { - get { return _buffer; } - } - - public int Offset - { - get { return _offset; } - } - - public int Count - { - get { return _count; } - } - - public string Value - { - get { return _offset == -1 ? null : _buffer.Substring(_offset, _count); } - } - - public bool HasValue - { - get { return _offset != -1 && _count != 0 && _buffer != null; } - } - - #region Equality members - - public bool Equals(StringSegment other) - { - return string.Equals(_buffer, other._buffer) && _offset == other._offset && _count == other._count; - } - - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) - { - return false; - } - - return obj is StringSegment && Equals((StringSegment)obj); - } - - public override int GetHashCode() - { - unchecked - { - int hashCode = (_buffer != null ? _buffer.GetHashCode() : 0); - hashCode = (hashCode * 397) ^ _offset; - hashCode = (hashCode * 397) ^ _count; - return hashCode; - } - } - - public static bool operator ==(StringSegment left, StringSegment right) - { - return left.Equals(right); - } - - public static bool operator !=(StringSegment left, StringSegment right) - { - return !left.Equals(right); - } - - #endregion - - public bool StartsWith(string text, StringComparison comparisonType) - { - if (text == null) - { - throw new ArgumentNullException(nameof(text)); - } - - int textLength = text.Length; - if (!HasValue || _count < textLength) - { - return false; - } - - return string.Compare(_buffer, _offset, text, 0, textLength, comparisonType) == 0; - } - - public bool EndsWith(string text, StringComparison comparisonType) - { - if (text == null) - { - throw new ArgumentNullException(nameof(text)); - } - - int textLength = text.Length; - if (!HasValue || _count < textLength) - { - return false; - } - - return string.Compare(_buffer, _offset + _count - textLength, text, 0, textLength, comparisonType) == 0; - } - - public bool Equals(string text, StringComparison comparisonType) - { - if (text == null) - { - throw new ArgumentNullException(nameof(text)); - } - - int textLength = text.Length; - if (!HasValue || _count != textLength) - { - return false; - } - - return string.Compare(_buffer, _offset, text, 0, textLength, comparisonType) == 0; - } - - public string Substring(int offset, int length) - { - return _buffer.Substring(_offset + offset, length); - } - - public StringSegment Subsegment(int offset, int length) - { - return new StringSegment(_buffer, _offset + offset, length); - } - - public override string ToString() - { - return Value ?? string.Empty; - } - } - internal static class ParsingHelpers { public static StringValues GetHeader(IDictionary headers, string key)