1 write to _ps
System.Private.Xml (1)
System\Xml\Core\XmlTextReaderImpl.cs (1)
8160
_ps
= _parsingStatesStack[_parsingStatesStackTop--];
1705 references to _ps
System.Private.Xml (1705)
System\Xml\Core\XmlTextReaderImpl.cs (1053)
352
_ps
.lineNo = 1;
353
_ps
.lineStartPos = -1;
414
_ps
.lineNo = _lineNumberOffset + 1;
415
_ps
.lineStartPos = -_linePositionOffset - 1;
416
_curNode.SetLineInfo(
_ps
.LineNo - 1,
_ps
.LinePos - 1);
476
_reportedBaseUri =
_ps
.baseUriStr;
477
_reportedEncoding =
_ps
.encoding;
500
_reportedEncoding =
_ps
.encoding;
523
_reportedBaseUri =
_ps
.baseUriStr;
524
_reportedEncoding =
_ps
.encoding;
545
_reportedEncoding =
_ps
.encoding;
576
_ps
.baseUri = GetTempResolver().ResolveUri(null, url);
577
_ps
.baseUriStr =
_ps
.baseUri.ToString();
578
_reportedBaseUri =
_ps
.baseUriStr;
664
_reportedEncoding =
_ps
.encoding;
744
_reportedEncoding =
_ps
.encoding;
797
_reportedEncoding =
_ps
.encoding;
815
_reportedBaseUri =
_ps
.baseUriStr;
816
_reportedEncoding =
_ps
.encoding;
1238
Debug.Assert(!
_ps
.appendMode);
1247
_reportedEncoding =
_ps
.encoding;
1250
_reportedEncoding =
_ps
.encoding;
1287
_reportedEncoding =
_ps
.encoding;
1288
_reportedBaseUri =
_ps
.baseUriStr;
1294
_curNode.SetLineInfo(
_ps
.lineNo,
_ps
.LinePos);
1295
_reportedEncoding =
_ps
.encoding;
1296
_reportedBaseUri =
_ps
.baseUriStr;
1468
_attributeValueBaseEntityId =
_ps
.entityId;
1473
if (
_ps
.entityId == _attributeValueBaseEntityId)
1509
if (
_ps
.charsUsed -
_ps
.charPos == 0)
1530
if (
_ps
.charsUsed -
_ps
.charPos == 0 && !
_ps
.entity!.IsExternal)
1548
_ps
.entityResolvedManually = true;
1868
Debug.Assert(
_ps
.chars != null);
1869
BlockCopyChars(
_ps
.chars, startPos, buffer, (index + readCount), copyCount);
1892
Debug.Assert(
_ps
.chars != null);
1893
_curNode.SetValue(
_ps
.chars, startPos, endPos - startPos);
2021
if (
_ps
.entity == null ||
_ps
.entity.IsExternal)
2023
_ps
.eolNormalized = !value;
2112
_ps
.baseUri = null;
2179
_stringBuilder.Append(
_ps
.chars, _incReadLeftStartPos, _incReadLeftEndPos - _incReadLeftStartPos);
2189
_ps
.appendMode = false;
2192
_stringBuilder.Append(
_ps
.chars,
_ps
.charPos,
_ps
.charsUsed -
_ps
.charPos);
2193
_ps
.charPos =
_ps
.charsUsed;
2364
if (
_ps
.baseUriStr.Length > 0 &&
_ps
.baseUri == null && _xmlResolver != null)
2366
_ps
.baseUri = _xmlResolver.ResolveUri(null,
_ps
.baseUriStr);
2369
return
_ps
.baseUri;
2377
return
_ps
.isEof;
2385
return
_ps
.chars;
2393
return
_ps
.charsUsed;
2401
return
_ps
.charPos;
2405
Debug.Assert(value >= 0 && value <=
_ps
.charsUsed);
2406
_ps
.charPos = value;
2422
return
_ps
.eolNormalized;
2447
return
_ps
.LineNo;
2455
return
_ps
.lineStartPos;
2515
if (e.ResString == SR.Xml_UnexpectedEOF &&
_ps
.entity != null)
2517
SendValidationEvent(XmlSeverityType.Error, SR.Sch_ParEntityRefNesting, null,
_ps
.LineNo,
_ps
.LinePos);
2556
entityId =
_ps
.entityId;
2569
oldEntity =
_ps
.entity;
2571
newEntityId =
_ps
.entityId;
2589
if (
_ps
.baseUri == null && !string.IsNullOrEmpty(
_ps
.baseUriStr))
2591
_ps
.baseUri = _xmlResolver.ResolveUri(null,
_ps
.baseUriStr);
2594
PushExternalEntityOrSubset(publicId, systemId,
_ps
.baseUri, null);
2596
_ps
.entity = null;
2597
_ps
.entityId = 0;
2599
Debug.Assert(
_ps
.appendMode);
2600
int initialPos =
_ps
.charPos;
2607
_ps
.charPos = initialPos;
2623
_ps
.entity = null;
2624
_ps
.entityId = 0;
2625
_ps
.eolNormalized = false;
2656
_ps
.charPos = pos;
2663
_ps
.charPos = pos;
2670
_ps
.charPos = pos;
2683
Throw(new XmlException(res, string.Empty, lineNo, linePos,
_ps
.baseUriStr));
2689
Throw(new XmlException(res, arg,
_ps
.LineNo,
_ps
.LinePos,
_ps
.baseUriStr));
2695
Throw(new XmlException(res, arg, lineNo, linePos,
_ps
.baseUriStr));
2701
Throw(new XmlException(res, args,
_ps
.LineNo,
_ps
.LinePos,
_ps
.baseUriStr));
2713
Throw(new XmlException(res, args, innerException,
_ps
.LineNo,
_ps
.LinePos,
_ps
.baseUriStr));
2733
Throw(new XmlException(e.Message, (Exception?)null, lineNo, linePos,
_ps
.baseUriStr));
2739
Throw(new XmlException(res, string.Empty,
_ps
.baseUriStr));
2745
Throw(new XmlException(res, arg,
_ps
.baseUriStr));
2751
Throw(new XmlException(res, args, innerException, 0, 0,
_ps
.baseUriStr));
2768
SendValidationEvent(severity, new XmlSchemaException(code, arg,
_ps
.baseUriStr, lineNo, linePos));
2801
while (
_ps
.entityId != _attributeValueBaseEntityId)
2843
Debug.Assert(
_ps
.charPos == 0 &&
_ps
.charsUsed == 0 &&
_ps
.textReader == null);
2847
_ps
.stream = stream;
2848
_ps
.baseUri = baseUri;
2849
_ps
.baseUriStr = baseUriStr;
2855
_ps
.bytes = bytes;
2856
_ps
.bytesUsed = byteCount;
2857
bufferSize =
_ps
.bytes.Length;
2870
if (
_ps
.bytes == null ||
_ps
.bytes.Length < bufferSize)
2872
_ps
.bytes = new byte[bufferSize];
2877
if (
_ps
.chars == null ||
_ps
.chars.Length < bufferSize + 1)
2879
_ps
.chars = new char[bufferSize + 1];
2883
_ps
.bytePos = 0;
2884
if (
_ps
.bytesUsed < 4 &&
_ps
.bytes.Length -
_ps
.bytesUsed > 0)
2886
int bytesToRead = Math.Min(4,
_ps
.bytes.Length -
_ps
.bytesUsed);
2887
int read = stream.ReadAtLeast(
_ps
.bytes.AsSpan(
_ps
.bytesUsed), bytesToRead, throwOnEndOfStream: false);
2890
_ps
.isStreamEof = true;
2892
_ps
.bytesUsed += read;
2902
_documentStartBytePos =
_ps
.bytePos;
2904
_ps
.eolNormalized = !_normalize;
2907
_ps
.appendMode = true;
2918
Debug.Assert(
_ps
.charPos == 0 &&
_ps
.charsUsed == 0 &&
_ps
.stream == null);
2921
_ps
.textReader = input;
2922
_ps
.baseUriStr = baseUriStr;
2923
_ps
.baseUri = baseUri;
2925
if (
_ps
.chars == null)
2929
_ps
.chars = new char[XmlReader.AsyncBufferSize + 1];
2933
_ps
.chars = new char[XmlReader.DefaultBufferSize + 1];
2937
_ps
.encoding = Encoding.Unicode;
2938
_ps
.eolNormalized = !_normalize;
2941
_ps
.appendMode = true;
2947
Debug.Assert(
_ps
.stream == null &&
_ps
.textReader == null);
2948
Debug.Assert(
_ps
.charPos == 0 &&
_ps
.charsUsed == 0);
2952
_ps
.baseUriStr = baseUriStr;
2953
_ps
.baseUri = null;
2956
_ps
.chars = new char[len + 1];
2957
str.CopyTo(0,
_ps
.chars, 0, str.Length);
2958
_ps
.charsUsed = len;
2959
_ps
.chars[len] = (char)0;
2961
_ps
.encoding = originalEncoding;
2963
_ps
.eolNormalized = !_normalize;
2964
_ps
.isEof = true;
2983
_ps
.baseUriStr = parserContext.BaseURI;
2984
_ps
.baseUri = null;
2991
_ps
.baseUriStr = string.Empty;
2992
_ps
.baseUri = null;
2995
_reportedBaseUri =
_ps
.baseUriStr;
3000
_ps
.appendMode = false;
3015
_ps
.appendMode = false;
3061
if (
_ps
.baseUri == null)
3063
_ps
.baseUri = tmpResolver.ResolveUri(null, _url);
3064
_ps
.baseUriStr =
_ps
.baseUri.ToString();
3069
_ps
.stream = (Stream?)tmpResolver.GetEntity(
_ps
.baseUri, null, typeof(Stream));
3077
if (
_ps
.stream == null)
3079
ThrowWithoutLineInfo(SR.Xml_CannotResolveUrl,
_ps
.baseUriStr);
3082
Debug.Assert(
_ps
.stream != null);
3083
InitStreamInput(
_ps
.baseUri,
_ps
.baseUriStr,
_ps
.stream, null);
3084
_reportedEncoding =
_ps
.encoding;
3090
Debug.Assert(
_ps
.bytes != null);
3091
Debug.Assert(
_ps
.bytePos == 0);
3093
if (
_ps
.bytesUsed < 2)
3098
int first2Bytes =
_ps
.bytes[0] << 8 |
_ps
.bytes[1];
3099
int next2Bytes = (
_ps
.bytesUsed >= 4) ? (
_ps
.bytes[2] << 8 |
_ps
.bytes[3]) : 0;
3177
Debug.Assert(
_ps
.charPos == 0);
3178
_ps
.encoding = Encoding.UTF8;
3179
_ps
.decoder = new SafeAsciiDecoder();
3183
_ps
.encoding = encoding;
3184
_ps
.decoder =
_ps
.encoding.WebName switch // Encoding.Codepage is not supported in Silverlight
3195
Debug.Assert(
_ps
.encoding != null);
3196
Debug.Assert(
_ps
.bytes != null);
3197
ReadOnlySpan<byte> preamble =
_ps
.encoding.Preamble;
3198
if (
_ps
.bytes.AsSpan(0,
_ps
.bytesUsed).StartsWith(preamble))
3200
_ps
.bytePos = preamble.Length;
3207
Debug.Assert(
_ps
.encoding != null);
3208
if ((newEncoding.WebName !=
_ps
.encoding.WebName ||
_ps
.decoder is SafeAsciiDecoder) && !_afterResetState)
3210
Debug.Assert(
_ps
.stream != null);
3212
_ps
.appendMode = false;
3222
Debug.Assert(
_ps
.encoding != null);
3225
if (
_ps
.stream == null)
3227
return
_ps
.encoding;
3235
if (
_ps
.encoding.WebName != "utf-16BE" &&
3236
_ps
.encoding.WebName != "utf-16" &&
3248
return
_ps
.encoding;
3276
if (_afterResetState &&
_ps
.encoding.WebName != newEncoding.WebName)
3286
Debug.Assert(
_ps
.stream != null &&
_ps
.decoder != null &&
_ps
.bytes != null);
3287
Debug.Assert(
_ps
.appendMode, "UnDecodeChars cannot be called after ps.appendMode has been changed to false");
3289
Debug.Assert(
_ps
.charsUsed >=
_ps
.charPos, "The current position must be in the valid character range.");
3297
Debug.Assert(_charactersInDocument >=
_ps
.charsUsed -
_ps
.charPos,
3299
_charactersInDocument -=
_ps
.charsUsed -
_ps
.charPos;
3306
Debug.Assert(_charactersFromEntities >=
_ps
.charsUsed -
_ps
.charPos,
3308
_charactersFromEntities -=
_ps
.charsUsed -
_ps
.charPos;
3312
_ps
.bytePos = _documentStartBytePos; // byte position after preamble
3313
if (
_ps
.charPos > 0)
3315
Debug.Assert(
_ps
.encoding != null);
3316
Debug.Assert(
_ps
.chars != null);
3317
if (
_ps
.decoder is SafeAsciiDecoder)
3324
_ps
.bytePos +=
_ps
.charPos;
3325
int encodingByteCount =
_ps
.encoding.GetByteCount(
_ps
.chars, 0,
_ps
.charPos);
3326
if (encodingByteCount !=
_ps
.charPos)
3333
_ps
.bytePos +=
_ps
.encoding.GetByteCount(
_ps
.chars, 0,
_ps
.charPos);
3337
_ps
.charsUsed =
_ps
.charPos;
3338
_ps
.isEof = false;
3354
if (
_ps
.isEof)
3359
Debug.Assert(
_ps
.chars != null);
3361
if (
_ps
.appendMode)
3364
if (
_ps
.charsUsed ==
_ps
.chars.Length - 1)
3387
char[] newChars = new char[
_ps
.chars.Length * 2];
3388
BlockCopyChars(
_ps
.chars, 0, newChars, 0,
_ps
.chars.Length);
3389
_ps
.chars = newChars;
3392
if (
_ps
.stream != null)
3395
if (
_ps
.bytesUsed -
_ps
.bytePos < MaxByteSequenceLen)
3397
Debug.Assert(
_ps
.bytes != null);
3398
if (
_ps
.bytes.Length -
_ps
.bytesUsed < MaxByteSequenceLen)
3400
byte[] newBytes = new byte[
_ps
.bytes.Length * 2];
3401
BlockCopy(
_ps
.bytes, 0, newBytes, 0,
_ps
.bytesUsed);
3402
_ps
.bytes = newBytes;
3407
charsRead =
_ps
.chars.Length -
_ps
.charsUsed - 1;
3415
int charsLen =
_ps
.chars.Length;
3416
if (charsLen -
_ps
.charsUsed <= charsLen / 2)
3440
int copyCharsCount =
_ps
.charsUsed -
_ps
.charPos;
3443
_ps
.lineStartPos -=
_ps
.charPos;
3446
BlockCopyChars(
_ps
.chars,
_ps
.charPos,
_ps
.chars, 0, copyCharsCount);
3448
_ps
.charPos = 0;
3449
_ps
.charsUsed = copyCharsCount;
3453
char[] newChars = new char[
_ps
.chars.Length * 2];
3454
BlockCopyChars(
_ps
.chars, 0, newChars, 0,
_ps
.chars.Length);
3455
_ps
.chars = newChars;
3459
if (
_ps
.stream != null)
3462
int bytesLeft =
_ps
.bytesUsed -
_ps
.bytePos;
3467
_ps
.bytesUsed = 0;
3471
Debug.Assert(
_ps
.bytes != null);
3472
BlockCopy(
_ps
.bytes,
_ps
.bytePos,
_ps
.bytes, 0, bytesLeft);
3473
_ps
.bytesUsed = bytesLeft;
3476
_ps
.bytePos = 0;
3479
charsRead =
_ps
.chars.Length -
_ps
.charsUsed - 1;
3482
if (
_ps
.stream != null)
3484
if (!
_ps
.isStreamEof)
3486
Debug.Assert(
_ps
.bytes != null);
3489
if (
_ps
.bytePos ==
_ps
.bytesUsed &&
_ps
.bytes.Length -
_ps
.bytesUsed > 0)
3491
int read =
_ps
.stream.Read(
_ps
.bytes,
_ps
.bytesUsed,
_ps
.bytes.Length -
_ps
.bytesUsed);
3494
_ps
.isStreamEof = true;
3496
_ps
.bytesUsed += read;
3500
int originalBytePos =
_ps
.bytePos;
3504
if (charsRead == 0 &&
_ps
.bytePos != originalBytePos)
3510
else if (
_ps
.textReader != null)
3513
charsRead =
_ps
.textReader.Read(
_ps
.chars,
_ps
.charsUsed,
_ps
.chars.Length -
_ps
.charsUsed - 1);
3514
_ps
.charsUsed += charsRead;
3525
Debug.Assert(
_ps
.charsUsed <
_ps
.chars.Length);
3526
_ps
.isEof = true;
3529
_ps
.chars[
_ps
.charsUsed] = (char)0;
3536
Debug.Assert(
_ps
.stream != null &&
_ps
.decoder != null &&
_ps
.bytes != null);
3537
Debug.Assert(
_ps
.chars != null);
3538
Debug.Assert(maxCharsCount <=
_ps
.chars.Length -
_ps
.charsUsed - 1);
3541
int bytesCount =
_ps
.bytesUsed -
_ps
.bytePos;
3552
_ps
.decoder.Convert(
_ps
.bytes,
_ps
.bytePos, bytesCount,
_ps
.chars,
_ps
.charsUsed, maxCharsCount, false, out bytesCount, out charsCount, out completed);
3560
_ps
.bytePos += bytesCount;
3561
_ps
.charsUsed += charsCount;
3577
Debug.Assert(
_ps
.decoder != null);
3578
Debug.Assert(
_ps
.bytes != null);
3579
Debug.Assert(
_ps
.chars != null);
3580
_ps
.decoder.Convert(
_ps
.bytes,
_ps
.bytePos + bytesDecoded, 1,
_ps
.chars,
_ps
.charsUsed + charsDecoded, 2, false, out bDec, out chDec, out completed);
3593
Throw(
_ps
.charsUsed, SR.Xml_InvalidCharInThisEncoding);
3612
_ps
.Close(closeInput);
3627
Debug.Assert(
_ps
.chars != null);
3628
BlockCopyChars(
_ps
.chars, sourcePos,
_ps
.chars, destPos, count);
3634
while (
_ps
.charsUsed -
_ps
.charPos < 6)
3642
if (!
_ps
.chars.AsSpan(
_ps
.charPos).StartsWith(XmlDeclarationBeginning) ||
3643
XmlCharType.IsNameSingleChar(
_ps
.chars![
_ps
.charPos + 5]))
3650
_curNode.SetLineInfo(
_ps
.LineNo,
_ps
.LinePos + 2);
3654
_ps
.charPos += 5;
3670
if (
_ps
.chars[
_ps
.charPos] == '?')
3674
if (
_ps
.chars[
_ps
.charPos + 1] == '>')
3681
_ps
.charPos += 2;
3701
Debug.Assert(
_ps
.encoding != null);
3702
string encodingName =
_ps
.encoding.WebName;
3704
encodingName != "utf-16BE" && !(
_ps
.encoding is Ucs4Encoding))
3706
Throw(SR.Xml_EncodingSwitchAfterResetState, (
_ps
.encoding.GetByteCount("A") == 1) ? "UTF-8" : "UTF-16");
3709
if (
_ps
.decoder is SafeAsciiDecoder)
3718
_ps
.appendMode = false;
3721
else if (
_ps
.charPos + 1 ==
_ps
.charsUsed)
3740
switch (
_ps
.chars.AsSpan(
_ps
.charPos, nameEndPos -
_ps
.charPos))
3779
attr.SetLineInfo(
_ps
.LineNo,
_ps
.LinePos);
3781
sb.Append(
_ps
.chars,
_ps
.charPos, nameEndPos -
_ps
.charPos);
3782
_ps
.charPos = nameEndPos;
3785
if (
_ps
.chars[
_ps
.charPos] != '=')
3788
if (
_ps
.chars[
_ps
.charPos] != '=')
3794
_ps
.charPos++;
3796
char quoteChar =
_ps
.chars[
_ps
.charPos];
3800
quoteChar =
_ps
.chars[
_ps
.charPos];
3807
_ps
.charPos++;
3812
attr.SetLineInfo2(
_ps
.LineNo,
_ps
.LinePos);
3816
int pos =
_ps
.charPos;
3819
chars =
_ps
.chars;
3825
if (
_ps
.chars[pos] == quoteChar)
3832
if (
_ps
.chars.AsSpan(
_ps
.charPos).StartsWith("1.0"))
3837
attr.SetValue(
_ps
.chars,
_ps
.charPos, pos -
_ps
.charPos);
3843
string badVersion = new string(
_ps
.chars,
_ps
.charPos, pos -
_ps
.charPos);
3848
string encName = new string(
_ps
.chars,
_ps
.charPos, pos -
_ps
.charPos);
3858
switch (
_ps
.chars.AsSpan(
_ps
.charPos, pos -
_ps
.charPos))
3868
Throw(SR.Xml_InvalidXmlDecl,
_ps
.LineNo,
_ps
.LinePos - 1);
3874
attr.SetValue(
_ps
.chars,
_ps
.charPos, pos -
_ps
.charPos);
3882
sb.Append(chars,
_ps
.charPos, pos -
_ps
.charPos);
3884
_ps
.charPos = pos + 1;
3887
else if (pos ==
_ps
.charsUsed)
3904
if (
_ps
.isEof || ReadData() == 0)
3919
Debug.Assert(
_ps
.encoding != null);
3920
string encodingName =
_ps
.encoding.WebName;
3922
encodingName != "utf-16BE" && !(
_ps
.encoding is Ucs4Encoding))
3924
Throw(SR.Xml_EncodingSwitchAfterResetState, (
_ps
.encoding.GetByteCount("A") == 1) ? "UTF-8" : "UTF-16");
3927
if (
_ps
.decoder is SafeAsciiDecoder)
3931
_ps
.appendMode = false;
3942
int pos =
_ps
.charPos;
3943
Debug.Assert(
_ps
.chars != null);
3944
char[] chars =
_ps
.chars;
3950
if (
_ps
.charsUsed - pos < 4) // minimum "<a/>"
3957
_ps
.charPos = pos + 1;
3965
if (
_ps
.charsUsed - pos < 2) // minimum characters expected "--"
3972
_ps
.charPos = pos + 2;
3990
if (
_ps
.charsUsed - pos < 6)
3996
_ps
.charPos = pos + 6;
4011
Throw(
_ps
.charPos, SR.Xml_InvalidRootData);
4020
_ps
.charPos = pos;
4056
_ps
.charPos = pos;
4097
else if (pos ==
_ps
.charsUsed || ((_v1Compat || mangoQuirks) && chars[pos] == 0x0))
4125
Debug.Assert(pos ==
_ps
.charsUsed && !
_ps
.isEof);
4167
int pos =
_ps
.charPos;
4168
Debug.Assert(
_ps
.chars != null);
4169
char[] chars =
_ps
.chars;
4179
_ps
.charPos = pos + 2;
4187
if (
_ps
.charsUsed - pos < 2)
4194
_ps
.charPos = pos + 2;
4210
if (
_ps
.charsUsed - pos < 6)
4216
_ps
.charPos = pos + 6;
4239
_ps
.charPos = pos + 2;
4244
if (pos + 1 ==
_ps
.charsUsed)
4251
_ps
.charPos = pos + 1;
4265
if (pos ==
_ps
.charsUsed)
4284
if (
_ps
.charsUsed -
_ps
.charPos != 0)
4310
Throw(
_ps
.charsUsed, SR.Xml_UnexpectedEOF1);
4334
Throw(
_ps
.charsUsed, SR.Xml_UnexpectedEOFInElementContent, _stringBuilder.ToString());
4341
int pos =
_ps
.charPos;
4342
Debug.Assert(
_ps
.chars != null);
4343
char[] chars =
_ps
.chars;
4346
_curNode.SetLineInfo(
_ps
.LineNo,
_ps
.LinePos);
4397
else if (pos + 1 <
_ps
.charsUsed)
4404
chars =
_ps
.chars;
4415
_nameTable.Add(chars,
_ps
.charPos, pos -
_ps
.charPos));
4419
int startPos =
_ps
.charPos;
4432
_nameTable.Add(chars,
_ps
.charPos, prefixLen),
4443
_ps
.charPos = pos;
4453
_ps
.charPos = pos + 1;
4459
if (pos + 1 ==
_ps
.charsUsed)
4461
_ps
.charPos = pos;
4466
pos =
_ps
.charPos;
4467
chars =
_ps
.chars;
4474
_ps
.charPos = pos + 2;
4484
Throw(pos, SR.Xml_BadNameChar, XmlException.BuildCharExceptionArgs(chars,
_ps
.charsUsed, pos));
4584
while (
_ps
.charsUsed -
_ps
.charPos < prefLen + locLen + 1)
4593
Debug.Assert(
_ps
.chars != null);
4594
char[] chars =
_ps
.chars;
4597
if (!chars.AsSpan(
_ps
.charPos).StartsWith(startTagNode.localName))
4605
int colonPos =
_ps
.charPos + prefLen;
4606
if (!chars.AsSpan(
_ps
.charPos).StartsWith(startTagNode.prefix) ||
4615
LineInfo endTagLineInfo = new LineInfo(
_ps
.lineNo,
_ps
.LinePos);
4620
pos =
_ps
.charPos + nameLen;
4621
chars =
_ps
.chars;
4623
if (pos ==
_ps
.charsUsed)
4650
else if (pos ==
_ps
.charsUsed && !
_ps
.isEof)
4664
else if (pos ==
_ps
.charsUsed)
4690
_ps
.charPos = pos + 1;
4704
Debug.Assert(
_ps
.chars != null);
4709
args[3] = new string(
_ps
.chars,
_ps
.charPos, endPos -
_ps
.charPos);
4722
int pos =
_ps
.charPos;
4723
Debug.Assert(
_ps
.chars != null);
4724
char[] chars =
_ps
.chars;
4749
else if (pos + 1 !=
_ps
.charsUsed)
4756
_ps
.charPos = pos;
4777
_ps
.charPos = pos + 1;
4785
if (pos + 1 ==
_ps
.charsUsed)
4791
_ps
.charPos = pos + 2;
4802
else if (pos ==
_ps
.charsUsed)
4808
Throw(pos, SR.Xml_BadStartNameChar, XmlException.BuildCharExceptionArgs(chars,
_ps
.charsUsed, pos));
4812
if (pos ==
_ps
.charPos)
4816
_ps
.charPos = pos;
4819
int attrNameLinePos =
_ps
.LinePos;
4875
chars =
_ps
.chars;
4878
else if (pos + 1 >=
_ps
.charsUsed)
4881
chars =
_ps
.chars;
4885
attr.SetLineInfo(
_ps
.LineNo, attrNameLinePos);
4894
_ps
.charPos = pos;
4896
pos =
_ps
.charPos;
4907
_ps
.charPos = pos;
4909
pos =
_ps
.charPos;
4917
_ps
.charPos = pos;
4920
attr.SetLineInfo2(
_ps
.LineNo,
_ps
.LinePos);
4938
attr.SetValue(chars,
_ps
.charPos, pos -
_ps
.charPos);
4940
_ps
.charPos = pos;
4945
pos =
_ps
.charPos;
4946
chars =
_ps
.chars;
4974
_ps
.lineNo -= lineNoDelta;
4977
pos =
_ps
.charPos;
4978
chars =
_ps
.chars;
5137
Debug.Assert(
_ps
.chars != null);
5138
char[] chars =
_ps
.chars;
5139
int attributeBaseEntityId =
_ps
.entityId;
5141
LineInfo valueChunkLineInfo = new LineInfo(
_ps
.lineNo,
_ps
.LinePos);
5154
if (pos -
_ps
.charPos > 0)
5156
_stringBuilder.Append(chars,
_ps
.charPos, pos -
_ps
.charPos);
5157
_ps
.charPos = pos;
5160
if (chars[pos] == quoteChar && attributeBaseEntityId ==
_ps
.entityId)
5175
_ps
.charPos++;
5184
_stringBuilder.Append(
_ps
.eolNormalized ? "\u0020\u0020" : "\u0020"); // CDATA normalization of 0xD 0xA
5185
_ps
.charPos = pos;
5188
else if (pos + 1 <
_ps
.charsUsed ||
_ps
.isEof)
5194
_ps
.charPos = pos;
5209
_ps
.charPos++;
5223
if (pos -
_ps
.charPos > 0)
5225
_stringBuilder.Append(chars,
_ps
.charPos, pos -
_ps
.charPos);
5227
_ps
.charPos = pos;
5229
int enclosingEntityId =
_ps
.entityId;
5230
LineInfo entityLineInfo = new LineInfo(
_ps
.lineNo,
_ps
.LinePos + 1);
5238
if (_parsingMode == ParsingMode.Full &&
_ps
.entityId == attributeBaseEntityId)
5252
_ps
.charPos++;
5269
valueChunkLineInfo.Set(
_ps
.LineNo,
_ps
.LinePos);
5275
_ps
.charPos++;
5278
pos =
_ps
.charPos;
5299
Debug.Assert(
_ps
.entity != null);
5300
entityChunk.SetNamedNode(XmlNodeType.EntityReference,
_ps
.entity.Name);
5308
pos =
_ps
.charPos;
5311
pos =
_ps
.charPos;
5314
chars =
_ps
.chars;
5318
if (pos ==
_ps
.charsUsed)
5328
if (pos + 1 ==
_ps
.charsUsed)
5339
ThrowInvalidChar(chars,
_ps
.charsUsed, pos);
5349
if (
_ps
.charsUsed -
_ps
.charPos > 0)
5351
if (
_ps
.chars[
_ps
.charPos] != (char)0xD)
5356
Debug.Assert(
_ps
.isEof);
5364
if (attributeBaseEntityId !=
_ps
.entityId)
5378
if (attributeBaseEntityId ==
_ps
.entityId)
5381
valueChunkLineInfo.Set(
_ps
.LineNo,
_ps
.LinePos);
5386
pos =
_ps
.charPos;
5387
chars =
_ps
.chars;
5404
_ps
.charPos = pos + 1;
5442
_curNode.SetLineInfo(
_ps
.LineNo,
_ps
.LinePos);
5460
Debug.Assert(
_ps
.chars != null);
5461
_curNode.SetValueNode(nodeType,
_ps
.chars, startPos, endPos - startPos);
5474
_stringBuilder.Append(
_ps
.chars, startPos, endPos - startPos);
5480
_stringBuilder.Append(
_ps
.chars, startPos, endPos - startPos);
5505
Debug.Assert(
_ps
.chars != null);
5506
_curNode.SetValueNode(XmlNodeType.Text,
_ps
.chars, startPos, endPos - startPos);
5515
_stringBuilder.Append(
_ps
.chars, startPos, endPos - startPos);
5522
_stringBuilder.Append(
_ps
.chars, startPos, endPos - startPos);
5580
Debug.Assert(
_ps
.chars != null);
5581
char[] chars =
_ps
.chars;
5582
int pos =
_ps
.charPos;
5610
if (!
_ps
.eolNormalized && _parsingMode == ParsingMode.Full)
5612
if (pos -
_ps
.charPos > 0)
5628
_ps
.charPos++;
5633
else if (pos + 1 <
_ps
.charsUsed ||
_ps
.isEof)
5635
if (!
_ps
.eolNormalized)
5673
if (pos >
_ps
.charPos)
5694
if (!XmlCharType.IsWhiteSpace(
_ps
.chars[pos - 1]))
5700
pos =
_ps
.charPos;
5703
chars =
_ps
.chars;
5707
if (
_ps
.charsUsed - pos < 3 && !
_ps
.isEof)
5720
if (pos ==
_ps
.charsUsed)
5730
if (pos + 1 ==
_ps
.charsUsed)
5742
int offset = pos -
_ps
.charPos;
5745
pos =
_ps
.charPos + offset;
5750
ThrowInvalidChar(
_ps
.chars,
_ps
.charsUsed,
_ps
.charPos + offset);
5757
if (pos >
_ps
.charPos)
5764
if (
_ps
.charsUsed -
_ps
.charPos > 0)
5766
if (
_ps
.chars[
_ps
.charPos] != (char)0xD &&
_ps
.chars[
_ps
.charPos] != ']')
5770
Debug.Assert(
_ps
.isEof);
5789
pos =
_ps
.charPos;
5790
chars =
_ps
.chars;
5802
startPos =
_ps
.charPos;
5804
_ps
.charPos = pos;
5823
_stringBuilder.Append(
_ps
.chars, startPos, endPos - startPos);
5825
_stringBuilder.Append(
_ps
.chars, startPos, endPos - startPos);
5945
Debug.Assert(
_ps
.chars != null);
5949
if (
_ps
.chars[
_ps
.charPos] == '<' ||
_ps
.charsUsed -
_ps
.charPos == 0 || ZeroEndingStream(
_ps
.charPos))
5956
_curNode.SetLineInfo(
_ps
.LineNo,
_ps
.LinePos);
5958
if (
_ps
.chars[
_ps
.charPos] == '<' ||
_ps
.charsUsed -
_ps
.charPos == 0 || ZeroEndingStream(
_ps
.charPos))
5970
if (XmlCharType.IsCharData(
_ps
.chars[
_ps
.charPos]))
5976
ThrowInvalidChar(
_ps
.chars,
_ps
.charsUsed,
_ps
.charPos);
5983
Debug.Assert(
_ps
.chars != null);
5984
Debug.Assert(
_ps
.chars[
_ps
.charPos] == '&');
5985
_ps
.charPos++;
5987
_curNode.SetLineInfo(
_ps
.LineNo,
_ps
.LinePos);
5993
Debug.Assert(
_ps
.chars != null);
5994
Debug.Assert(
_ps
.chars[
_ps
.charPos] == '&');
5996
if (
_ps
.charPos + 1 ==
_ps
.charsUsed)
6005
if (
_ps
.chars[
_ps
.charPos + 1] == '#')
6033
_ps
.charPos++;
6034
int savedLinePos =
_ps
.LinePos;
6041
Throw(SR.Xml_ErrorParsingEntityName,
_ps
.LineNo, savedLinePos);
6046
if (
_ps
.chars[endPos] != ';')
6051
int entityLinePos =
_ps
.LinePos;
6052
string entityName = _nameTable.Add(
_ps
.chars,
_ps
.charPos, endPos -
_ps
.charPos);
6053
_ps
.charPos = endPos + 1;
6057
_reportedBaseUri =
_ps
.baseUriStr;
6058
_reportedEncoding =
_ps
.encoding;
6084
Throw(SR.Xml_UndeclaredEntity, name,
_ps
.LineNo, entityStartLinePos);
6098
Throw(SR.Xml_UnparsedEntityRef, name,
_ps
.LineNo, entityStartLinePos);
6103
Throw(SR.Xml_ExternalEntityInStandAloneDocument, entity.Name,
_ps
.LineNo, entityStartLinePos);
6110
Throw(SR.Xml_ExternalEntityInAttValue, name,
_ps
.LineNo, entityStartLinePos);
6124
_curNode.entityId =
_ps
.entityId;
6132
_curNode.entityId =
_ps
.entityId;
6145
_curNode.entityId =
_ps
.entityId;
6167
if (
_ps
.entityResolvedManually)
6173
if (
_ps
.entityId != _nodes[_index].entityId)
6179
_lastEntity =
_ps
.entity; // save last entity for the EndEntity node
6188
if (
_ps
.entityId != _nodes[_index].entityId)
6196
_reportedEncoding =
_ps
.encoding;
6197
_reportedBaseUri =
_ps
.baseUriStr;
6206
_reportedEncoding =
_ps
.encoding;
6207
_reportedBaseUri =
_ps
.baseUriStr;
6212
_curNode.lineInfo.Set(
_ps
.lineNo,
_ps
.LinePos - 1);
6241
_curNode.SetLineInfo(
_ps
.LineNo,
_ps
.LinePos);
6248
Debug.Assert(
_ps
.chars != null);
6249
string target = _nameTable.Add(
_ps
.chars,
_ps
.charPos, nameEndPos -
_ps
.charPos);
6255
_ps
.charPos = nameEndPos;
6270
char ch =
_ps
.chars[
_ps
.charPos];
6271
Debug.Assert(
_ps
.charPos <
_ps
.charsUsed);
6274
if (
_ps
.charsUsed -
_ps
.charPos < 2)
6278
if (ch != '?' ||
_ps
.chars[
_ps
.charPos + 1] != '>')
6280
Throw(SR.Xml_BadNameChar, XmlException.BuildCharExceptionArgs(
_ps
.chars,
_ps
.charsUsed,
_ps
.charPos));
6296
_curNode.SetValue(
_ps
.chars, startPos, endPos - startPos);
6301
piInDtdStringBuilder.Append(
_ps
.chars, startPos, endPos - startPos);
6324
sb.Append(
_ps
.chars, startPos, endPos - startPos);
6326
sb.Append(
_ps
.chars, startPos, endPos - startPos);
6341
if (
_ps
.charsUsed -
_ps
.charPos < 2)
6345
Throw(
_ps
.charsUsed, SR.Xml_UnexpectedEOF, "PI");
6349
Debug.Assert(
_ps
.chars != null);
6350
int pos =
_ps
.charPos;
6351
char[] chars =
_ps
.chars;
6371
Debug.Assert(!
_ps
.eolNormalized);
6379
outStartPos =
_ps
.charPos;
6380
_ps
.charPos = pos + 2;
6383
else if (pos + 1 ==
_ps
.charsUsed)
6400
if (!
_ps
.eolNormalized && _parsingMode == ParsingMode.Full)
6403
if (pos -
_ps
.charPos > 0)
6419
_ps
.charPos++;
6424
else if (pos + 1 <
_ps
.charsUsed ||
_ps
.isEof)
6426
if (!
_ps
.eolNormalized)
6446
if (pos ==
_ps
.charsUsed)
6456
if (pos + 1 ==
_ps
.charsUsed)
6467
ThrowInvalidChar(chars,
_ps
.charsUsed, pos);
6483
outStartPos =
_ps
.charPos;
6484
_ps
.charPos = pos;
6517
_curNode.SetLineInfo(
_ps
.LineNo,
_ps
.LinePos);
6521
Debug.Assert(
_ps
.chars != null);
6522
_curNode.SetValueNode(type,
_ps
.chars, startPos, endPos - startPos);
6528
_stringBuilder.Append(
_ps
.chars, startPos, endPos - startPos);
6531
_stringBuilder.Append(
_ps
.chars, startPos, endPos - startPos);
6545
if (
_ps
.charsUsed -
_ps
.charPos < 3)
6554
Debug.Assert(
_ps
.chars != null);
6555
int pos =
_ps
.charPos;
6556
char[] chars =
_ps
.chars;
6578
Debug.Assert(!
_ps
.eolNormalized);
6586
outStartPos =
_ps
.charPos;
6587
_ps
.charPos = pos + 3;
6590
else if (pos + 2 ==
_ps
.charsUsed)
6599
else if (pos + 1 ==
_ps
.charsUsed)
6619
if (!
_ps
.eolNormalized && _parsingMode == ParsingMode.Full)
6621
if (pos -
_ps
.charPos > 0)
6637
_ps
.charPos++;
6642
else if (pos + 1 <
_ps
.charsUsed ||
_ps
.isEof)
6644
if (!
_ps
.eolNormalized)
6664
if (pos ==
_ps
.charsUsed)
6672
if (pos + 1 ==
_ps
.charsUsed)
6683
ThrowInvalidChar(chars,
_ps
.charsUsed, pos);
6698
outStartPos =
_ps
.charPos;
6700
_ps
.charPos = pos;
6714
while (
_ps
.charsUsed -
_ps
.charPos < 8)
6722
if (!
_ps
.chars.AsSpan(
_ps
.charPos).StartsWith("DOCTYPE"))
6727
Debug.Assert(
_ps
.chars != null);
6728
if (!XmlCharType.IsWhiteSpace(
_ps
.chars[
_ps
.charPos + 7]))
6730
ThrowExpectingWhitespace(
_ps
.charPos + 7);
6735
Throw(
_ps
.charPos - 2, SR.Xml_MultipleDTDsProvided); // position just before <!DOCTYPE
6740
Throw(
_ps
.charPos - 2, SR.Xml_DtdAfterRootElement);
6743
_ps
.charPos += 8;
6749
_curNode.SetLineInfo(
_ps
.LineNo,
_ps
.LinePos);
6786
_ps
.charPos = pos;
6792
Debug.Assert(
_ps
.chars != null);
6793
if (
_ps
.chars[
_ps
.charPos] == 'P')
6796
while (
_ps
.charsUsed -
_ps
.charPos < 6)
6804
if (!
_ps
.chars.AsSpan(
_ps
.charPos).StartsWith("PUBLIC"))
6808
_ps
.charPos += 6;
6813
ThrowExpectingWhitespace(
_ps
.charPos);
6822
ThrowExpectingWhitespace(
_ps
.charPos);
6830
else if (
_ps
.chars[
_ps
.charPos] == 'S')
6833
while (
_ps
.charsUsed -
_ps
.charPos < 6)
6841
if (!
_ps
.chars.AsSpan(
_ps
.charPos).StartsWith("SYSTEM"))
6845
_ps
.charPos += 6;
6850
ThrowExpectingWhitespace(
_ps
.charPos);
6858
else if (
_ps
.chars[
_ps
.charPos] != '[' &&
_ps
.chars[
_ps
.charPos] != '>')
6864
if (
_ps
.chars[
_ps
.charPos] == '[')
6866
_ps
.charPos++;
6871
if (
_ps
.chars[
_ps
.charPos] != '>')
6876
else if (
_ps
.chars[
_ps
.charPos] == '>')
6884
_ps
.charPos++;
6889
Debug.Assert(
_ps
.chars != null);
6891
char quoteChar =
_ps
.chars[
_ps
.charPos];
6897
_ps
.charPos++;
6908
Debug.Assert(
_ps
.chars != null);
6909
char[] chars =
_ps
.chars;
6910
int pos =
_ps
.charPos;
6924
_ps
.charPos = pos + 1;
6929
_ps
.charPos = pos;
6942
else if (pos + 1 <
_ps
.charsUsed ||
_ps
.isEof)
6968
if (pos + 3 >=
_ps
.charsUsed && !
_ps
.isEof)
6983
else if (pos + 1 >=
_ps
.charsUsed && !
_ps
.isEof)
6993
if (pos + 2 >=
_ps
.charsUsed && !
_ps
.isEof)
7011
if (pos + 1 >=
_ps
.charsUsed && !
_ps
.isEof)
7052
if (pos ==
_ps
.charsUsed)
7062
if (pos + 1 ==
_ps
.charsUsed)
7073
ThrowInvalidChar(chars,
_ps
.charsUsed, pos);
7082
if (
_ps
.charsUsed -
_ps
.charPos > 0)
7084
if (
_ps
.chars[
_ps
.charPos] != (char)0xD)
7089
Debug.Assert(
_ps
.isEof);
7096
chars =
_ps
.chars;
7097
pos =
_ps
.charPos;
7103
int pos =
_ps
.charPos;
7105
Debug.Assert(
_ps
.chars != null);
7106
char[] chars =
_ps
.chars;
7121
int tmp1 = pos -
_ps
.charPos;
7122
if (sb != null && !
_ps
.eolNormalized)
7126
sb.Append(chars,
_ps
.charPos, tmp1);
7129
_ps
.charPos = pos + 1;
7133
else if (pos + 1 <
_ps
.charsUsed ||
_ps
.isEof)
7135
if (!
_ps
.eolNormalized)
7152
if (pos ==
_ps
.charsUsed)
7158
int tmp2 = pos -
_ps
.charPos;
7161
sb?.Append(
_ps
.chars,
_ps
.charPos, tmp2);
7162
_ps
.charPos = pos;
7171
int tmp3 = pos -
_ps
.charPos;
7174
sb?.Append(
_ps
.chars,
_ps
.charPos, tmp3);
7175
_ps
.charPos = pos;
7181
if (
_ps
.charsUsed -
_ps
.charPos == 0)
7185
if (
_ps
.chars[
_ps
.charPos] != (char)0xD)
7190
Debug.Assert(
_ps
.isEof);
7192
pos =
_ps
.charPos;
7193
chars =
_ps
.chars;
7199
Debug.Assert(
_ps
.chars != null);
7200
Debug.Assert(
_ps
.chars[startPos] == '&');
7201
if (
_ps
.chars[startPos + 1] == '#')
7224
switch (newPos = ParseNumericCharRefInline(
_ps
.charPos, expand, internalSubsetBuilder, out charCount, out entityType))
7233
Debug.Assert(
_ps
.chars != null);
7234
Debug.Assert(
_ps
.chars[
_ps
.charPos] == '&');
7239
_ps
.charPos = newPos - charCount;
7254
Debug.Assert(
_ps
.chars != null);
7255
Debug.Assert(
_ps
.chars[startPos] == '&' &&
_ps
.chars[startPos + 1] == '#');
7263
chars =
_ps
.chars;
7285
else if (pos <
_ps
.charsUsed)
7305
_ps
.charPos = pos;
7314
if (pos ==
_ps
.charsUsed)
7332
Throw((
_ps
.chars[startPos + 2] == 'x') ? startPos + 3 : startPos + 2, SR.Xml_InvalidCharacter, XmlException.BuildCharExceptionArgs(ch, '\0'));
7337
internalSubsetBuilder?.Append(
_ps
.chars,
_ps
.charPos, pos -
_ps
.charPos + 1);
7358
Throw((
_ps
.chars[startPos + 2] == 'x') ? startPos + 3 : startPos + 2, SR.Xml_InvalidCharacter, XmlException.BuildCharExceptionArgs(high, low));
7365
internalSubsetBuilder?.Append(
_ps
.chars,
_ps
.charPos, pos -
_ps
.charPos + 1);
7385
switch (newPos = ParseNamedCharRefInline(
_ps
.charPos, expand, internalSubsetBuilder))
7396
Debug.Assert(
_ps
.chars != null);
7397
Debug.Assert(
_ps
.chars[
_ps
.charPos] == '&');
7402
_ps
.charPos = newPos - 1;
7417
Debug.Assert(startPos <
_ps
.charsUsed);
7418
Debug.Assert(
_ps
.chars != null);
7419
Debug.Assert(
_ps
.chars[startPos] == '&');
7420
Debug.Assert(
_ps
.chars[startPos + 1] != '#');
7423
char[] chars =
_ps
.chars;
7434
if (
_ps
.charsUsed - pos >= 3)
7451
if (
_ps
.charsUsed - pos >= 4)
7466
else if (pos <
_ps
.charsUsed)
7473
if (
_ps
.charsUsed - pos >= 5)
7490
if (
_ps
.charsUsed - pos >= 3)
7506
if (
_ps
.charsUsed - pos >= 3)
7531
internalSubsetBuilder?.Append(
_ps
.chars,
_ps
.charPos, pos -
_ps
.charPos);
7532
_ps
.chars[pos - 1] = ch;
7550
int pos =
_ps
.charPos + startOffset;
7553
Debug.Assert(
_ps
.chars != null);
7554
char[] chars =
_ps
.chars;
7563
if (pos + 1 >=
_ps
.charsUsed)
7573
Throw(pos, SR.Xml_BadStartNameChar, XmlException.BuildCharExceptionArgs(chars,
_ps
.charsUsed, pos));
7600
colonOffset = pos -
_ps
.charPos;
7606
colonOffset = pos -
_ps
.charPos;
7612
else if (pos ==
_ps
.charsUsed)
7616
Debug.Assert(
_ps
.chars != null);
7617
chars =
_ps
.chars;
7624
colonPos = (colonOffset == -1) ? -1 :
_ps
.charPos + colonOffset;
7630
int offset = pos -
_ps
.charPos;
7632
pos =
_ps
.charPos + offset;
7649
Debug.Assert(
_ps
.chars != null);
7652
if (
_ps
.chars[endPos] != ';')
7657
string entityName = _nameTable.Add(
_ps
.chars,
_ps
.charPos, endPos -
_ps
.charPos);
7658
_ps
.charPos = endPos + 1;
7702
Debug.Assert(
_ps
.chars != null);
7707
string localName = _nameTable.Add(
_ps
.chars,
_ps
.charPos, endNamePos -
_ps
.charPos);
7713
int startPos =
_ps
.charPos;
7715
if (prefixLen == _lastPrefix.Length &&
_ps
.chars.AsSpan(
_ps
.charPos).StartsWith(_lastPrefix))
7717
return AddAttribute(_nameTable.Add(
_ps
.chars, colonPos + 1, endNamePos - colonPos - 1),
7723
string prefix = _nameTable.Add(
_ps
.chars, startPos, prefixLen);
7725
return AddAttribute(_nameTable.Add(
_ps
.chars, colonPos + 1, endNamePos - colonPos - 1),
7784
_ps
.lineNo++;
7785
_ps
.lineStartPos = pos - 1;
7790
Debug.Assert(
_ps
.isEof);
7793
_curNode.SetLineInfo(
_ps
.LineNo,
_ps
.LinePos);
8044
Debug.Assert(
_ps
.appendMode);
8045
int initialPos =
_ps
.charPos;
8053
_ps
.charPos = initialPos;
8060
Encoding? enc =
_ps
.encoding;
8077
Encoding? enc =
_ps
.encoding;
8085
_ps
.lineNo = entity.LineNumber;
8086
_ps
.lineStartPos = -entity.LinePosition - 1;
8088
_ps
.eolNormalized = true;
8095
_ps
.stream?.Dispose();
8099
_curNode.entityId =
_ps
.entityId;
8115
_ps
.entity = entity;
8116
_ps
.entityId = _nextEntityId++;
8130
if (
_ps
.entity != null)
8132
_currentEntities!.Remove(
_ps
.entity);
8150
_parsingStatesStack[_parsingStatesStackTop] =
_ps
;
8152
_ps
.Clear();
8159
_ps
.Close(true);
8171
_incReadLeftStartPos =
_ps
.charPos;
8172
_incReadLeftEndPos =
_ps
.charPos;
8173
_incReadLineInfo.Set(
_ps
.LineNo,
_ps
.LinePos);
8216
Debug.Assert(
_ps
.chars != null);
8226
count = _incReadDecoder.Decode(
_ps
.chars, _incReadLeftStartPos, charsLeft);
8265
Debug.Assert(
_ps
.chars.AsSpan(
_ps
.charPos - 2).StartsWith("?>"));
8266
_ps
.charPos -= 2;
8273
Debug.Assert(
_ps
.chars.AsSpan(
_ps
.charPos - 3).StartsWith("-->"));
8274
_ps
.charPos -= 3;
8281
Debug.Assert(
_ps
.chars.AsSpan(
_ps
.charPos - 3).StartsWith("]]>"));
8282
_ps
.charPos -= 3;
8310
char[] chars =
_ps
.chars;
8311
startPos =
_ps
.charPos;
8316
_incReadLineInfo.Set(
_ps
.LineNo,
_ps
.LinePos);
8357
else if (pos + 1 <
_ps
.charsUsed)
8374
if (
_ps
.charsUsed - pos < 2)
8387
if (
_ps
.charsUsed - pos < 4)
8397
if (
_ps
.charsUsed - pos < 9)
8415
Debug.Assert(
_ps
.charPos - pos == 0);
8416
Debug.Assert(
_ps
.charPos - startPos == 0);
8421
if ((endPos -
_ps
.charPos - 2) == checkName.Length && chars.AsSpan(
_ps
.charPos + 2).StartsWith(checkName) &&
8422
(
_ps
.chars[endPos] == '>' || XmlCharType.IsWhiteSpace(
_ps
.chars[endPos])))
8430
_ps
.charPos = endPos;
8431
if (XmlCharType.IsWhiteSpace(
_ps
.chars[endPos]))
8435
if (
_ps
.chars[
_ps
.charPos] != '>')
8439
_ps
.charPos++;
8447
startPos =
_ps
.charPos;
8448
chars =
_ps
.chars;
8455
Debug.Assert(
_ps
.charPos - pos == 0);
8456
Debug.Assert(
_ps
.charPos - startPos == 0);
8460
if (endPos -
_ps
.charPos - 1 == _curNode.localName.Length &&
_ps
.chars.AsSpan(
_ps
.charPos + 1).StartsWith(_curNode.localName) &&
8461
(
_ps
.chars[endPos] == '>' ||
_ps
.chars[endPos] == '/' || XmlCharType.IsWhiteSpace(
_ps
.chars[endPos])))
8469
startPos =
_ps
.charPos;
8470
chars =
_ps
.chars;
8479
if (
_ps
.charsUsed - pos < 2)
8518
if (pos ==
_ps
.charsUsed)
8535
_ps
.charPos = pos;
8545
count = _incReadDecoder.Decode(
_ps
.chars, startPos, charsParsed);
8583
ParseAttributeValueSlow(
_ps
.charPos, ' ', _curNode); // The quote char is intentionally empty (space) because we need to parse ' and " into the attribute value
8606
Debug.Assert(
_ps
.chars != null);
8608
char[] chars =
_ps
.chars;
8609
int pos =
_ps
.charPos;
8612
_curNode.SetLineInfo(
_ps
.LineNo,
_ps
.LinePos);
8632
Debug.Assert(
_ps
.eolNormalized, "Entity replacement text for attribute values should be EOL-normalized!");
8655
if (pos -
_ps
.charPos > 0)
8657
_stringBuilder.Append(chars,
_ps
.charPos, pos -
_ps
.charPos);
8660
_ps
.charPos = pos;
8668
chars =
_ps
.chars;
8669
if (_normalize && XmlCharType.IsWhiteSpace(chars[
_ps
.charPos]) && pos -
_ps
.charPos == 1)
8671
chars[
_ps
.charPos] = (char)0x20; // CDATA normalization of character references in entities
8678
_ps
.charPos++;
8690
chars =
_ps
.chars;
8694
if (pos ==
_ps
.charsUsed)
8704
if (pos + 1 ==
_ps
.charsUsed)
8717
ThrowInvalidChar(chars,
_ps
.charsUsed, pos);
8723
if (pos -
_ps
.charPos > 0)
8725
_stringBuilder.Append(chars,
_ps
.charPos, pos -
_ps
.charPos);
8726
_ps
.charPos = pos;
8750
pos =
_ps
.charPos;
8751
chars =
_ps
.chars;
8755
if (pos -
_ps
.charPos > 0)
8757
_stringBuilder.Append(chars,
_ps
.charPos, pos -
_ps
.charPos);
8758
_ps
.charPos = pos;
8790
_ps
.charPos = pos;
8814
_ps
.charPos = pos;
8820
if (
_ps
.charPos ==
_ps
.charsUsed)
8825
Debug.Assert(
_ps
.chars != null);
8827
if (XmlCharType.IsNCNameSingleChar(
_ps
.chars[
_ps
.charPos]))
8829
int pos =
_ps
.charPos + 1;
8830
while (XmlCharType.IsNCNameSingleChar(
_ps
.chars[pos]))
8834
return new string(
_ps
.chars,
_ps
.charPos, pos -
_ps
.charPos);
8838
Debug.Assert(
_ps
.charPos <
_ps
.charsUsed);
8839
return new string(
_ps
.chars,
_ps
.charPos, 1);
8903
Debug.Assert(
_ps
.chars != null);
8905
if (_v1Compat && pos ==
_ps
.charsUsed - 1 &&
_ps
.chars[pos] == (char)0 && ReadData() == 0 &&
_ps
.isStreamEof)
8907
_ps
.charsUsed--;
9413
_curNode.AdjustLineInfo(_readValueOffset,
_ps
.eolNormalized, ref _incReadLineInfo);
9427
Debug.Assert(
_ps
.chars != null);
9438
_incReadLineInfo.Set(
_ps
.LineNo,
_ps
.LinePos);
9443
charsRead = _incReadDecoder.Decode(
_ps
.chars, startPos, endPos - startPos);
9458
_curNode.SetValue(
_ps
.chars, startPos, endPos - startPos);
9460
AdjustLineInfo(
_ps
.chars, startPos - charsRead, startPos,
_ps
.eolNormalized, ref _incReadLineInfo);
System\Xml\Core\XmlTextReaderImplAsync.cs (652)
97
_reportedEncoding =
_ps
.encoding;
128
_reportedEncoding =
_ps
.encoding;
143
_reportedEncoding =
_ps
.encoding;
178
Debug.Assert(!
_ps
.appendMode);
219
_reportedEncoding =
_ps
.encoding;
220
_reportedBaseUri =
_ps
.baseUriStr;
226
_curNode.SetLineInfo(
_ps
.lineNo,
_ps
.LinePos);
227
_reportedEncoding =
_ps
.encoding;
228
_reportedBaseUri =
_ps
.baseUriStr;
295
_reportedEncoding =
_ps
.encoding;
300
_reportedEncoding =
_ps
.encoding;
695
BlockCopyChars(
_ps
.chars, startPos, buffer, (index + readCount), copyCount);
718
_curNode.SetValue(
_ps
.chars, startPos, endPos - startPos);
786
if (e.ResString == SR.Xml_UnexpectedEOF &&
_ps
.entity != null)
788
SendValidationEvent(XmlSeverityType.Error, SR.Sch_ParEntityRefNesting, null,
_ps
.LineNo,
_ps
.LinePos);
818
entityId =
_ps
.entityId;
837
if (
_ps
.baseUri == null && !string.IsNullOrEmpty(
_ps
.baseUriStr))
839
_ps
.baseUri = _xmlResolver!.ResolveUri(null,
_ps
.baseUriStr);
841
await PushExternalEntityOrSubsetAsync(publicId, systemId,
_ps
.baseUri, null).ConfigureAwait(false);
843
_ps
.entity = null;
844
_ps
.entityId = 0;
846
Debug.Assert(
_ps
.appendMode);
847
int initialPos =
_ps
.charPos;
854
_ps
.charPos = initialPos;
868
Debug.Assert(
_ps
.charPos == 0 &&
_ps
.charsUsed == 0 &&
_ps
.textReader == null);
872
_ps
.stream = stream;
873
_ps
.baseUri = baseUri;
874
_ps
.baseUriStr = baseUriStr;
880
_ps
.bytes = bytes;
881
_ps
.bytesUsed = byteCount;
882
bufferSize =
_ps
.bytes.Length;
897
if (
_ps
.bytes == null ||
_ps
.bytes.Length < bufferSize)
899
_ps
.bytes = new byte[bufferSize];
904
if (
_ps
.chars == null ||
_ps
.chars.Length < bufferSize + 1)
906
_ps
.chars = new char[bufferSize + 1];
910
_ps
.bytePos = 0;
911
if (
_ps
.bytesUsed < 4 &&
_ps
.bytes.Length -
_ps
.bytesUsed > 0)
913
int bytesToRead = Math.Min(4,
_ps
.bytes.Length -
_ps
.bytesUsed);
914
int read = await stream.ReadAtLeastAsync(
_ps
.bytes.AsMemory(
_ps
.bytesUsed), bytesToRead, throwOnEndOfStream: false).ConfigureAwait(false);
917
_ps
.isStreamEof = true;
919
_ps
.bytesUsed += read;
929
_documentStartBytePos =
_ps
.bytePos;
931
_ps
.eolNormalized = !_normalize;
934
_ps
.appendMode = true;
944
Debug.Assert(
_ps
.charPos == 0 &&
_ps
.charsUsed == 0 &&
_ps
.stream == null);
947
_ps
.textReader = input;
948
_ps
.baseUriStr = baseUriStr;
949
_ps
.baseUri = baseUri;
951
if (
_ps
.chars == null)
964
_ps
.chars = new char[bufferSize + 1];
967
_ps
.encoding = Encoding.Unicode;
968
_ps
.eolNormalized = !_normalize;
971
_ps
.appendMode = true;
1001
if ((newEncoding.WebName !=
_ps
.encoding!.WebName ||
_ps
.decoder is SafeAsciiDecoder) && !_afterResetState)
1003
Debug.Assert(
_ps
.stream != null);
1005
_ps
.appendMode = false;
1026
if (
_ps
.isEof)
1032
if (
_ps
.appendMode)
1035
if (
_ps
.charsUsed ==
_ps
.chars.Length - 1)
1058
char[] newChars = new char[
_ps
.chars.Length * 2];
1059
BlockCopyChars(
_ps
.chars, 0, newChars, 0,
_ps
.chars.Length);
1060
_ps
.chars = newChars;
1063
if (
_ps
.stream != null)
1066
if (
_ps
.bytesUsed -
_ps
.bytePos < MaxByteSequenceLen)
1068
if (
_ps
.bytes!.Length -
_ps
.bytesUsed < MaxByteSequenceLen)
1070
byte[] newBytes = new byte[
_ps
.bytes.Length * 2];
1071
BlockCopy(
_ps
.bytes, 0, newBytes, 0,
_ps
.bytesUsed);
1072
_ps
.bytes = newBytes;
1077
charsRead =
_ps
.chars.Length -
_ps
.charsUsed - 1;
1085
int charsLen =
_ps
.chars.Length;
1086
if (charsLen -
_ps
.charsUsed <= charsLen / 2)
1110
int copyCharsCount =
_ps
.charsUsed -
_ps
.charPos;
1113
_ps
.lineStartPos -=
_ps
.charPos;
1116
BlockCopyChars(
_ps
.chars,
_ps
.charPos,
_ps
.chars, 0, copyCharsCount);
1118
_ps
.charPos = 0;
1119
_ps
.charsUsed = copyCharsCount;
1123
char[] newChars = new char[
_ps
.chars.Length * 2];
1124
BlockCopyChars(
_ps
.chars, 0, newChars, 0,
_ps
.chars.Length);
1125
_ps
.chars = newChars;
1129
if (
_ps
.stream != null)
1132
int bytesLeft =
_ps
.bytesUsed -
_ps
.bytePos;
1137
_ps
.bytesUsed = 0;
1141
BlockCopy(
_ps
.bytes!,
_ps
.bytePos,
_ps
.bytes!, 0, bytesLeft);
1142
_ps
.bytesUsed = bytesLeft;
1144
_ps
.bytePos = 0;
1147
charsRead =
_ps
.chars.Length -
_ps
.charsUsed - 1;
1150
if (
_ps
.stream != null)
1152
if (!
_ps
.isStreamEof)
1155
if (
_ps
.bytePos ==
_ps
.bytesUsed &&
_ps
.bytes!.Length -
_ps
.bytesUsed > 0)
1157
int read = await
_ps
.stream.ReadAsync(
_ps
.bytes.AsMemory(
_ps
.bytesUsed)).ConfigureAwait(false);
1160
_ps
.isStreamEof = true;
1162
_ps
.bytesUsed += read;
1166
int originalBytePos =
_ps
.bytePos;
1170
if (charsRead == 0 &&
_ps
.bytePos != originalBytePos)
1176
else if (
_ps
.textReader != null)
1179
charsRead = await
_ps
.textReader.ReadAsync(
_ps
.chars.AsMemory(
_ps
.charsUsed,
_ps
.chars.Length -
_ps
.charsUsed - 1)).ConfigureAwait(false);
1180
_ps
.charsUsed += charsRead;
1191
Debug.Assert(
_ps
.charsUsed <
_ps
.chars.Length);
1192
_ps
.isEof = true;
1194
_ps
.chars[
_ps
.charsUsed] = (char)0;
1201
while (
_ps
.charsUsed -
_ps
.charPos < 6)
1209
if (!
_ps
.chars.AsSpan(
_ps
.charPos).StartsWith(XmlDeclarationBeginning) ||
1210
XmlCharType.IsNameSingleChar(
_ps
.chars[
_ps
.charPos + 5]))
1217
_curNode.SetLineInfo(
_ps
.LineNo,
_ps
.LinePos + 2);
1220
_ps
.charPos += 5;
1236
if (
_ps
.chars[
_ps
.charPos] == '?')
1240
if (
_ps
.chars[
_ps
.charPos + 1] == '>')
1247
_ps
.charPos += 2;
1268
string encodingName =
_ps
.encoding!.WebName;
1270
encodingName != "utf-16BE" && !(
_ps
.encoding is Ucs4Encoding))
1272
Throw(SR.Xml_EncodingSwitchAfterResetState, (
_ps
.encoding.GetByteCount("A") == 1) ? "UTF-8" : "UTF-16");
1275
if (
_ps
.decoder is SafeAsciiDecoder)
1284
_ps
.appendMode = false;
1287
else if (
_ps
.charPos + 1 ==
_ps
.charsUsed)
1306
switch (
_ps
.chars.AsSpan(
_ps
.charPos, nameEndPos -
_ps
.charPos))
1343
attr!.SetLineInfo(
_ps
.LineNo,
_ps
.LinePos);
1345
sb.Append(
_ps
.chars,
_ps
.charPos, nameEndPos -
_ps
.charPos);
1346
_ps
.charPos = nameEndPos;
1349
if (
_ps
.chars[
_ps
.charPos] != '=')
1352
if (
_ps
.chars[
_ps
.charPos] != '=')
1358
_ps
.charPos++;
1360
char quoteChar =
_ps
.chars[
_ps
.charPos];
1364
quoteChar =
_ps
.chars[
_ps
.charPos];
1371
_ps
.charPos++;
1375
attr.SetLineInfo2(
_ps
.LineNo,
_ps
.LinePos);
1379
int pos =
_ps
.charPos;
1382
chars =
_ps
.chars;
1389
if (
_ps
.chars[pos] == quoteChar)
1396
if (
_ps
.chars.AsSpan(
_ps
.charPos).StartsWith("1.0"))
1400
attr!.SetValue(
_ps
.chars,
_ps
.charPos, pos -
_ps
.charPos);
1406
string badVersion = new string(
_ps
.chars,
_ps
.charPos, pos -
_ps
.charPos);
1411
string encName = new string(
_ps
.chars,
_ps
.charPos, pos -
_ps
.charPos);
1420
switch (
_ps
.chars.AsSpan(
_ps
.charPos, pos -
_ps
.charPos))
1430
Throw(SR.Xml_InvalidXmlDecl,
_ps
.LineNo,
_ps
.LinePos - 1);
1435
attr!.SetValue(
_ps
.chars,
_ps
.charPos, pos -
_ps
.charPos);
1443
sb.Append(chars,
_ps
.charPos, pos -
_ps
.charPos);
1445
_ps
.charPos = pos + 1;
1448
else if (pos ==
_ps
.charsUsed)
1465
if (
_ps
.isEof || await ReadDataAsync().ConfigureAwait(false) == 0)
1481
string encodingName =
_ps
.encoding!.WebName;
1483
encodingName != "utf-16BE" && !(
_ps
.encoding is Ucs4Encoding))
1485
Throw(SR.Xml_EncodingSwitchAfterResetState, (
_ps
.encoding.GetByteCount("A") == 1) ? "UTF-8" : "UTF-16");
1488
if (
_ps
.decoder is SafeAsciiDecoder)
1492
_ps
.appendMode = false;
1504
int pos =
_ps
.charPos;
1505
char[] chars =
_ps
.chars;
1511
if (
_ps
.charsUsed - pos < 4) // minimum "<a/>"
1518
_ps
.charPos = pos + 1;
1522
if (
_ps
.charsUsed - pos < 2) // minimum characters expected "--"
1529
_ps
.charPos = pos + 2;
1543
if (
_ps
.charsUsed - pos < 6)
1549
_ps
.charPos = pos + 6;
1559
Throw(
_ps
.charPos, SR.Xml_InvalidRootData);
1568
_ps
.charPos = pos;
1600
_ps
.charPos = pos;
1610
else if (pos ==
_ps
.charsUsed || (_v1Compat && chars[pos] == 0x0))
1627
Debug.Assert(pos ==
_ps
.charsUsed && !
_ps
.isEof);
1642
int pos =
_ps
.charPos;
1763
int pos =
_ps
.charPos;
1764
char[] chars =
_ps
.chars;
1774
_ps
.charPos = pos + 2;
1778
if (
_ps
.charsUsed - pos < 2)
1785
_ps
.charPos = pos + 2;
1797
if (
_ps
.charsUsed - pos < 6)
1803
_ps
.charPos = pos + 6;
1825
_ps
.charPos = pos + 2;
1829
if (pos + 1 ==
_ps
.charsUsed)
1836
_ps
.charPos = pos + 1;
1845
if (pos ==
_ps
.charsUsed)
1863
if (
_ps
.charsUsed -
_ps
.charPos != 0)
1888
int pos =
_ps
.charPos;
1889
char[] chars =
_ps
.chars;
1892
_curNode.SetLineInfo(
_ps
.LineNo,
_ps
.LinePos);
1943
else if (pos + 1 <
_ps
.charsUsed)
1981
char[] chars =
_ps
.chars;
1990
_nameTable.Add(chars,
_ps
.charPos, pos -
_ps
.charPos));
1994
int startPos =
_ps
.charPos;
2007
_nameTable.Add(chars,
_ps
.charPos, prefixLen),
2019
_ps
.charPos = pos;
2033
int pos =
_ps
.charPos;
2034
char[] chars =
_ps
.chars;
2039
_ps
.charPos = pos + 1;
2045
if (pos + 1 ==
_ps
.charsUsed)
2047
_ps
.charPos = pos;
2055
_ps
.charPos = pos + 2;
2065
Throw(pos, SR.Xml_BadNameChar, XmlException.BuildCharExceptionArgs(chars,
_ps
.charsUsed, pos));
2097
if (
_ps
.charsUsed -
_ps
.charPos < prefLen + locLen + 1)
2119
while (
_ps
.charsUsed -
_ps
.charPos < prefLen + locLen + 1)
2135
char[] chars =
_ps
.chars;
2138
if (!chars.AsSpan(
_ps
.charPos).StartsWith(startTagNode.localName))
2146
int colonPos =
_ps
.charPos + prefLen;
2147
if (!chars.AsSpan(
_ps
.charPos).StartsWith(startTagNode.prefix) ||
2155
LineInfo endTagLineInfo = new LineInfo(
_ps
.lineNo,
_ps
.LinePos);
2217
pos =
_ps
.charPos + nameLen;
2218
chars =
_ps
.chars;
2220
if (pos ==
_ps
.charsUsed)
2255
else if (pos ==
_ps
.charsUsed && !
_ps
.isEof)
2269
else if (pos ==
_ps
.charsUsed)
2290
_ps
.charPos = pos + 1;
2324
args[3] = new string(
_ps
.chars,
_ps
.charPos, endPos -
_ps
.charPos);
2337
int pos =
_ps
.charPos;
2338
char[] chars =
_ps
.chars;
2364
else if (pos + 1 !=
_ps
.charsUsed)
2371
_ps
.charPos = pos;
2392
_ps
.charPos = pos + 1;
2400
if (pos + 1 ==
_ps
.charsUsed)
2406
_ps
.charPos = pos + 2;
2417
else if (pos ==
_ps
.charsUsed)
2423
Throw(pos, SR.Xml_BadStartNameChar, XmlException.BuildCharExceptionArgs(chars,
_ps
.charsUsed, pos));
2427
if (pos ==
_ps
.charPos)
2431
_ps
.charPos = pos;
2434
int attrNameLinePos =
_ps
.LinePos;
2496
chars =
_ps
.chars;
2499
else if (pos + 1 >=
_ps
.charsUsed)
2506
chars =
_ps
.chars;
2510
attr.SetLineInfo(
_ps
.LineNo, attrNameLinePos);
2519
_ps
.charPos = pos;
2521
pos =
_ps
.charPos;
2532
_ps
.charPos = pos;
2534
pos =
_ps
.charPos;
2542
_ps
.charPos = pos;
2545
attr.SetLineInfo2(
_ps
.LineNo,
_ps
.LinePos);
2563
attr.SetValue(chars,
_ps
.charPos, pos -
_ps
.charPos);
2565
_ps
.charPos = pos;
2570
pos =
_ps
.charPos;
2571
chars =
_ps
.chars;
2599
_ps
.lineNo -= lineNoDelta;
2602
pos =
_ps
.charPos;
2603
chars =
_ps
.chars;
2636
char[] chars =
_ps
.chars;
2637
int attributeBaseEntityId =
_ps
.entityId;
2640
LineInfo valueChunkLineInfo = new LineInfo(
_ps
.lineNo,
_ps
.LinePos);
2653
if (pos -
_ps
.charPos > 0)
2655
_stringBuilder.Append(chars,
_ps
.charPos, pos -
_ps
.charPos);
2656
_ps
.charPos = pos;
2659
if (chars[pos] == quoteChar && attributeBaseEntityId ==
_ps
.entityId)
2674
_ps
.charPos++;
2683
_stringBuilder.Append(
_ps
.eolNormalized ? "\u0020\u0020" : "\u0020"); // CDATA normalization of 0xD 0xA
2684
_ps
.charPos = pos;
2687
else if (pos + 1 <
_ps
.charsUsed ||
_ps
.isEof)
2693
_ps
.charPos = pos;
2708
_ps
.charPos++;
2722
if (pos -
_ps
.charPos > 0)
2724
_stringBuilder.Append(chars,
_ps
.charPos, pos -
_ps
.charPos);
2726
_ps
.charPos = pos;
2729
int enclosingEntityId =
_ps
.entityId;
2730
LineInfo entityLineInfo = new LineInfo(
_ps
.lineNo,
_ps
.LinePos + 1);
2743
if (_parsingMode == ParsingMode.Full &&
_ps
.entityId == attributeBaseEntityId)
2757
_ps
.charPos++;
2774
valueChunkLineInfo.Set(
_ps
.LineNo,
_ps
.LinePos);
2780
_ps
.charPos++;
2783
pos =
_ps
.charPos;
2804
entityChunk.SetNamedNode(XmlNodeType.EntityReference,
_ps
.entity!.Name);
2812
pos =
_ps
.charPos;
2815
pos =
_ps
.charPos;
2818
chars =
_ps
.chars;
2822
if (pos ==
_ps
.charsUsed)
2832
if (pos + 1 ==
_ps
.charsUsed)
2843
ThrowInvalidChar(chars,
_ps
.charsUsed, pos);
2853
if (
_ps
.charsUsed -
_ps
.charPos > 0)
2855
if (
_ps
.chars[
_ps
.charPos] != (char)0xD)
2860
Debug.Assert(
_ps
.isEof);
2868
if (attributeBaseEntityId !=
_ps
.entityId)
2883
if (attributeBaseEntityId ==
_ps
.entityId)
2886
valueChunkLineInfo.Set(
_ps
.LineNo,
_ps
.LinePos);
2891
pos =
_ps
.charPos;
2892
chars =
_ps
.chars;
2910
_ps
.charPos = pos + 1;
2928
_curNode.SetLineInfo(
_ps
.LineNo,
_ps
.LinePos);
2960
_curNode.SetValueNode(nodeType,
_ps
.chars, startPos, endPos - startPos);
2996
_curNode.SetLineInfo(
_ps
.LineNo,
_ps
.LinePos);
3019
_curNode.SetValueNode(nodeType,
_ps
.chars, startPos, endPos - startPos);
3034
_stringBuilder.Append(
_ps
.chars, startPos, endPos - startPos);
3045
_stringBuilder.Append(
_ps
.chars, startPos, endPos - startPos);
3070
_curNode.SetValueNode(XmlNodeType.Text,
_ps
.chars, startPos, endPos - startPos);
3079
_stringBuilder.Append(
_ps
.chars, startPos, endPos - startPos);
3092
_stringBuilder.Append(
_ps
.chars, startPos, endPos - startPos);
3199
Task<(int, int, int, bool)> task = ParseTextAsync(outOrChars,
_ps
.chars,
_ps
.charPos, 0, -1, outOrChars);
3298
if (!
_ps
.eolNormalized && _parsingMode == ParsingMode.Full)
3300
if (pos -
_ps
.charPos > 0)
3316
_ps
.charPos++;
3321
else if (pos + 1 <
_ps
.charsUsed ||
_ps
.isEof)
3323
if (!
_ps
.eolNormalized)
3348
if (
_ps
.charsUsed - pos < 3 && !
_ps
.isEof)
3363
if (pos ==
_ps
.charsUsed)
3403
if (pos >
_ps
.charPos)
3433
if (!XmlCharType.IsWhiteSpace(
_ps
.chars[pos - 1]))
3439
pos =
_ps
.charPos;
3442
chars =
_ps
.chars;
3455
if (pos + 1 ==
_ps
.charsUsed)
3471
int offset = pos -
_ps
.charPos;
3474
chars =
_ps
.chars;
3475
pos =
_ps
.charPos + offset;
3482
ThrowInvalidChar(
_ps
.chars,
_ps
.charsUsed,
_ps
.charPos + offset);
3490
if (pos >
_ps
.charPos)
3499
if (
_ps
.charsUsed -
_ps
.charPos > 0)
3501
if (
_ps
.chars[
_ps
.charPos] != (char)0xD &&
_ps
.chars[
_ps
.charPos] != ']')
3505
Debug.Assert(
_ps
.isEof);
3529
pos =
_ps
.charPos;
3530
chars =
_ps
.chars;
3547
int startPos =
_ps
.charPos;
3549
_ps
.charPos = pos;
3576
_stringBuilder.Append(
_ps
.chars, startPos, endPos - startPos);
3583
_stringBuilder.Append(
_ps
.chars, startPos, endPos - startPos);
3714
if (
_ps
.chars[
_ps
.charPos] == '<' ||
_ps
.charsUsed -
_ps
.charPos == 0 || await ZeroEndingStreamAsync(
_ps
.charPos).ConfigureAwait(false))
3721
_curNode.SetLineInfo(
_ps
.LineNo,
_ps
.LinePos);
3723
if (
_ps
.chars[
_ps
.charPos] == '<' ||
_ps
.charsUsed -
_ps
.charPos == 0 || await ZeroEndingStreamAsync(
_ps
.charPos).ConfigureAwait(false))
3735
if (XmlCharType.IsCharData(
_ps
.chars[
_ps
.charPos]))
3741
ThrowInvalidChar(
_ps
.chars,
_ps
.charsUsed,
_ps
.charPos);
3748
Debug.Assert(
_ps
.chars[
_ps
.charPos] == '&');
3749
_ps
.charPos++;
3751
_curNode.SetLineInfo(
_ps
.LineNo,
_ps
.LinePos);
3759
Debug.Assert(
_ps
.chars[
_ps
.charPos] == '&');
3761
if (
_ps
.charPos + 1 ==
_ps
.charsUsed)
3770
if (
_ps
.chars[
_ps
.charPos + 1] == '#')
3805
_ps
.charPos++;
3806
int savedLinePos =
_ps
.LinePos;
3813
Throw(SR.Xml_ErrorParsingEntityName,
_ps
.LineNo, savedLinePos);
3819
if (
_ps
.chars[endPos] != ';')
3824
int entityLinePos =
_ps
.LinePos;
3825
string entityName = _nameTable.Add(
_ps
.chars,
_ps
.charPos, endPos -
_ps
.charPos);
3826
_ps
.charPos = endPos + 1;
3830
_reportedBaseUri =
_ps
.baseUriStr;
3831
_reportedEncoding =
_ps
.encoding;
3859
Throw(SR.Xml_UndeclaredEntity, name,
_ps
.LineNo, entityStartLinePos);
3872
Throw(SR.Xml_UnparsedEntityRef, name,
_ps
.LineNo, entityStartLinePos);
3877
Throw(SR.Xml_ExternalEntityInStandAloneDocument, entity.Name,
_ps
.LineNo, entityStartLinePos);
3884
Throw(SR.Xml_ExternalEntityInAttValue, name,
_ps
.LineNo, entityStartLinePos);
3898
_curNode.entityId =
_ps
.entityId;
3906
_curNode.entityId =
_ps
.entityId;
3919
_curNode.entityId =
_ps
.entityId;
3935
_curNode.SetLineInfo(
_ps
.LineNo,
_ps
.LinePos);
3942
string target = _nameTable.Add(
_ps
.chars,
_ps
.charPos, nameEndPos -
_ps
.charPos);
3948
_ps
.charPos = nameEndPos;
3963
char ch =
_ps
.chars[
_ps
.charPos];
3964
Debug.Assert(
_ps
.charPos <
_ps
.charsUsed);
3967
if (
_ps
.charsUsed -
_ps
.charPos < 2)
3971
if (ch != '?' ||
_ps
.chars[
_ps
.charPos + 1] != '>')
3973
Throw(SR.Xml_BadNameChar, XmlException.BuildCharExceptionArgs(
_ps
.chars,
_ps
.charsUsed,
_ps
.charPos));
3994
_curNode.SetValue(
_ps
.chars, startPos, endPos - startPos);
3999
piInDtdStringBuilder.Append(
_ps
.chars, startPos, endPos - startPos);
4029
sb.Append(
_ps
.chars, startPos, endPos - startPos);
4036
sb.Append(
_ps
.chars, startPos, endPos - startPos);
4053
if (
_ps
.charsUsed -
_ps
.charPos < 2)
4057
Throw(
_ps
.charsUsed, SR.Xml_UnexpectedEOF, "PI");
4061
int pos =
_ps
.charPos;
4062
char[] chars =
_ps
.chars;
4083
Debug.Assert(!
_ps
.eolNormalized);
4091
outStartPos =
_ps
.charPos;
4092
_ps
.charPos = pos + 2;
4096
else if (pos + 1 ==
_ps
.charsUsed)
4113
if (!
_ps
.eolNormalized && _parsingMode == ParsingMode.Full)
4116
if (pos -
_ps
.charPos > 0)
4132
_ps
.charPos++;
4137
else if (pos + 1 <
_ps
.charsUsed ||
_ps
.isEof)
4139
if (!
_ps
.eolNormalized)
4159
if (pos ==
_ps
.charsUsed)
4169
if (pos + 1 ==
_ps
.charsUsed)
4180
ThrowInvalidChar(chars,
_ps
.charsUsed, pos);
4196
outStartPos =
_ps
.charPos;
4197
_ps
.charPos = pos;
4231
_curNode.SetLineInfo(
_ps
.LineNo,
_ps
.LinePos);
4240
_curNode.SetValueNode(type,
_ps
.chars, startPos, endPos - startPos);
4248
_stringBuilder.Append(
_ps
.chars, startPos, endPos - startPos);
4255
_stringBuilder.Append(
_ps
.chars, startPos, endPos - startPos);
4277
if (
_ps
.charsUsed -
_ps
.charPos < 3)
4286
int pos =
_ps
.charPos;
4287
char[] chars =
_ps
.chars;
4309
Debug.Assert(!
_ps
.eolNormalized);
4317
outStartPos =
_ps
.charPos;
4318
_ps
.charPos = pos + 3;
4322
else if (pos + 2 ==
_ps
.charsUsed)
4331
else if (pos + 1 ==
_ps
.charsUsed)
4351
if (!
_ps
.eolNormalized && _parsingMode == ParsingMode.Full)
4353
if (pos -
_ps
.charPos > 0)
4369
_ps
.charPos++;
4374
else if (pos + 1 <
_ps
.charsUsed ||
_ps
.isEof)
4376
if (!
_ps
.eolNormalized)
4396
if (pos ==
_ps
.charsUsed)
4404
if (pos + 1 ==
_ps
.charsUsed)
4415
ThrowInvalidChar(chars,
_ps
.charsUsed, pos);
4430
outStartPos =
_ps
.charPos;
4432
_ps
.charPos = pos;
4447
while (
_ps
.charsUsed -
_ps
.charPos < 8)
4454
if (!
_ps
.chars.AsSpan(
_ps
.charPos).StartsWith("DOCTYPE"))
4458
if (!XmlCharType.IsWhiteSpace(
_ps
.chars[
_ps
.charPos + 7]))
4460
ThrowExpectingWhitespace(
_ps
.charPos + 7);
4465
Throw(
_ps
.charPos - 2, SR.Xml_MultipleDTDsProvided); // position just before <!DOCTYPE
4469
Throw(
_ps
.charPos - 2, SR.Xml_DtdAfterRootElement);
4472
_ps
.charPos += 8;
4479
_curNode.SetLineInfo(
_ps
.LineNo,
_ps
.LinePos);
4521
_ps
.charPos = pos;
4527
if (
_ps
.chars[
_ps
.charPos] == 'P')
4530
while (
_ps
.charsUsed -
_ps
.charPos < 6)
4538
if (!
_ps
.chars.AsSpan(
_ps
.charPos).StartsWith("PUBLIC"))
4542
_ps
.charPos += 6;
4547
ThrowExpectingWhitespace(
_ps
.charPos);
4556
ThrowExpectingWhitespace(
_ps
.charPos);
4564
else if (
_ps
.chars[
_ps
.charPos] == 'S')
4567
while (
_ps
.charsUsed -
_ps
.charPos < 6)
4575
if (!
_ps
.chars.AsSpan(
_ps
.charPos).StartsWith("SYSTEM"))
4579
_ps
.charPos += 6;
4584
ThrowExpectingWhitespace(
_ps
.charPos);
4592
else if (
_ps
.chars[
_ps
.charPos] != '[' &&
_ps
.chars[
_ps
.charPos] != '>')
4598
if (
_ps
.chars[
_ps
.charPos] == '[')
4600
_ps
.charPos++;
4605
if (
_ps
.chars[
_ps
.charPos] != '>')
4610
else if (
_ps
.chars[
_ps
.charPos] == '>')
4618
_ps
.charPos++;
4624
char quoteChar =
_ps
.chars[
_ps
.charPos];
4630
_ps
.charPos++;
4641
char[] chars =
_ps
.chars;
4642
int pos =
_ps
.charPos;
4656
_ps
.charPos = pos + 1;
4661
_ps
.charPos = pos;
4674
else if (pos + 1 <
_ps
.charsUsed ||
_ps
.isEof)
4700
if (pos + 3 >=
_ps
.charsUsed && !
_ps
.isEof)
4715
else if (pos + 1 >=
_ps
.charsUsed && !
_ps
.isEof)
4725
if (pos + 2 >=
_ps
.charsUsed && !
_ps
.isEof)
4743
if (pos + 1 >=
_ps
.charsUsed && !
_ps
.isEof)
4784
if (pos ==
_ps
.charsUsed)
4794
if (pos + 1 ==
_ps
.charsUsed)
4805
ThrowInvalidChar(chars,
_ps
.charsUsed, pos);
4814
if (
_ps
.charsUsed -
_ps
.charPos > 0)
4816
if (
_ps
.chars[
_ps
.charPos] != (char)0xD)
4821
Debug.Assert(
_ps
.isEof);
4828
chars =
_ps
.chars;
4829
pos =
_ps
.charPos;
4835
int pos =
_ps
.charPos;
4837
char[] chars =
_ps
.chars;
4852
int tmp1 = pos -
_ps
.charPos;
4853
if (sb != null && !
_ps
.eolNormalized)
4857
sb.Append(chars,
_ps
.charPos, tmp1);
4860
_ps
.charPos = pos + 1;
4864
else if (pos + 1 <
_ps
.charsUsed ||
_ps
.isEof)
4866
if (!
_ps
.eolNormalized)
4883
if (pos ==
_ps
.charsUsed)
4889
int tmp2 = pos -
_ps
.charPos;
4892
sb?.Append(
_ps
.chars,
_ps
.charPos, tmp2);
4893
_ps
.charPos = pos;
4902
int tmp3 = pos -
_ps
.charPos;
4905
sb?.Append(
_ps
.chars,
_ps
.charPos, tmp3);
4906
_ps
.charPos = pos;
4912
if (
_ps
.charsUsed -
_ps
.charPos == 0)
4916
if (
_ps
.chars[
_ps
.charPos] != (char)0xD)
4921
Debug.Assert(
_ps
.isEof);
4923
pos =
_ps
.charPos;
4924
chars =
_ps
.chars;
4942
switch (newPos = ParseNumericCharRefInline(
_ps
.charPos, expand, internalSubsetBuilder, out charCount, out entityType))
4950
Debug.Assert(
_ps
.chars[
_ps
.charPos] == '&');
4955
_ps
.charPos = newPos - charCount;
4974
switch (newPos = ParseNamedCharRefInline(
_ps
.charPos, expand, internalSubsetBuilder))
4984
Debug.Assert(
_ps
.chars[
_ps
.charPos] == '&');
4989
_ps
.charPos = newPos - 1;
5012
int pos =
_ps
.charPos + startOffset;
5015
char[] chars =
_ps
.chars;
5024
if (pos + 1 >=
_ps
.charsUsed)
5037
Throw(pos, SR.Xml_BadStartNameChar, XmlException.BuildCharExceptionArgs(chars,
_ps
.charsUsed, pos));
5064
colonOffset = pos -
_ps
.charPos;
5070
colonOffset = pos -
_ps
.charPos;
5076
else if (pos ==
_ps
.charsUsed)
5083
chars =
_ps
.chars;
5090
colonPos = (colonOffset == -1) ? -1 :
_ps
.charPos + colonOffset;
5097
int offset = pos -
_ps
.charPos;
5099
pos =
_ps
.charPos + offset;
5118
if (
_ps
.chars[endPos] != ';')
5123
string entityName = _nameTable.Add(
_ps
.chars,
_ps
.charPos, endPos -
_ps
.charPos);
5124
_ps
.charPos = endPos + 1;
5241
Debug.Assert(
_ps
.appendMode);
5242
int initialPos =
_ps
.charPos;
5249
_ps
.charPos = initialPos;
5255
Encoding? enc =
_ps
.encoding;
5275
if (_v1Compat && pos ==
_ps
.charsUsed - 1 &&
_ps
.chars[pos] == (char)0 && await ReadDataAsync().ConfigureAwait(false) == 0 &&
_ps
.isStreamEof)
5277
_ps
.charsUsed--;
5409
_curNode.AdjustLineInfo(_readValueOffset,
_ps
.eolNormalized, ref _incReadLineInfo);
5433
_incReadLineInfo.Set(
_ps
.LineNo,
_ps
.LinePos);
5443
charsRead = _incReadDecoder.Decode(
_ps
.chars, startPos, endPos - startPos);
5457
_curNode.SetValue(
_ps
.chars, startPos, endPos - startPos);
5459
AdjustLineInfo(
_ps
.chars, startPos - charsRead, startPos,
_ps
.eolNormalized, ref _incReadLineInfo);