Skip to content
This repository was archived by the owner on Nov 20, 2018. It is now read-only.

Commit 221df71

Browse files
committed
Incorporate StringSegment from primitives
1 parent 4083c18 commit 221df71

File tree

1 file changed

+0
-146
lines changed

1 file changed

+0
-146
lines changed

src/Microsoft.AspNet.Http/ParsingHelpers.cs

Lines changed: 0 additions & 146 deletions
Original file line numberDiff line numberDiff line change
@@ -361,152 +361,6 @@ public void Reset()
361361
}
362362
}
363363

364-
[System.CodeDom.Compiler.GeneratedCode("App_Packages", "")]
365-
internal struct StringSegment : IEquatable<StringSegment>
366-
{
367-
private readonly string _buffer;
368-
private readonly int _offset;
369-
private readonly int _count;
370-
371-
// <summary>
372-
// Initializes a new instance of the <see cref="T:System.Object"/> class.
373-
// </summary>
374-
public StringSegment(string buffer, int offset, int count)
375-
{
376-
_buffer = buffer;
377-
_offset = offset;
378-
_count = count;
379-
}
380-
381-
public string Buffer
382-
{
383-
get { return _buffer; }
384-
}
385-
386-
public int Offset
387-
{
388-
get { return _offset; }
389-
}
390-
391-
public int Count
392-
{
393-
get { return _count; }
394-
}
395-
396-
public string Value
397-
{
398-
get { return _offset == -1 ? null : _buffer.Substring(_offset, _count); }
399-
}
400-
401-
public bool HasValue
402-
{
403-
get { return _offset != -1 && _count != 0 && _buffer != null; }
404-
}
405-
406-
#region Equality members
407-
408-
public bool Equals(StringSegment other)
409-
{
410-
return string.Equals(_buffer, other._buffer) && _offset == other._offset && _count == other._count;
411-
}
412-
413-
public override bool Equals(object obj)
414-
{
415-
if (ReferenceEquals(null, obj))
416-
{
417-
return false;
418-
}
419-
420-
return obj is StringSegment && Equals((StringSegment)obj);
421-
}
422-
423-
public override int GetHashCode()
424-
{
425-
unchecked
426-
{
427-
int hashCode = (_buffer != null ? _buffer.GetHashCode() : 0);
428-
hashCode = (hashCode * 397) ^ _offset;
429-
hashCode = (hashCode * 397) ^ _count;
430-
return hashCode;
431-
}
432-
}
433-
434-
public static bool operator ==(StringSegment left, StringSegment right)
435-
{
436-
return left.Equals(right);
437-
}
438-
439-
public static bool operator !=(StringSegment left, StringSegment right)
440-
{
441-
return !left.Equals(right);
442-
}
443-
444-
#endregion
445-
446-
public bool StartsWith(string text, StringComparison comparisonType)
447-
{
448-
if (text == null)
449-
{
450-
throw new ArgumentNullException(nameof(text));
451-
}
452-
453-
int textLength = text.Length;
454-
if (!HasValue || _count < textLength)
455-
{
456-
return false;
457-
}
458-
459-
return string.Compare(_buffer, _offset, text, 0, textLength, comparisonType) == 0;
460-
}
461-
462-
public bool EndsWith(string text, StringComparison comparisonType)
463-
{
464-
if (text == null)
465-
{
466-
throw new ArgumentNullException(nameof(text));
467-
}
468-
469-
int textLength = text.Length;
470-
if (!HasValue || _count < textLength)
471-
{
472-
return false;
473-
}
474-
475-
return string.Compare(_buffer, _offset + _count - textLength, text, 0, textLength, comparisonType) == 0;
476-
}
477-
478-
public bool Equals(string text, StringComparison comparisonType)
479-
{
480-
if (text == null)
481-
{
482-
throw new ArgumentNullException(nameof(text));
483-
}
484-
485-
int textLength = text.Length;
486-
if (!HasValue || _count != textLength)
487-
{
488-
return false;
489-
}
490-
491-
return string.Compare(_buffer, _offset, text, 0, textLength, comparisonType) == 0;
492-
}
493-
494-
public string Substring(int offset, int length)
495-
{
496-
return _buffer.Substring(_offset + offset, length);
497-
}
498-
499-
public StringSegment Subsegment(int offset, int length)
500-
{
501-
return new StringSegment(_buffer, _offset + offset, length);
502-
}
503-
504-
public override string ToString()
505-
{
506-
return Value ?? string.Empty;
507-
}
508-
}
509-
510364
internal static class ParsingHelpers
511365
{
512366
public static StringValues GetHeader(IDictionary<string, StringValues> headers, string key)

0 commit comments

Comments
 (0)