@@ -1209,14 +1209,14 @@ static bool IsMboxMarker (byte[] buffer, int startIndex = 0, bool allowMunged =
1209
1209
1210
1210
bool StepMboxMarkerStart ( ref bool midline )
1211
1211
{
1212
- var span = input . AsSpan ( ) ;
1212
+ var span = input . AsSpan ( 0 , inputEnd + 1 ) ;
1213
1213
int index = inputIndex ;
1214
1214
1215
1215
input [ inputEnd ] = ( byte ) '\n ' ;
1216
1216
1217
1217
if ( midline ) {
1218
1218
// we're in the middle of a line, so we need to scan for the end of the line
1219
- index = span . Slice ( index ) . IndexOf ( ( byte ) ' \n ' ) + index ;
1219
+ index = span . Slice ( index ) . EndOfLine ( ) + index ;
1220
1220
1221
1221
if ( index == inputEnd ) {
1222
1222
// we don't have enough input data
@@ -1238,7 +1238,7 @@ bool StepMboxMarkerStart (ref bool midline)
1238
1238
}
1239
1239
1240
1240
// scan for the end of the line
1241
- index = span . Slice ( index ) . IndexOf ( ( byte ) ' \n ' ) + index ;
1241
+ index = span . Slice ( index ) . EndOfLine ( ) + index ;
1242
1242
1243
1243
if ( index == inputEnd ) {
1244
1244
// we don't have enough data to check for a From line
@@ -1261,7 +1261,7 @@ bool StepMboxMarker (out int count)
1261
1261
input [ inputEnd ] = ( byte ) '\n ' ;
1262
1262
1263
1263
// scan for the end of the line
1264
- count = input . AsSpan ( inputIndex ) . IndexOf ( ( byte ) ' \n ' ) ;
1264
+ count = input . AsSpan ( inputIndex , ( inputEnd + 1 ) - inputIndex ) . EndOfLine ( ) ;
1265
1265
1266
1266
int index = inputIndex + count ;
1267
1267
@@ -1435,13 +1435,14 @@ void StepHeaderField (int headerFieldLength)
1435
1435
1436
1436
bool StepHeaderValue ( ref bool midline )
1437
1437
{
1438
+ var span = input . AsSpan ( 0 , inputEnd + 1 ) ;
1438
1439
int index = inputIndex ;
1439
1440
int nread ;
1440
1441
1441
1442
input [ inputEnd ] = ( byte ) '\n ' ;
1442
1443
1443
1444
while ( index < inputEnd && ( midline || IsBlank ( input [ index ] ) ) ) {
1444
- int count = input . AsSpan ( index ) . IndexOf ( ( byte ) ' \n ' ) ;
1445
+ int count = span . Slice ( index ) . EndOfLine ( ) ;
1445
1446
1446
1447
index += count ;
1447
1448
@@ -1499,8 +1500,8 @@ bool TryCheckBoundaryWithinHeaderBlock ()
1499
1500
{
1500
1501
input [ inputEnd ] = ( byte ) '\n ' ;
1501
1502
1502
- var span = input . AsSpan ( inputIndex ) ;
1503
- int length = span . IndexOf ( ( byte ) ' \n ' ) ;
1503
+ var span = input . AsSpan ( inputIndex , ( inputEnd + 1 ) - inputIndex ) ;
1504
+ int length = span . EndOfLine ( ) ;
1504
1505
1505
1506
if ( inputIndex + length == inputEnd )
1506
1507
return false ;
@@ -1710,7 +1711,7 @@ bool InnerSkipLine (bool consumeNewLine)
1710
1711
{
1711
1712
input [ inputEnd ] = ( byte ) '\n ' ;
1712
1713
1713
- int index = input . AsSpan ( inputIndex ) . IndexOf ( ( byte ) ' \n ' ) + inputIndex ;
1714
+ int index = input . AsSpan ( inputIndex , ( inputEnd + 1 ) - inputIndex ) . EndOfLine ( ) + inputIndex ;
1714
1715
1715
1716
if ( index < inputEnd ) {
1716
1717
inputIndex = index ;
@@ -1858,8 +1859,8 @@ BoundaryType CheckBoundary ()
1858
1859
{
1859
1860
input [ inputEnd ] = ( byte ) '\n ' ;
1860
1861
1861
- var span = input . AsSpan ( inputIndex ) ;
1862
- int length = span . IndexOf ( ( byte ) ' \n ' ) ;
1862
+ var span = input . AsSpan ( inputIndex , ( inputEnd + 1 ) - inputIndex ) ;
1863
+ int length = span . EndOfLine ( ) ;
1863
1864
var line = span . Slice ( 0 , length ) ;
1864
1865
1865
1866
return CheckBoundary ( inputIndex , line ) ;
@@ -1871,8 +1872,8 @@ bool FoundImmediateBoundary (bool final)
1871
1872
1872
1873
input [ inputEnd ] = ( byte ) '\n ' ;
1873
1874
1874
- var span = input . AsSpan ( inputIndex ) ;
1875
- int length = span . IndexOf ( ( byte ) ' \n ' ) ;
1875
+ var span = input . AsSpan ( inputIndex , ( inputEnd + 1 ) - inputIndex ) ;
1876
+ int length = span . EndOfLine ( ) ;
1876
1877
var line = span . Slice ( 0 , length ) ;
1877
1878
1878
1879
return IsBoundary ( line , bounds [ 0 ] . Marker , boundaryLength ) ;
@@ -1907,6 +1908,7 @@ static bool IsMessagePart (ContentType contentType, ContentEncoding? encoding)
1907
1908
1908
1909
void ScanContent ( ref int nleft , ref bool midline , ref bool [ ] formats )
1909
1910
{
1911
+ var span = input . AsSpan ( 0 , inputEnd + 1 ) ;
1910
1912
int length = inputEnd - inputIndex ;
1911
1913
int startIndex = inputIndex ;
1912
1914
int index = inputIndex ;
@@ -1917,13 +1919,13 @@ void ScanContent (ref int nleft, ref bool midline, ref bool[] formats)
1917
1919
input [ inputEnd ] = ( byte ) '\n ' ;
1918
1920
1919
1921
while ( index < inputEnd ) {
1920
- var span = input . AsSpan ( index ) ;
1922
+ var slice = span . Slice ( index ) ;
1921
1923
1922
- length = span . IndexOf ( ( byte ) ' \n ' ) ;
1924
+ length = slice . EndOfLine ( ) ;
1923
1925
index += length ;
1924
1926
1925
1927
if ( index < inputEnd ) {
1926
- var line = span . Slice ( 0 , length ) ;
1928
+ var line = slice . Slice ( 0 , length ) ;
1927
1929
1928
1930
if ( ( boundary = CheckBoundary ( startIndex , line ) ) != BoundaryType . None )
1929
1931
break ;
@@ -1946,7 +1948,7 @@ void ScanContent (ref int nleft, ref bool midline, ref bool[] formats)
1946
1948
break ;
1947
1949
}
1948
1950
1949
- var line = span . Slice ( 0 , length ) ;
1951
+ var line = slice . Slice ( 0 , length ) ;
1950
1952
1951
1953
if ( ( boundary = CheckBoundary ( startIndex , line ) ) != BoundaryType . None )
1952
1954
break ;
0 commit comments