1 write to _ps
System.Private.Xml (1)
System\Xml\Core\XmlTextReaderImpl.cs (1)
8135
_ps
= _parsingStatesStack[_parsingStatesStackTop--];
1713 references to _ps
System.Private.Xml (1713)
System\Xml\Core\XmlTextReaderImpl.cs (1057)
351
_ps
.lineNo = 1;
352
_ps
.lineStartPos = -1;
413
_ps
.lineNo = _lineNumberOffset + 1;
414
_ps
.lineStartPos = -_linePositionOffset - 1;
415
_curNode.SetLineInfo(
_ps
.LineNo - 1,
_ps
.LinePos - 1);
475
_reportedBaseUri =
_ps
.baseUriStr;
476
_reportedEncoding =
_ps
.encoding;
499
_reportedEncoding =
_ps
.encoding;
522
_reportedBaseUri =
_ps
.baseUriStr;
523
_reportedEncoding =
_ps
.encoding;
544
_reportedEncoding =
_ps
.encoding;
575
_ps
.baseUri = GetTempResolver().ResolveUri(null, url);
576
_ps
.baseUriStr =
_ps
.baseUri.ToString();
577
_reportedBaseUri =
_ps
.baseUriStr;
663
_reportedEncoding =
_ps
.encoding;
743
_reportedEncoding =
_ps
.encoding;
796
_reportedEncoding =
_ps
.encoding;
814
_reportedBaseUri =
_ps
.baseUriStr;
815
_reportedEncoding =
_ps
.encoding;
1237
Debug.Assert(!
_ps
.appendMode);
1246
_reportedEncoding =
_ps
.encoding;
1249
_reportedEncoding =
_ps
.encoding;
1286
_reportedEncoding =
_ps
.encoding;
1287
_reportedBaseUri =
_ps
.baseUriStr;
1293
_curNode.SetLineInfo(
_ps
.lineNo,
_ps
.LinePos);
1294
_reportedEncoding =
_ps
.encoding;
1295
_reportedBaseUri =
_ps
.baseUriStr;
1467
_attributeValueBaseEntityId =
_ps
.entityId;
1472
if (
_ps
.entityId == _attributeValueBaseEntityId)
1508
if (
_ps
.charsUsed -
_ps
.charPos == 0)
1529
if (
_ps
.charsUsed -
_ps
.charPos == 0 && !
_ps
.entity!.IsExternal)
1547
_ps
.entityResolvedManually = true;
1867
Debug.Assert(
_ps
.chars != null);
1868
BlockCopyChars(
_ps
.chars, startPos, buffer, (index + readCount), copyCount);
1891
Debug.Assert(
_ps
.chars != null);
1892
_curNode.SetValue(
_ps
.chars, startPos, endPos - startPos);
2020
if (
_ps
.entity == null ||
_ps
.entity.IsExternal)
2022
_ps
.eolNormalized = !value;
2111
_ps
.baseUri = null;
2178
_stringBuilder.Append(
_ps
.chars, _incReadLeftStartPos, _incReadLeftEndPos - _incReadLeftStartPos);
2188
_ps
.appendMode = false;
2191
_stringBuilder.Append(
_ps
.chars,
_ps
.charPos,
_ps
.charsUsed -
_ps
.charPos);
2192
_ps
.charPos =
_ps
.charsUsed;
2363
if (
_ps
.baseUriStr.Length > 0 &&
_ps
.baseUri == null && _xmlResolver != null)
2365
_ps
.baseUri = _xmlResolver.ResolveUri(null,
_ps
.baseUriStr);
2368
return
_ps
.baseUri;
2376
return
_ps
.isEof;
2384
return
_ps
.chars;
2392
return
_ps
.charsUsed;
2400
return
_ps
.charPos;
2404
Debug.Assert(value >= 0 && value <=
_ps
.charsUsed);
2405
_ps
.charPos = value;
2421
return
_ps
.eolNormalized;
2446
return
_ps
.LineNo;
2454
return
_ps
.lineStartPos;
2514
if (e.ResString == SR.Xml_UnexpectedEOF &&
_ps
.entity != null)
2516
SendValidationEvent(XmlSeverityType.Error, SR.Sch_ParEntityRefNesting, null,
_ps
.LineNo,
_ps
.LinePos);
2555
entityId =
_ps
.entityId;
2568
oldEntity =
_ps
.entity;
2570
newEntityId =
_ps
.entityId;
2588
if (
_ps
.baseUri == null && !string.IsNullOrEmpty(
_ps
.baseUriStr))
2590
_ps
.baseUri = _xmlResolver.ResolveUri(null,
_ps
.baseUriStr);
2593
PushExternalEntityOrSubset(publicId, systemId,
_ps
.baseUri, null);
2595
_ps
.entity = null;
2596
_ps
.entityId = 0;
2598
Debug.Assert(
_ps
.appendMode);
2599
int initialPos =
_ps
.charPos;
2606
_ps
.charPos = initialPos;
2622
_ps
.entity = null;
2623
_ps
.entityId = 0;
2624
_ps
.eolNormalized = false;
2655
_ps
.charPos = pos;
2662
_ps
.charPos = pos;
2669
_ps
.charPos = pos;
2682
Throw(new XmlException(res, string.Empty, lineNo, linePos,
_ps
.baseUriStr));
2688
Throw(new XmlException(res, arg,
_ps
.LineNo,
_ps
.LinePos,
_ps
.baseUriStr));
2694
Throw(new XmlException(res, arg, lineNo, linePos,
_ps
.baseUriStr));
2700
Throw(new XmlException(res, args,
_ps
.LineNo,
_ps
.LinePos,
_ps
.baseUriStr));
2712
Throw(new XmlException(res, args, innerException,
_ps
.LineNo,
_ps
.LinePos,
_ps
.baseUriStr));
2732
Throw(new XmlException(e.Message, (Exception?)null, lineNo, linePos,
_ps
.baseUriStr));
2738
Throw(new XmlException(res, string.Empty,
_ps
.baseUriStr));
2744
Throw(new XmlException(res, arg,
_ps
.baseUriStr));
2750
Throw(new XmlException(res, args, innerException, 0, 0,
_ps
.baseUriStr));
2767
SendValidationEvent(severity, new XmlSchemaException(code, arg,
_ps
.baseUriStr, lineNo, linePos));
2800
while (
_ps
.entityId != _attributeValueBaseEntityId)
2842
Debug.Assert(
_ps
.charPos == 0 &&
_ps
.charsUsed == 0 &&
_ps
.textReader == null);
2846
_ps
.stream = stream;
2847
_ps
.baseUri = baseUri;
2848
_ps
.baseUriStr = baseUriStr;
2854
_ps
.bytes = bytes;
2855
_ps
.bytesUsed = byteCount;
2856
bufferSize =
_ps
.bytes.Length;
2869
if (
_ps
.bytes == null ||
_ps
.bytes.Length < bufferSize)
2871
_ps
.bytes = new byte[bufferSize];
2876
if (
_ps
.chars == null ||
_ps
.chars.Length < bufferSize + 1)
2878
_ps
.chars = new char[bufferSize + 1];
2882
_ps
.bytePos = 0;
2883
if (
_ps
.bytesUsed < 4 &&
_ps
.bytes.Length -
_ps
.bytesUsed > 0)
2885
int bytesToRead = Math.Min(4,
_ps
.bytes.Length -
_ps
.bytesUsed);
2886
int read = stream.ReadAtLeast(
_ps
.bytes.AsSpan(
_ps
.bytesUsed), bytesToRead, throwOnEndOfStream: false);
2889
_ps
.isStreamEof = true;
2891
_ps
.bytesUsed += read;
2901
_documentStartBytePos =
_ps
.bytePos;
2903
_ps
.eolNormalized = !_normalize;
2906
_ps
.appendMode = true;
2917
Debug.Assert(
_ps
.charPos == 0 &&
_ps
.charsUsed == 0 &&
_ps
.stream == null);
2920
_ps
.textReader = input;
2921
_ps
.baseUriStr = baseUriStr;
2922
_ps
.baseUri = baseUri;
2924
if (
_ps
.chars == null)
2928
_ps
.chars = new char[XmlReader.AsyncBufferSize + 1];
2932
_ps
.chars = new char[XmlReader.DefaultBufferSize + 1];
2936
_ps
.encoding = Encoding.Unicode;
2937
_ps
.eolNormalized = !_normalize;
2940
_ps
.appendMode = true;
2946
Debug.Assert(
_ps
.stream == null &&
_ps
.textReader == null);
2947
Debug.Assert(
_ps
.charPos == 0 &&
_ps
.charsUsed == 0);
2951
_ps
.baseUriStr = baseUriStr;
2952
_ps
.baseUri = null;
2955
_ps
.chars = new char[len + 1];
2956
str.CopyTo(0,
_ps
.chars, 0, str.Length);
2957
_ps
.charsUsed = len;
2958
_ps
.chars[len] = (char)0;
2960
_ps
.encoding = originalEncoding;
2962
_ps
.eolNormalized = !_normalize;
2963
_ps
.isEof = true;
2982
_ps
.baseUriStr = parserContext.BaseURI;
2983
_ps
.baseUri = null;
2990
_ps
.baseUriStr = string.Empty;
2991
_ps
.baseUri = null;
2994
_reportedBaseUri =
_ps
.baseUriStr;
2999
_ps
.appendMode = false;
3014
_ps
.appendMode = false;
3060
if (
_ps
.baseUri == null)
3062
_ps
.baseUri = tmpResolver.ResolveUri(null, _url);
3063
_ps
.baseUriStr =
_ps
.baseUri.ToString();
3068
_ps
.stream = (Stream?)tmpResolver.GetEntity(
_ps
.baseUri, null, typeof(Stream));
3076
if (
_ps
.stream == null)
3078
ThrowWithoutLineInfo(SR.Xml_CannotResolveUrl,
_ps
.baseUriStr);
3081
Debug.Assert(
_ps
.stream != null);
3082
InitStreamInput(
_ps
.baseUri,
_ps
.baseUriStr,
_ps
.stream, null);
3083
_reportedEncoding =
_ps
.encoding;
3089
Debug.Assert(
_ps
.bytes != null);
3090
Debug.Assert(
_ps
.bytePos == 0);
3092
if (
_ps
.bytesUsed < 2)
3097
int first2Bytes =
_ps
.bytes[0] << 8 |
_ps
.bytes[1];
3098
int next2Bytes = (
_ps
.bytesUsed >= 4) ? (
_ps
.bytes[2] << 8 |
_ps
.bytes[3]) : 0;
3176
Debug.Assert(
_ps
.charPos == 0);
3177
_ps
.encoding = Encoding.UTF8;
3178
_ps
.decoder = new SafeAsciiDecoder();
3182
_ps
.encoding = encoding;
3183
_ps
.decoder =
_ps
.encoding.WebName switch // Encoding.Codepage is not supported in Silverlight
3194
Debug.Assert(
_ps
.encoding != null);
3195
Debug.Assert(
_ps
.bytes != null);
3196
ReadOnlySpan<byte> preamble =
_ps
.encoding.Preamble;
3197
if (
_ps
.bytes.AsSpan(0,
_ps
.bytesUsed).StartsWith(preamble))
3199
_ps
.bytePos = preamble.Length;
3206
Debug.Assert(
_ps
.encoding != null);
3207
if ((newEncoding.WebName !=
_ps
.encoding.WebName ||
_ps
.decoder is SafeAsciiDecoder) && !_afterResetState)
3209
Debug.Assert(
_ps
.stream != null);
3211
_ps
.appendMode = false;
3221
Debug.Assert(
_ps
.encoding != null);
3224
if (
_ps
.stream == null)
3226
return
_ps
.encoding;
3234
if (
_ps
.encoding.WebName != "utf-16BE" &&
3235
_ps
.encoding.WebName != "utf-16" &&
3247
return
_ps
.encoding;
3275
if (_afterResetState &&
_ps
.encoding.WebName != newEncoding.WebName)
3285
Debug.Assert(
_ps
.stream != null &&
_ps
.decoder != null &&
_ps
.bytes != null);
3286
Debug.Assert(
_ps
.appendMode, "UnDecodeChars cannot be called after ps.appendMode has been changed to false");
3288
Debug.Assert(
_ps
.charsUsed >=
_ps
.charPos, "The current position must be in the valid character range.");
3296
Debug.Assert(_charactersInDocument >=
_ps
.charsUsed -
_ps
.charPos,
3298
_charactersInDocument -=
_ps
.charsUsed -
_ps
.charPos;
3305
Debug.Assert(_charactersFromEntities >=
_ps
.charsUsed -
_ps
.charPos,
3307
_charactersFromEntities -=
_ps
.charsUsed -
_ps
.charPos;
3311
_ps
.bytePos = _documentStartBytePos; // byte position after preamble
3312
if (
_ps
.charPos > 0)
3314
Debug.Assert(
_ps
.encoding != null);
3315
Debug.Assert(
_ps
.chars != null);
3316
if (
_ps
.decoder is SafeAsciiDecoder)
3323
_ps
.bytePos +=
_ps
.charPos;
3324
int encodingByteCount =
_ps
.encoding.GetByteCount(
_ps
.chars, 0,
_ps
.charPos);
3325
if (encodingByteCount !=
_ps
.charPos)
3332
_ps
.bytePos +=
_ps
.encoding.GetByteCount(
_ps
.chars, 0,
_ps
.charPos);
3336
_ps
.charsUsed =
_ps
.charPos;
3337
_ps
.isEof = false;
3353
if (
_ps
.isEof)
3358
Debug.Assert(
_ps
.chars != null);
3360
if (
_ps
.appendMode)
3363
if (
_ps
.charsUsed ==
_ps
.chars.Length - 1)
3371
char[] newChars = new char[
_ps
.chars.Length * 2];
3372
BlockCopyChars(
_ps
.chars, 0, newChars, 0,
_ps
.chars.Length);
3373
_ps
.chars = newChars;
3376
if (
_ps
.stream != null)
3379
if (
_ps
.bytesUsed -
_ps
.bytePos < MaxByteSequenceLen)
3381
Debug.Assert(
_ps
.bytes != null);
3382
if (
_ps
.bytes.Length -
_ps
.bytesUsed < MaxByteSequenceLen)
3384
byte[] newBytes = new byte[
_ps
.bytes.Length * 2];
3385
BlockCopy(
_ps
.bytes, 0, newBytes, 0,
_ps
.bytesUsed);
3386
_ps
.bytes = newBytes;
3391
charsRead =
_ps
.chars.Length -
_ps
.charsUsed - 1;
3399
int charsLen =
_ps
.chars.Length;
3400
if (charsLen -
_ps
.charsUsed <= charsLen / 2)
3409
int copyCharsCount =
_ps
.charsUsed -
_ps
.charPos;
3412
_ps
.lineStartPos -=
_ps
.charPos;
3415
BlockCopyChars(
_ps
.chars,
_ps
.charPos,
_ps
.chars, 0, copyCharsCount);
3417
_ps
.charPos = 0;
3418
_ps
.charsUsed = copyCharsCount;
3422
char[] newChars = new char[
_ps
.chars.Length * 2];
3423
BlockCopyChars(
_ps
.chars, 0, newChars, 0,
_ps
.chars.Length);
3424
_ps
.chars = newChars;
3428
if (
_ps
.stream != null)
3431
int bytesLeft =
_ps
.bytesUsed -
_ps
.bytePos;
3436
_ps
.bytesUsed = 0;
3440
Debug.Assert(
_ps
.bytes != null);
3441
BlockCopy(
_ps
.bytes,
_ps
.bytePos,
_ps
.bytes, 0, bytesLeft);
3442
_ps
.bytesUsed = bytesLeft;
3445
_ps
.bytePos = 0;
3448
charsRead =
_ps
.chars.Length -
_ps
.charsUsed - 1;
3451
if (
_ps
.stream != null)
3453
if (!
_ps
.isStreamEof)
3455
Debug.Assert(
_ps
.bytes != null);
3458
if (
_ps
.bytePos ==
_ps
.bytesUsed &&
_ps
.bytes.Length -
_ps
.bytesUsed > 0)
3460
int read =
_ps
.stream.Read(
_ps
.bytes,
_ps
.bytesUsed,
_ps
.bytes.Length -
_ps
.bytesUsed);
3463
_ps
.isStreamEof = true;
3465
_ps
.bytesUsed += read;
3469
int originalBytePos =
_ps
.bytePos;
3473
if (charsRead == 0 &&
_ps
.bytePos != originalBytePos)
3479
else if (
_ps
.textReader != null)
3482
charsRead =
_ps
.textReader.Read(
_ps
.chars,
_ps
.charsUsed,
_ps
.chars.Length -
_ps
.charsUsed - 1);
3483
_ps
.charsUsed += charsRead;
3494
Debug.Assert(
_ps
.charsUsed <
_ps
.chars.Length);
3495
_ps
.isEof = true;
3498
_ps
.chars[
_ps
.charsUsed] = (char)0;
3505
Debug.Assert(
_ps
.stream != null &&
_ps
.decoder != null &&
_ps
.bytes != null);
3506
Debug.Assert(
_ps
.chars != null);
3507
Debug.Assert(maxCharsCount <=
_ps
.chars.Length -
_ps
.charsUsed - 1);
3510
int bytesCount =
_ps
.bytesUsed -
_ps
.bytePos;
3521
_ps
.decoder.Convert(
_ps
.bytes,
_ps
.bytePos, bytesCount,
_ps
.chars,
_ps
.charsUsed, maxCharsCount, false, out bytesCount, out charsCount, out completed);
3529
_ps
.bytePos += bytesCount;
3530
_ps
.charsUsed += charsCount;
3546
Debug.Assert(
_ps
.decoder != null);
3547
Debug.Assert(
_ps
.bytes != null);
3548
Debug.Assert(
_ps
.chars != null);
3549
_ps
.decoder.Convert(
_ps
.bytes,
_ps
.bytePos + bytesDecoded, 1,
_ps
.chars,
_ps
.charsUsed + charsDecoded, 2, false, out bDec, out chDec, out completed);
3562
Throw(
_ps
.charsUsed, SR.Xml_InvalidCharInThisEncoding);
3581
_ps
.Close(closeInput);
3596
Debug.Assert(
_ps
.chars != null);
3597
BlockCopyChars(
_ps
.chars, sourcePos,
_ps
.chars, destPos, count);
3603
while (
_ps
.charsUsed -
_ps
.charPos < 6)
3611
if (!
_ps
.chars.AsSpan(
_ps
.charPos).StartsWith(XmlDeclarationBeginning) ||
3612
XmlCharType.IsNameSingleChar(
_ps
.chars![
_ps
.charPos + 5]))
3619
_curNode.SetLineInfo(
_ps
.LineNo,
_ps
.LinePos + 2);
3623
_ps
.charPos += 5;
3639
if (
_ps
.chars[
_ps
.charPos] == '?')
3643
if (
_ps
.chars[
_ps
.charPos + 1] == '>')
3650
_ps
.charPos += 2;
3670
Debug.Assert(
_ps
.encoding != null);
3671
string encodingName =
_ps
.encoding.WebName;
3673
encodingName != "utf-16BE" && !(
_ps
.encoding is Ucs4Encoding))
3675
Throw(SR.Xml_EncodingSwitchAfterResetState, (
_ps
.encoding.GetByteCount("A") == 1) ? "UTF-8" : "UTF-16");
3678
if (
_ps
.decoder is SafeAsciiDecoder)
3687
_ps
.appendMode = false;
3690
else if (
_ps
.charPos + 1 ==
_ps
.charsUsed)
3709
switch (
_ps
.chars.AsSpan(
_ps
.charPos, nameEndPos -
_ps
.charPos))
3748
attr.SetLineInfo(
_ps
.LineNo,
_ps
.LinePos);
3750
sb.Append(
_ps
.chars,
_ps
.charPos, nameEndPos -
_ps
.charPos);
3751
_ps
.charPos = nameEndPos;
3754
if (
_ps
.chars[
_ps
.charPos] != '=')
3757
if (
_ps
.chars[
_ps
.charPos] != '=')
3763
_ps
.charPos++;
3765
char quoteChar =
_ps
.chars[
_ps
.charPos];
3769
quoteChar =
_ps
.chars[
_ps
.charPos];
3776
_ps
.charPos++;
3781
attr.SetLineInfo2(
_ps
.LineNo,
_ps
.LinePos);
3785
int pos =
_ps
.charPos;
3788
chars =
_ps
.chars;
3794
if (
_ps
.chars[pos] == quoteChar)
3801
if (
_ps
.chars.AsSpan(
_ps
.charPos).StartsWith("1.0"))
3806
attr.SetValue(
_ps
.chars,
_ps
.charPos, pos -
_ps
.charPos);
3812
string badVersion = new string(
_ps
.chars,
_ps
.charPos, pos -
_ps
.charPos);
3817
string encName = new string(
_ps
.chars,
_ps
.charPos, pos -
_ps
.charPos);
3827
switch (
_ps
.chars.AsSpan(
_ps
.charPos, pos -
_ps
.charPos))
3837
Throw(SR.Xml_InvalidXmlDecl,
_ps
.LineNo,
_ps
.LinePos - 1);
3843
attr.SetValue(
_ps
.chars,
_ps
.charPos, pos -
_ps
.charPos);
3851
sb.Append(chars,
_ps
.charPos, pos -
_ps
.charPos);
3853
_ps
.charPos = pos + 1;
3856
else if (pos ==
_ps
.charsUsed)
3873
if (
_ps
.isEof || ReadData() == 0)
3888
Debug.Assert(
_ps
.encoding != null);
3889
string encodingName =
_ps
.encoding.WebName;
3891
encodingName != "utf-16BE" && !(
_ps
.encoding is Ucs4Encoding))
3893
Throw(SR.Xml_EncodingSwitchAfterResetState, (
_ps
.encoding.GetByteCount("A") == 1) ? "UTF-8" : "UTF-16");
3896
if (
_ps
.decoder is SafeAsciiDecoder)
3900
_ps
.appendMode = false;
3911
int pos =
_ps
.charPos;
3912
Debug.Assert(
_ps
.chars != null);
3913
char[] chars =
_ps
.chars;
3919
if (
_ps
.charsUsed - pos < 4) // minimum "<a/>"
3926
_ps
.charPos = pos + 1;
3934
if (
_ps
.charsUsed - pos < 2) // minimum characters expected "--"
3941
_ps
.charPos = pos + 2;
3959
if (
_ps
.charsUsed - pos < 6)
3965
_ps
.charPos = pos + 6;
3980
Throw(
_ps
.charPos, SR.Xml_InvalidRootData);
3989
_ps
.charPos = pos;
4025
_ps
.charPos = pos;
4066
else if (pos ==
_ps
.charsUsed || ((_v1Compat || mangoQuirks) && chars[pos] == 0x0))
4094
Debug.Assert(pos ==
_ps
.charsUsed && !
_ps
.isEof);
4136
int pos =
_ps
.charPos;
4137
Debug.Assert(
_ps
.chars != null);
4138
char[] chars =
_ps
.chars;
4148
_ps
.charPos = pos + 2;
4156
if (
_ps
.charsUsed - pos < 2)
4163
_ps
.charPos = pos + 2;
4179
if (
_ps
.charsUsed - pos < 6)
4185
_ps
.charPos = pos + 6;
4208
_ps
.charPos = pos + 2;
4213
if (pos + 1 ==
_ps
.charsUsed)
4220
_ps
.charPos = pos + 1;
4234
if (pos ==
_ps
.charsUsed)
4253
if (
_ps
.charsUsed -
_ps
.charPos != 0)
4279
Throw(
_ps
.charsUsed, SR.Xml_UnexpectedEOF1);
4303
Throw(
_ps
.charsUsed, SR.Xml_UnexpectedEOFInElementContent, _stringBuilder.ToString());
4310
int pos =
_ps
.charPos;
4311
Debug.Assert(
_ps
.chars != null);
4312
char[] chars =
_ps
.chars;
4315
_curNode.SetLineInfo(
_ps
.LineNo,
_ps
.LinePos);
4366
else if (pos + 1 <
_ps
.charsUsed)
4373
chars =
_ps
.chars;
4384
_nameTable.Add(chars,
_ps
.charPos, pos -
_ps
.charPos));
4388
int startPos =
_ps
.charPos;
4401
_nameTable.Add(chars,
_ps
.charPos, prefixLen),
4412
_ps
.charPos = pos;
4422
_ps
.charPos = pos + 1;
4428
if (pos + 1 ==
_ps
.charsUsed)
4430
_ps
.charPos = pos;
4435
pos =
_ps
.charPos;
4436
chars =
_ps
.chars;
4443
_ps
.charPos = pos + 2;
4453
Throw(pos, SR.Xml_BadNameChar, XmlException.BuildCharExceptionArgs(chars,
_ps
.charsUsed, pos));
4553
while (
_ps
.charsUsed -
_ps
.charPos < prefLen + locLen + 1)
4562
Debug.Assert(
_ps
.chars != null);
4563
char[] chars =
_ps
.chars;
4566
if (!chars.AsSpan(
_ps
.charPos).StartsWith(startTagNode.localName))
4574
int colonPos =
_ps
.charPos + prefLen;
4575
if (!chars.AsSpan(
_ps
.charPos).StartsWith(startTagNode.prefix) ||
4584
LineInfo endTagLineInfo = new LineInfo(
_ps
.lineNo,
_ps
.LinePos);
4589
pos =
_ps
.charPos + nameLen;
4590
chars =
_ps
.chars;
4592
if (pos ==
_ps
.charsUsed)
4619
else if (pos ==
_ps
.charsUsed && !
_ps
.isEof)
4633
else if (pos ==
_ps
.charsUsed)
4659
_ps
.charPos = pos + 1;
4673
Debug.Assert(
_ps
.chars != null);
4678
args[3] = new string(
_ps
.chars,
_ps
.charPos, endPos -
_ps
.charPos);
4691
int pos =
_ps
.charPos;
4692
Debug.Assert(
_ps
.chars != null);
4693
char[] chars =
_ps
.chars;
4718
else if (pos + 1 !=
_ps
.charsUsed)
4725
_ps
.charPos = pos;
4746
_ps
.charPos = pos + 1;
4754
if (pos + 1 ==
_ps
.charsUsed)
4760
_ps
.charPos = pos + 2;
4771
else if (pos ==
_ps
.charsUsed)
4777
Throw(pos, SR.Xml_BadStartNameChar, XmlException.BuildCharExceptionArgs(chars,
_ps
.charsUsed, pos));
4781
if (pos ==
_ps
.charPos)
4785
_ps
.charPos = pos;
4788
int attrNameLinePos =
_ps
.LinePos;
4791
int attrNameLineNo =
_ps
.LineNo;
4844
chars =
_ps
.chars;
4847
else if (pos + 1 >=
_ps
.charsUsed)
4850
chars =
_ps
.chars;
4854
attr.SetLineInfo(
_ps
.LineNo, attrNameLinePos);
4857
Debug.Assert(attrNameLineNo ==
_ps
.LineNo);
4863
_ps
.charPos = pos;
4865
pos =
_ps
.charPos;
4876
_ps
.charPos = pos;
4878
pos =
_ps
.charPos;
4886
_ps
.charPos = pos;
4889
attr.SetLineInfo2(
_ps
.LineNo,
_ps
.LinePos);
4903
string val = new string(chars,
_ps
.charPos, pos -
_ps
.charPos);
4907
attr.SetValue(chars,
_ps
.charPos, pos -
_ps
.charPos);
4909
_ps
.charPos = pos;
4914
pos =
_ps
.charPos;
4915
chars =
_ps
.chars;
4943
_ps
.lineNo -= lineNoDelta;
4946
pos =
_ps
.charPos;
4947
chars =
_ps
.chars;
5113
Debug.Assert(
_ps
.chars != null);
5114
char[] chars =
_ps
.chars;
5115
int attributeBaseEntityId =
_ps
.entityId;
5117
LineInfo valueChunkLineInfo = new LineInfo(
_ps
.lineNo,
_ps
.LinePos);
5130
if (pos -
_ps
.charPos > 0)
5132
_stringBuilder.Append(chars,
_ps
.charPos, pos -
_ps
.charPos);
5133
_ps
.charPos = pos;
5136
if (chars[pos] == quoteChar && attributeBaseEntityId ==
_ps
.entityId)
5151
_ps
.charPos++;
5160
_stringBuilder.Append(
_ps
.eolNormalized ? "\u0020\u0020" : "\u0020"); // CDATA normalization of 0xD 0xA
5161
_ps
.charPos = pos;
5164
else if (pos + 1 <
_ps
.charsUsed ||
_ps
.isEof)
5170
_ps
.charPos = pos;
5185
_ps
.charPos++;
5199
if (pos -
_ps
.charPos > 0)
5201
_stringBuilder.Append(chars,
_ps
.charPos, pos -
_ps
.charPos);
5203
_ps
.charPos = pos;
5205
int enclosingEntityId =
_ps
.entityId;
5206
LineInfo entityLineInfo = new LineInfo(
_ps
.lineNo,
_ps
.LinePos + 1);
5214
if (_parsingMode == ParsingMode.Full &&
_ps
.entityId == attributeBaseEntityId)
5228
_ps
.charPos++;
5245
valueChunkLineInfo.Set(
_ps
.LineNo,
_ps
.LinePos);
5251
_ps
.charPos++;
5254
pos =
_ps
.charPos;
5275
Debug.Assert(
_ps
.entity != null);
5276
entityChunk.SetNamedNode(XmlNodeType.EntityReference,
_ps
.entity.Name);
5284
pos =
_ps
.charPos;
5287
pos =
_ps
.charPos;
5290
chars =
_ps
.chars;
5294
if (pos ==
_ps
.charsUsed)
5304
if (pos + 1 ==
_ps
.charsUsed)
5315
ThrowInvalidChar(chars,
_ps
.charsUsed, pos);
5325
if (
_ps
.charsUsed -
_ps
.charPos > 0)
5327
if (
_ps
.chars[
_ps
.charPos] != (char)0xD)
5332
Debug.Assert(
_ps
.isEof);
5340
if (attributeBaseEntityId !=
_ps
.entityId)
5354
if (attributeBaseEntityId ==
_ps
.entityId)
5357
valueChunkLineInfo.Set(
_ps
.LineNo,
_ps
.LinePos);
5362
pos =
_ps
.charPos;
5363
chars =
_ps
.chars;
5380
_ps
.charPos = pos + 1;
5418
_curNode.SetLineInfo(
_ps
.LineNo,
_ps
.LinePos);
5436
Debug.Assert(
_ps
.chars != null);
5437
_curNode.SetValueNode(nodeType,
_ps
.chars, startPos, endPos - startPos);
5450
_stringBuilder.Append(
_ps
.chars, startPos, endPos - startPos);
5456
_stringBuilder.Append(
_ps
.chars, startPos, endPos - startPos);
5481
Debug.Assert(
_ps
.chars != null);
5482
_curNode.SetValueNode(XmlNodeType.Text,
_ps
.chars, startPos, endPos - startPos);
5491
_stringBuilder.Append(
_ps
.chars, startPos, endPos - startPos);
5498
_stringBuilder.Append(
_ps
.chars, startPos, endPos - startPos);
5556
Debug.Assert(
_ps
.chars != null);
5557
char[] chars =
_ps
.chars;
5558
int pos =
_ps
.charPos;
5586
if (!
_ps
.eolNormalized && _parsingMode == ParsingMode.Full)
5588
if (pos -
_ps
.charPos > 0)
5604
_ps
.charPos++;
5609
else if (pos + 1 <
_ps
.charsUsed ||
_ps
.isEof)
5611
if (!
_ps
.eolNormalized)
5649
if (pos >
_ps
.charPos)
5670
if (!XmlCharType.IsWhiteSpace(
_ps
.chars[pos - 1]))
5676
pos =
_ps
.charPos;
5679
chars =
_ps
.chars;
5683
if (
_ps
.charsUsed - pos < 3 && !
_ps
.isEof)
5696
if (pos ==
_ps
.charsUsed)
5706
if (pos + 1 ==
_ps
.charsUsed)
5718
int offset = pos -
_ps
.charPos;
5721
pos =
_ps
.charPos + offset;
5726
ThrowInvalidChar(
_ps
.chars,
_ps
.charsUsed,
_ps
.charPos + offset);
5733
if (pos >
_ps
.charPos)
5740
if (
_ps
.charsUsed -
_ps
.charPos > 0)
5742
if (
_ps
.chars[
_ps
.charPos] != (char)0xD &&
_ps
.chars[
_ps
.charPos] != ']')
5746
Debug.Assert(
_ps
.isEof);
5765
pos =
_ps
.charPos;
5766
chars =
_ps
.chars;
5778
startPos =
_ps
.charPos;
5780
_ps
.charPos = pos;
5799
_stringBuilder.Append(
_ps
.chars, startPos, endPos - startPos);
5801
_stringBuilder.Append(
_ps
.chars, startPos, endPos - startPos);
5921
Debug.Assert(
_ps
.chars != null);
5925
if (
_ps
.chars[
_ps
.charPos] == '<' ||
_ps
.charsUsed -
_ps
.charPos == 0 || ZeroEndingStream(
_ps
.charPos))
5932
_curNode.SetLineInfo(
_ps
.LineNo,
_ps
.LinePos);
5934
if (
_ps
.chars[
_ps
.charPos] == '<' ||
_ps
.charsUsed -
_ps
.charPos == 0 || ZeroEndingStream(
_ps
.charPos))
5946
if (XmlCharType.IsCharData(
_ps
.chars[
_ps
.charPos]))
5952
ThrowInvalidChar(
_ps
.chars,
_ps
.charsUsed,
_ps
.charPos);
5959
Debug.Assert(
_ps
.chars != null);
5960
Debug.Assert(
_ps
.chars[
_ps
.charPos] == '&');
5961
_ps
.charPos++;
5963
_curNode.SetLineInfo(
_ps
.LineNo,
_ps
.LinePos);
5969
Debug.Assert(
_ps
.chars != null);
5970
Debug.Assert(
_ps
.chars[
_ps
.charPos] == '&');
5972
if (
_ps
.charPos + 1 ==
_ps
.charsUsed)
5981
if (
_ps
.chars[
_ps
.charPos + 1] == '#')
6009
_ps
.charPos++;
6010
int savedLinePos =
_ps
.LinePos;
6017
Throw(SR.Xml_ErrorParsingEntityName,
_ps
.LineNo, savedLinePos);
6022
if (
_ps
.chars[endPos] != ';')
6027
int entityLinePos =
_ps
.LinePos;
6028
string entityName = _nameTable.Add(
_ps
.chars,
_ps
.charPos, endPos -
_ps
.charPos);
6029
_ps
.charPos = endPos + 1;
6033
_reportedBaseUri =
_ps
.baseUriStr;
6034
_reportedEncoding =
_ps
.encoding;
6060
Throw(SR.Xml_UndeclaredEntity, name,
_ps
.LineNo, entityStartLinePos);
6074
Throw(SR.Xml_UnparsedEntityRef, name,
_ps
.LineNo, entityStartLinePos);
6079
Throw(SR.Xml_ExternalEntityInStandAloneDocument, entity.Name,
_ps
.LineNo, entityStartLinePos);
6086
Throw(SR.Xml_ExternalEntityInAttValue, name,
_ps
.LineNo, entityStartLinePos);
6100
_curNode.entityId =
_ps
.entityId;
6108
_curNode.entityId =
_ps
.entityId;
6121
_curNode.entityId =
_ps
.entityId;
6143
if (
_ps
.entityResolvedManually)
6149
if (
_ps
.entityId != _nodes[_index].entityId)
6155
_lastEntity =
_ps
.entity; // save last entity for the EndEntity node
6164
if (
_ps
.entityId != _nodes[_index].entityId)
6172
_reportedEncoding =
_ps
.encoding;
6173
_reportedBaseUri =
_ps
.baseUriStr;
6182
_reportedEncoding =
_ps
.encoding;
6183
_reportedBaseUri =
_ps
.baseUriStr;
6188
_curNode.lineInfo.Set(
_ps
.lineNo,
_ps
.LinePos - 1);
6217
_curNode.SetLineInfo(
_ps
.LineNo,
_ps
.LinePos);
6224
Debug.Assert(
_ps
.chars != null);
6225
string target = _nameTable.Add(
_ps
.chars,
_ps
.charPos, nameEndPos -
_ps
.charPos);
6231
_ps
.charPos = nameEndPos;
6246
char ch =
_ps
.chars[
_ps
.charPos];
6247
Debug.Assert(
_ps
.charPos <
_ps
.charsUsed);
6250
if (
_ps
.charsUsed -
_ps
.charPos < 2)
6254
if (ch != '?' ||
_ps
.chars[
_ps
.charPos + 1] != '>')
6256
Throw(SR.Xml_BadNameChar, XmlException.BuildCharExceptionArgs(
_ps
.chars,
_ps
.charsUsed,
_ps
.charPos));
6272
_curNode.SetValue(
_ps
.chars, startPos, endPos - startPos);
6277
piInDtdStringBuilder.Append(
_ps
.chars, startPos, endPos - startPos);
6300
sb.Append(
_ps
.chars, startPos, endPos - startPos);
6302
sb.Append(
_ps
.chars, startPos, endPos - startPos);
6317
if (
_ps
.charsUsed -
_ps
.charPos < 2)
6321
Throw(
_ps
.charsUsed, SR.Xml_UnexpectedEOF, "PI");
6325
Debug.Assert(
_ps
.chars != null);
6326
int pos =
_ps
.charPos;
6327
char[] chars =
_ps
.chars;
6347
Debug.Assert(!
_ps
.eolNormalized);
6355
outStartPos =
_ps
.charPos;
6356
_ps
.charPos = pos + 2;
6359
else if (pos + 1 ==
_ps
.charsUsed)
6376
if (!
_ps
.eolNormalized && _parsingMode == ParsingMode.Full)
6379
if (pos -
_ps
.charPos > 0)
6395
_ps
.charPos++;
6400
else if (pos + 1 <
_ps
.charsUsed ||
_ps
.isEof)
6402
if (!
_ps
.eolNormalized)
6422
if (pos ==
_ps
.charsUsed)
6432
if (pos + 1 ==
_ps
.charsUsed)
6443
ThrowInvalidChar(chars,
_ps
.charsUsed, pos);
6459
outStartPos =
_ps
.charPos;
6460
_ps
.charPos = pos;
6493
_curNode.SetLineInfo(
_ps
.LineNo,
_ps
.LinePos);
6497
Debug.Assert(
_ps
.chars != null);
6498
_curNode.SetValueNode(type,
_ps
.chars, startPos, endPos - startPos);
6504
_stringBuilder.Append(
_ps
.chars, startPos, endPos - startPos);
6507
_stringBuilder.Append(
_ps
.chars, startPos, endPos - startPos);
6521
if (
_ps
.charsUsed -
_ps
.charPos < 3)
6530
Debug.Assert(
_ps
.chars != null);
6531
int pos =
_ps
.charPos;
6532
char[] chars =
_ps
.chars;
6554
Debug.Assert(!
_ps
.eolNormalized);
6562
outStartPos =
_ps
.charPos;
6563
_ps
.charPos = pos + 3;
6566
else if (pos + 2 ==
_ps
.charsUsed)
6575
else if (pos + 1 ==
_ps
.charsUsed)
6595
if (!
_ps
.eolNormalized && _parsingMode == ParsingMode.Full)
6597
if (pos -
_ps
.charPos > 0)
6613
_ps
.charPos++;
6618
else if (pos + 1 <
_ps
.charsUsed ||
_ps
.isEof)
6620
if (!
_ps
.eolNormalized)
6640
if (pos ==
_ps
.charsUsed)
6648
if (pos + 1 ==
_ps
.charsUsed)
6659
ThrowInvalidChar(chars,
_ps
.charsUsed, pos);
6674
outStartPos =
_ps
.charPos;
6676
_ps
.charPos = pos;
6690
while (
_ps
.charsUsed -
_ps
.charPos < 8)
6698
if (!
_ps
.chars.AsSpan(
_ps
.charPos).StartsWith("DOCTYPE"))
6703
Debug.Assert(
_ps
.chars != null);
6704
if (!XmlCharType.IsWhiteSpace(
_ps
.chars[
_ps
.charPos + 7]))
6706
ThrowExpectingWhitespace(
_ps
.charPos + 7);
6711
Throw(
_ps
.charPos - 2, SR.Xml_MultipleDTDsProvided); // position just before <!DOCTYPE
6716
Throw(
_ps
.charPos - 2, SR.Xml_DtdAfterRootElement);
6719
_ps
.charPos += 8;
6725
_curNode.SetLineInfo(
_ps
.LineNo,
_ps
.LinePos);
6762
_ps
.charPos = pos;
6768
Debug.Assert(
_ps
.chars != null);
6769
if (
_ps
.chars[
_ps
.charPos] == 'P')
6772
while (
_ps
.charsUsed -
_ps
.charPos < 6)
6780
if (!
_ps
.chars.AsSpan(
_ps
.charPos).StartsWith("PUBLIC"))
6784
_ps
.charPos += 6;
6789
ThrowExpectingWhitespace(
_ps
.charPos);
6798
ThrowExpectingWhitespace(
_ps
.charPos);
6806
else if (
_ps
.chars[
_ps
.charPos] == 'S')
6809
while (
_ps
.charsUsed -
_ps
.charPos < 6)
6817
if (!
_ps
.chars.AsSpan(
_ps
.charPos).StartsWith("SYSTEM"))
6821
_ps
.charPos += 6;
6826
ThrowExpectingWhitespace(
_ps
.charPos);
6834
else if (
_ps
.chars[
_ps
.charPos] != '[' &&
_ps
.chars[
_ps
.charPos] != '>')
6840
if (
_ps
.chars[
_ps
.charPos] == '[')
6842
_ps
.charPos++;
6847
if (
_ps
.chars[
_ps
.charPos] != '>')
6852
else if (
_ps
.chars[
_ps
.charPos] == '>')
6860
_ps
.charPos++;
6865
Debug.Assert(
_ps
.chars != null);
6867
char quoteChar =
_ps
.chars[
_ps
.charPos];
6873
_ps
.charPos++;
6884
Debug.Assert(
_ps
.chars != null);
6885
char[] chars =
_ps
.chars;
6886
int pos =
_ps
.charPos;
6900
_ps
.charPos = pos + 1;
6905
_ps
.charPos = pos;
6918
else if (pos + 1 <
_ps
.charsUsed ||
_ps
.isEof)
6944
if (pos + 3 >=
_ps
.charsUsed && !
_ps
.isEof)
6959
else if (pos + 1 >=
_ps
.charsUsed && !
_ps
.isEof)
6969
if (pos + 2 >=
_ps
.charsUsed && !
_ps
.isEof)
6987
if (pos + 1 >=
_ps
.charsUsed && !
_ps
.isEof)
7028
if (pos ==
_ps
.charsUsed)
7038
if (pos + 1 ==
_ps
.charsUsed)
7049
ThrowInvalidChar(chars,
_ps
.charsUsed, pos);
7058
if (
_ps
.charsUsed -
_ps
.charPos > 0)
7060
if (
_ps
.chars[
_ps
.charPos] != (char)0xD)
7065
Debug.Assert(
_ps
.isEof);
7072
chars =
_ps
.chars;
7073
pos =
_ps
.charPos;
7079
int pos =
_ps
.charPos;
7081
Debug.Assert(
_ps
.chars != null);
7082
char[] chars =
_ps
.chars;
7097
int tmp1 = pos -
_ps
.charPos;
7098
if (sb != null && !
_ps
.eolNormalized)
7102
sb.Append(chars,
_ps
.charPos, tmp1);
7105
_ps
.charPos = pos + 1;
7109
else if (pos + 1 <
_ps
.charsUsed ||
_ps
.isEof)
7111
if (!
_ps
.eolNormalized)
7128
if (pos ==
_ps
.charsUsed)
7134
int tmp2 = pos -
_ps
.charPos;
7137
sb?.Append(
_ps
.chars,
_ps
.charPos, tmp2);
7138
_ps
.charPos = pos;
7147
int tmp3 = pos -
_ps
.charPos;
7150
sb?.Append(
_ps
.chars,
_ps
.charPos, tmp3);
7151
_ps
.charPos = pos;
7157
if (
_ps
.charsUsed -
_ps
.charPos == 0)
7161
if (
_ps
.chars[
_ps
.charPos] != (char)0xD)
7166
Debug.Assert(
_ps
.isEof);
7168
pos =
_ps
.charPos;
7169
chars =
_ps
.chars;
7175
Debug.Assert(
_ps
.chars != null);
7176
Debug.Assert(
_ps
.chars[startPos] == '&');
7177
if (
_ps
.chars[startPos + 1] == '#')
7200
switch (newPos = ParseNumericCharRefInline(
_ps
.charPos, expand, internalSubsetBuilder, out charCount, out entityType))
7209
Debug.Assert(
_ps
.chars != null);
7210
Debug.Assert(
_ps
.chars[
_ps
.charPos] == '&');
7215
_ps
.charPos = newPos - charCount;
7230
Debug.Assert(
_ps
.chars != null);
7231
Debug.Assert(
_ps
.chars[startPos] == '&' &&
_ps
.chars[startPos + 1] == '#');
7239
chars =
_ps
.chars;
7261
else if (pos <
_ps
.charsUsed)
7281
_ps
.charPos = pos;
7290
if (pos ==
_ps
.charsUsed)
7308
Throw((
_ps
.chars[startPos + 2] == 'x') ? startPos + 3 : startPos + 2, SR.Xml_InvalidCharacter, XmlException.BuildCharExceptionArgs(ch, '\0'));
7313
internalSubsetBuilder?.Append(
_ps
.chars,
_ps
.charPos, pos -
_ps
.charPos + 1);
7334
Throw((
_ps
.chars[startPos + 2] == 'x') ? startPos + 3 : startPos + 2, SR.Xml_InvalidCharacter, XmlException.BuildCharExceptionArgs(high, low));
7341
internalSubsetBuilder?.Append(
_ps
.chars,
_ps
.charPos, pos -
_ps
.charPos + 1);
7361
switch (newPos = ParseNamedCharRefInline(
_ps
.charPos, expand, internalSubsetBuilder))
7372
Debug.Assert(
_ps
.chars != null);
7373
Debug.Assert(
_ps
.chars[
_ps
.charPos] == '&');
7378
_ps
.charPos = newPos - 1;
7393
Debug.Assert(startPos <
_ps
.charsUsed);
7394
Debug.Assert(
_ps
.chars != null);
7395
Debug.Assert(
_ps
.chars[startPos] == '&');
7396
Debug.Assert(
_ps
.chars[startPos + 1] != '#');
7399
char[] chars =
_ps
.chars;
7410
if (
_ps
.charsUsed - pos >= 3)
7427
if (
_ps
.charsUsed - pos >= 4)
7442
else if (pos <
_ps
.charsUsed)
7449
if (
_ps
.charsUsed - pos >= 5)
7466
if (
_ps
.charsUsed - pos >= 3)
7482
if (
_ps
.charsUsed - pos >= 3)
7507
internalSubsetBuilder?.Append(
_ps
.chars,
_ps
.charPos, pos -
_ps
.charPos);
7508
_ps
.chars[pos - 1] = ch;
7526
int pos =
_ps
.charPos + startOffset;
7529
Debug.Assert(
_ps
.chars != null);
7530
char[] chars =
_ps
.chars;
7539
if (pos + 1 >=
_ps
.charsUsed)
7549
Throw(pos, SR.Xml_BadStartNameChar, XmlException.BuildCharExceptionArgs(chars,
_ps
.charsUsed, pos));
7576
colonOffset = pos -
_ps
.charPos;
7582
colonOffset = pos -
_ps
.charPos;
7588
else if (pos ==
_ps
.charsUsed)
7592
Debug.Assert(
_ps
.chars != null);
7593
chars =
_ps
.chars;
7600
colonPos = (colonOffset == -1) ? -1 :
_ps
.charPos + colonOffset;
7606
int offset = pos -
_ps
.charPos;
7608
pos =
_ps
.charPos + offset;
7625
Debug.Assert(
_ps
.chars != null);
7628
if (
_ps
.chars[endPos] != ';')
7633
string entityName = _nameTable.Add(
_ps
.chars,
_ps
.charPos, endPos -
_ps
.charPos);
7634
_ps
.charPos = endPos + 1;
7678
Debug.Assert(
_ps
.chars != null);
7683
string localName = _nameTable.Add(
_ps
.chars,
_ps
.charPos, endNamePos -
_ps
.charPos);
7689
int startPos =
_ps
.charPos;
7691
if (prefixLen == _lastPrefix.Length &&
_ps
.chars.AsSpan(
_ps
.charPos).StartsWith(_lastPrefix))
7693
return AddAttribute(_nameTable.Add(
_ps
.chars, colonPos + 1, endNamePos - colonPos - 1),
7699
string prefix = _nameTable.Add(
_ps
.chars, startPos, prefixLen);
7701
return AddAttribute(_nameTable.Add(
_ps
.chars, colonPos + 1, endNamePos - colonPos - 1),
7760
_ps
.lineNo++;
7761
_ps
.lineStartPos = pos - 1;
7766
Debug.Assert(
_ps
.isEof);
7769
_curNode.SetLineInfo(
_ps
.LineNo,
_ps
.LinePos);
8019
Debug.Assert(
_ps
.appendMode);
8020
int initialPos =
_ps
.charPos;
8028
_ps
.charPos = initialPos;
8035
Encoding? enc =
_ps
.encoding;
8052
Encoding? enc =
_ps
.encoding;
8060
_ps
.lineNo = entity.LineNumber;
8061
_ps
.lineStartPos = -entity.LinePosition - 1;
8063
_ps
.eolNormalized = true;
8070
_ps
.stream?.Dispose();
8074
_curNode.entityId =
_ps
.entityId;
8090
_ps
.entity = entity;
8091
_ps
.entityId = _nextEntityId++;
8105
if (
_ps
.entity != null)
8107
_currentEntities!.Remove(
_ps
.entity);
8125
_parsingStatesStack[_parsingStatesStackTop] =
_ps
;
8127
_ps
.Clear();
8134
_ps
.Close(true);
8146
_incReadLeftStartPos =
_ps
.charPos;
8147
_incReadLeftEndPos =
_ps
.charPos;
8148
_incReadLineInfo.Set(
_ps
.LineNo,
_ps
.LinePos);
8191
Debug.Assert(
_ps
.chars != null);
8201
count = _incReadDecoder.Decode(
_ps
.chars, _incReadLeftStartPos, charsLeft);
8240
Debug.Assert(
_ps
.chars.AsSpan(
_ps
.charPos - 2).StartsWith("?>"));
8241
_ps
.charPos -= 2;
8248
Debug.Assert(
_ps
.chars.AsSpan(
_ps
.charPos - 3).StartsWith("-->"));
8249
_ps
.charPos -= 3;
8256
Debug.Assert(
_ps
.chars.AsSpan(
_ps
.charPos - 3).StartsWith("]]>"));
8257
_ps
.charPos -= 3;
8285
char[] chars =
_ps
.chars;
8286
startPos =
_ps
.charPos;
8291
_incReadLineInfo.Set(
_ps
.LineNo,
_ps
.LinePos);
8332
else if (pos + 1 <
_ps
.charsUsed)
8349
if (
_ps
.charsUsed - pos < 2)
8362
if (
_ps
.charsUsed - pos < 4)
8372
if (
_ps
.charsUsed - pos < 9)
8390
Debug.Assert(
_ps
.charPos - pos == 0);
8391
Debug.Assert(
_ps
.charPos - startPos == 0);
8396
if ((endPos -
_ps
.charPos - 2) == checkName.Length && chars.AsSpan(
_ps
.charPos + 2).StartsWith(checkName) &&
8397
(
_ps
.chars[endPos] == '>' || XmlCharType.IsWhiteSpace(
_ps
.chars[endPos])))
8405
_ps
.charPos = endPos;
8406
if (XmlCharType.IsWhiteSpace(
_ps
.chars[endPos]))
8410
if (
_ps
.chars[
_ps
.charPos] != '>')
8414
_ps
.charPos++;
8422
startPos =
_ps
.charPos;
8423
chars =
_ps
.chars;
8430
Debug.Assert(
_ps
.charPos - pos == 0);
8431
Debug.Assert(
_ps
.charPos - startPos == 0);
8435
if (endPos -
_ps
.charPos - 1 == _curNode.localName.Length &&
_ps
.chars.AsSpan(
_ps
.charPos + 1).StartsWith(_curNode.localName) &&
8436
(
_ps
.chars[endPos] == '>' ||
_ps
.chars[endPos] == '/' || XmlCharType.IsWhiteSpace(
_ps
.chars[endPos])))
8444
startPos =
_ps
.charPos;
8445
chars =
_ps
.chars;
8454
if (
_ps
.charsUsed - pos < 2)
8493
if (pos ==
_ps
.charsUsed)
8510
_ps
.charPos = pos;
8520
count = _incReadDecoder.Decode(
_ps
.chars, startPos, charsParsed);
8558
ParseAttributeValueSlow(
_ps
.charPos, ' ', _curNode); // The quote char is intentionally empty (space) because we need to parse ' and " into the attribute value
8581
Debug.Assert(
_ps
.chars != null);
8583
char[] chars =
_ps
.chars;
8584
int pos =
_ps
.charPos;
8587
_curNode.SetLineInfo(
_ps
.LineNo,
_ps
.LinePos);
8607
Debug.Assert(
_ps
.eolNormalized, "Entity replacement text for attribute values should be EOL-normalized!");
8630
if (pos -
_ps
.charPos > 0)
8632
_stringBuilder.Append(chars,
_ps
.charPos, pos -
_ps
.charPos);
8635
_ps
.charPos = pos;
8643
chars =
_ps
.chars;
8644
if (_normalize && XmlCharType.IsWhiteSpace(chars[
_ps
.charPos]) && pos -
_ps
.charPos == 1)
8646
chars[
_ps
.charPos] = (char)0x20; // CDATA normalization of character references in entities
8653
_ps
.charPos++;
8665
chars =
_ps
.chars;
8669
if (pos ==
_ps
.charsUsed)
8679
if (pos + 1 ==
_ps
.charsUsed)
8692
ThrowInvalidChar(chars,
_ps
.charsUsed, pos);
8698
if (pos -
_ps
.charPos > 0)
8700
_stringBuilder.Append(chars,
_ps
.charPos, pos -
_ps
.charPos);
8701
_ps
.charPos = pos;
8725
pos =
_ps
.charPos;
8726
chars =
_ps
.chars;
8730
if (pos -
_ps
.charPos > 0)
8732
_stringBuilder.Append(chars,
_ps
.charPos, pos -
_ps
.charPos);
8733
_ps
.charPos = pos;
8765
_ps
.charPos = pos;
8789
_ps
.charPos = pos;
8795
if (
_ps
.charPos ==
_ps
.charsUsed)
8800
Debug.Assert(
_ps
.chars != null);
8802
if (XmlCharType.IsNCNameSingleChar(
_ps
.chars[
_ps
.charPos]))
8804
int pos =
_ps
.charPos + 1;
8805
while (XmlCharType.IsNCNameSingleChar(
_ps
.chars[pos]))
8809
return new string(
_ps
.chars,
_ps
.charPos, pos -
_ps
.charPos);
8813
Debug.Assert(
_ps
.charPos <
_ps
.charsUsed);
8814
return new string(
_ps
.chars,
_ps
.charPos, 1);
8878
Debug.Assert(
_ps
.chars != null);
8880
if (_v1Compat && pos ==
_ps
.charsUsed - 1 &&
_ps
.chars[pos] == (char)0 && ReadData() == 0 &&
_ps
.isStreamEof)
8882
_ps
.charsUsed--;
9388
_curNode.AdjustLineInfo(_readValueOffset,
_ps
.eolNormalized, ref _incReadLineInfo);
9402
Debug.Assert(
_ps
.chars != null);
9413
_incReadLineInfo.Set(
_ps
.LineNo,
_ps
.LinePos);
9418
charsRead = _incReadDecoder.Decode(
_ps
.chars, startPos, endPos - startPos);
9433
_curNode.SetValue(
_ps
.chars, startPos, endPos - startPos);
9435
AdjustLineInfo(
_ps
.chars, startPos - charsRead, startPos,
_ps
.eolNormalized, ref _incReadLineInfo);
System\Xml\Core\XmlTextReaderImplAsync.cs (656)
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)
1043
char[] newChars = new char[
_ps
.chars.Length * 2];
1044
BlockCopyChars(
_ps
.chars, 0, newChars, 0,
_ps
.chars.Length);
1045
_ps
.chars = newChars;
1048
if (
_ps
.stream != null)
1051
if (
_ps
.bytesUsed -
_ps
.bytePos < MaxByteSequenceLen)
1053
if (
_ps
.bytes!.Length -
_ps
.bytesUsed < MaxByteSequenceLen)
1055
byte[] newBytes = new byte[
_ps
.bytes.Length * 2];
1056
BlockCopy(
_ps
.bytes, 0, newBytes, 0,
_ps
.bytesUsed);
1057
_ps
.bytes = newBytes;
1062
charsRead =
_ps
.chars.Length -
_ps
.charsUsed - 1;
1070
int charsLen =
_ps
.chars.Length;
1071
if (charsLen -
_ps
.charsUsed <= charsLen / 2)
1080
int copyCharsCount =
_ps
.charsUsed -
_ps
.charPos;
1083
_ps
.lineStartPos -=
_ps
.charPos;
1086
BlockCopyChars(
_ps
.chars,
_ps
.charPos,
_ps
.chars, 0, copyCharsCount);
1088
_ps
.charPos = 0;
1089
_ps
.charsUsed = copyCharsCount;
1093
char[] newChars = new char[
_ps
.chars.Length * 2];
1094
BlockCopyChars(
_ps
.chars, 0, newChars, 0,
_ps
.chars.Length);
1095
_ps
.chars = newChars;
1099
if (
_ps
.stream != null)
1102
int bytesLeft =
_ps
.bytesUsed -
_ps
.bytePos;
1107
_ps
.bytesUsed = 0;
1111
BlockCopy(
_ps
.bytes!,
_ps
.bytePos,
_ps
.bytes!, 0, bytesLeft);
1112
_ps
.bytesUsed = bytesLeft;
1114
_ps
.bytePos = 0;
1117
charsRead =
_ps
.chars.Length -
_ps
.charsUsed - 1;
1120
if (
_ps
.stream != null)
1122
if (!
_ps
.isStreamEof)
1125
if (
_ps
.bytePos ==
_ps
.bytesUsed &&
_ps
.bytes!.Length -
_ps
.bytesUsed > 0)
1127
int read = await
_ps
.stream.ReadAsync(
_ps
.bytes.AsMemory(
_ps
.bytesUsed)).ConfigureAwait(false);
1130
_ps
.isStreamEof = true;
1132
_ps
.bytesUsed += read;
1136
int originalBytePos =
_ps
.bytePos;
1140
if (charsRead == 0 &&
_ps
.bytePos != originalBytePos)
1146
else if (
_ps
.textReader != null)
1149
charsRead = await
_ps
.textReader.ReadAsync(
_ps
.chars.AsMemory(
_ps
.charsUsed,
_ps
.chars.Length -
_ps
.charsUsed - 1)).ConfigureAwait(false);
1150
_ps
.charsUsed += charsRead;
1161
Debug.Assert(
_ps
.charsUsed <
_ps
.chars.Length);
1162
_ps
.isEof = true;
1164
_ps
.chars[
_ps
.charsUsed] = (char)0;
1171
while (
_ps
.charsUsed -
_ps
.charPos < 6)
1179
if (!
_ps
.chars.AsSpan(
_ps
.charPos).StartsWith(XmlDeclarationBeginning) ||
1180
XmlCharType.IsNameSingleChar(
_ps
.chars[
_ps
.charPos + 5]))
1187
_curNode.SetLineInfo(
_ps
.LineNo,
_ps
.LinePos + 2);
1190
_ps
.charPos += 5;
1206
if (
_ps
.chars[
_ps
.charPos] == '?')
1210
if (
_ps
.chars[
_ps
.charPos + 1] == '>')
1217
_ps
.charPos += 2;
1238
string encodingName =
_ps
.encoding!.WebName;
1240
encodingName != "utf-16BE" && !(
_ps
.encoding is Ucs4Encoding))
1242
Throw(SR.Xml_EncodingSwitchAfterResetState, (
_ps
.encoding.GetByteCount("A") == 1) ? "UTF-8" : "UTF-16");
1245
if (
_ps
.decoder is SafeAsciiDecoder)
1254
_ps
.appendMode = false;
1257
else if (
_ps
.charPos + 1 ==
_ps
.charsUsed)
1276
switch (
_ps
.chars.AsSpan(
_ps
.charPos, nameEndPos -
_ps
.charPos))
1313
attr!.SetLineInfo(
_ps
.LineNo,
_ps
.LinePos);
1315
sb.Append(
_ps
.chars,
_ps
.charPos, nameEndPos -
_ps
.charPos);
1316
_ps
.charPos = nameEndPos;
1319
if (
_ps
.chars[
_ps
.charPos] != '=')
1322
if (
_ps
.chars[
_ps
.charPos] != '=')
1328
_ps
.charPos++;
1330
char quoteChar =
_ps
.chars[
_ps
.charPos];
1334
quoteChar =
_ps
.chars[
_ps
.charPos];
1341
_ps
.charPos++;
1345
attr.SetLineInfo2(
_ps
.LineNo,
_ps
.LinePos);
1349
int pos =
_ps
.charPos;
1352
chars =
_ps
.chars;
1359
if (
_ps
.chars[pos] == quoteChar)
1366
if (
_ps
.chars.AsSpan(
_ps
.charPos).StartsWith("1.0"))
1370
attr!.SetValue(
_ps
.chars,
_ps
.charPos, pos -
_ps
.charPos);
1376
string badVersion = new string(
_ps
.chars,
_ps
.charPos, pos -
_ps
.charPos);
1381
string encName = new string(
_ps
.chars,
_ps
.charPos, pos -
_ps
.charPos);
1390
switch (
_ps
.chars.AsSpan(
_ps
.charPos, pos -
_ps
.charPos))
1400
Throw(SR.Xml_InvalidXmlDecl,
_ps
.LineNo,
_ps
.LinePos - 1);
1405
attr!.SetValue(
_ps
.chars,
_ps
.charPos, pos -
_ps
.charPos);
1413
sb.Append(chars,
_ps
.charPos, pos -
_ps
.charPos);
1415
_ps
.charPos = pos + 1;
1418
else if (pos ==
_ps
.charsUsed)
1435
if (
_ps
.isEof || await ReadDataAsync().ConfigureAwait(false) == 0)
1451
string encodingName =
_ps
.encoding!.WebName;
1453
encodingName != "utf-16BE" && !(
_ps
.encoding is Ucs4Encoding))
1455
Throw(SR.Xml_EncodingSwitchAfterResetState, (
_ps
.encoding.GetByteCount("A") == 1) ? "UTF-8" : "UTF-16");
1458
if (
_ps
.decoder is SafeAsciiDecoder)
1462
_ps
.appendMode = false;
1474
int pos =
_ps
.charPos;
1475
char[] chars =
_ps
.chars;
1481
if (
_ps
.charsUsed - pos < 4) // minimum "<a/>"
1488
_ps
.charPos = pos + 1;
1492
if (
_ps
.charsUsed - pos < 2) // minimum characters expected "--"
1499
_ps
.charPos = pos + 2;
1513
if (
_ps
.charsUsed - pos < 6)
1519
_ps
.charPos = pos + 6;
1529
Throw(
_ps
.charPos, SR.Xml_InvalidRootData);
1538
_ps
.charPos = pos;
1570
_ps
.charPos = pos;
1580
else if (pos ==
_ps
.charsUsed || (_v1Compat && chars[pos] == 0x0))
1597
Debug.Assert(pos ==
_ps
.charsUsed && !
_ps
.isEof);
1612
int pos =
_ps
.charPos;
1733
int pos =
_ps
.charPos;
1734
char[] chars =
_ps
.chars;
1744
_ps
.charPos = pos + 2;
1748
if (
_ps
.charsUsed - pos < 2)
1755
_ps
.charPos = pos + 2;
1767
if (
_ps
.charsUsed - pos < 6)
1773
_ps
.charPos = pos + 6;
1795
_ps
.charPos = pos + 2;
1799
if (pos + 1 ==
_ps
.charsUsed)
1806
_ps
.charPos = pos + 1;
1815
if (pos ==
_ps
.charsUsed)
1833
if (
_ps
.charsUsed -
_ps
.charPos != 0)
1858
int pos =
_ps
.charPos;
1859
char[] chars =
_ps
.chars;
1862
_curNode.SetLineInfo(
_ps
.LineNo,
_ps
.LinePos);
1913
else if (pos + 1 <
_ps
.charsUsed)
1951
char[] chars =
_ps
.chars;
1960
_nameTable.Add(chars,
_ps
.charPos, pos -
_ps
.charPos));
1964
int startPos =
_ps
.charPos;
1977
_nameTable.Add(chars,
_ps
.charPos, prefixLen),
1989
_ps
.charPos = pos;
2003
int pos =
_ps
.charPos;
2004
char[] chars =
_ps
.chars;
2009
_ps
.charPos = pos + 1;
2015
if (pos + 1 ==
_ps
.charsUsed)
2017
_ps
.charPos = pos;
2025
_ps
.charPos = pos + 2;
2035
Throw(pos, SR.Xml_BadNameChar, XmlException.BuildCharExceptionArgs(chars,
_ps
.charsUsed, pos));
2067
if (
_ps
.charsUsed -
_ps
.charPos < prefLen + locLen + 1)
2089
while (
_ps
.charsUsed -
_ps
.charPos < prefLen + locLen + 1)
2105
char[] chars =
_ps
.chars;
2108
if (!chars.AsSpan(
_ps
.charPos).StartsWith(startTagNode.localName))
2116
int colonPos =
_ps
.charPos + prefLen;
2117
if (!chars.AsSpan(
_ps
.charPos).StartsWith(startTagNode.prefix) ||
2125
LineInfo endTagLineInfo = new LineInfo(
_ps
.lineNo,
_ps
.LinePos);
2187
pos =
_ps
.charPos + nameLen;
2188
chars =
_ps
.chars;
2190
if (pos ==
_ps
.charsUsed)
2225
else if (pos ==
_ps
.charsUsed && !
_ps
.isEof)
2239
else if (pos ==
_ps
.charsUsed)
2260
_ps
.charPos = pos + 1;
2294
args[3] = new string(
_ps
.chars,
_ps
.charPos, endPos -
_ps
.charPos);
2307
int pos =
_ps
.charPos;
2308
char[] chars =
_ps
.chars;
2334
else if (pos + 1 !=
_ps
.charsUsed)
2341
_ps
.charPos = pos;
2362
_ps
.charPos = pos + 1;
2370
if (pos + 1 ==
_ps
.charsUsed)
2376
_ps
.charPos = pos + 2;
2387
else if (pos ==
_ps
.charsUsed)
2393
Throw(pos, SR.Xml_BadStartNameChar, XmlException.BuildCharExceptionArgs(chars,
_ps
.charsUsed, pos));
2397
if (pos ==
_ps
.charPos)
2401
_ps
.charPos = pos;
2404
int attrNameLinePos =
_ps
.LinePos;
2407
int attrNameLineNo =
_ps
.LineNo;
2466
chars =
_ps
.chars;
2469
else if (pos + 1 >=
_ps
.charsUsed)
2476
chars =
_ps
.chars;
2480
attr.SetLineInfo(
_ps
.LineNo, attrNameLinePos);
2483
Debug.Assert(attrNameLineNo ==
_ps
.LineNo);
2489
_ps
.charPos = pos;
2491
pos =
_ps
.charPos;
2502
_ps
.charPos = pos;
2504
pos =
_ps
.charPos;
2512
_ps
.charPos = pos;
2515
attr.SetLineInfo2(
_ps
.LineNo,
_ps
.LinePos);
2529
string val = new string(chars,
_ps
.charPos, pos -
_ps
.charPos);
2533
attr.SetValue(chars,
_ps
.charPos, pos -
_ps
.charPos);
2535
_ps
.charPos = pos;
2540
pos =
_ps
.charPos;
2541
chars =
_ps
.chars;
2569
_ps
.lineNo -= lineNoDelta;
2572
pos =
_ps
.charPos;
2573
chars =
_ps
.chars;
2606
char[] chars =
_ps
.chars;
2607
int attributeBaseEntityId =
_ps
.entityId;
2610
LineInfo valueChunkLineInfo = new LineInfo(
_ps
.lineNo,
_ps
.LinePos);
2623
if (pos -
_ps
.charPos > 0)
2625
_stringBuilder.Append(chars,
_ps
.charPos, pos -
_ps
.charPos);
2626
_ps
.charPos = pos;
2629
if (chars[pos] == quoteChar && attributeBaseEntityId ==
_ps
.entityId)
2644
_ps
.charPos++;
2653
_stringBuilder.Append(
_ps
.eolNormalized ? "\u0020\u0020" : "\u0020"); // CDATA normalization of 0xD 0xA
2654
_ps
.charPos = pos;
2657
else if (pos + 1 <
_ps
.charsUsed ||
_ps
.isEof)
2663
_ps
.charPos = pos;
2678
_ps
.charPos++;
2692
if (pos -
_ps
.charPos > 0)
2694
_stringBuilder.Append(chars,
_ps
.charPos, pos -
_ps
.charPos);
2696
_ps
.charPos = pos;
2699
int enclosingEntityId =
_ps
.entityId;
2700
LineInfo entityLineInfo = new LineInfo(
_ps
.lineNo,
_ps
.LinePos + 1);
2713
if (_parsingMode == ParsingMode.Full &&
_ps
.entityId == attributeBaseEntityId)
2727
_ps
.charPos++;
2744
valueChunkLineInfo.Set(
_ps
.LineNo,
_ps
.LinePos);
2750
_ps
.charPos++;
2753
pos =
_ps
.charPos;
2774
entityChunk.SetNamedNode(XmlNodeType.EntityReference,
_ps
.entity!.Name);
2782
pos =
_ps
.charPos;
2785
pos =
_ps
.charPos;
2788
chars =
_ps
.chars;
2792
if (pos ==
_ps
.charsUsed)
2802
if (pos + 1 ==
_ps
.charsUsed)
2813
ThrowInvalidChar(chars,
_ps
.charsUsed, pos);
2823
if (
_ps
.charsUsed -
_ps
.charPos > 0)
2825
if (
_ps
.chars[
_ps
.charPos] != (char)0xD)
2830
Debug.Assert(
_ps
.isEof);
2838
if (attributeBaseEntityId !=
_ps
.entityId)
2853
if (attributeBaseEntityId ==
_ps
.entityId)
2856
valueChunkLineInfo.Set(
_ps
.LineNo,
_ps
.LinePos);
2861
pos =
_ps
.charPos;
2862
chars =
_ps
.chars;
2880
_ps
.charPos = pos + 1;
2898
_curNode.SetLineInfo(
_ps
.LineNo,
_ps
.LinePos);
2930
_curNode.SetValueNode(nodeType,
_ps
.chars, startPos, endPos - startPos);
2966
_curNode.SetLineInfo(
_ps
.LineNo,
_ps
.LinePos);
2989
_curNode.SetValueNode(nodeType,
_ps
.chars, startPos, endPos - startPos);
3004
_stringBuilder.Append(
_ps
.chars, startPos, endPos - startPos);
3015
_stringBuilder.Append(
_ps
.chars, startPos, endPos - startPos);
3040
_curNode.SetValueNode(XmlNodeType.Text,
_ps
.chars, startPos, endPos - startPos);
3049
_stringBuilder.Append(
_ps
.chars, startPos, endPos - startPos);
3062
_stringBuilder.Append(
_ps
.chars, startPos, endPos - startPos);
3169
Task<(int, int, int, bool)> task = ParseTextAsync(outOrChars,
_ps
.chars,
_ps
.charPos, 0, -1, outOrChars);
3268
if (!
_ps
.eolNormalized && _parsingMode == ParsingMode.Full)
3270
if (pos -
_ps
.charPos > 0)
3286
_ps
.charPos++;
3291
else if (pos + 1 <
_ps
.charsUsed ||
_ps
.isEof)
3293
if (!
_ps
.eolNormalized)
3318
if (
_ps
.charsUsed - pos < 3 && !
_ps
.isEof)
3333
if (pos ==
_ps
.charsUsed)
3373
if (pos >
_ps
.charPos)
3403
if (!XmlCharType.IsWhiteSpace(
_ps
.chars[pos - 1]))
3409
pos =
_ps
.charPos;
3412
chars =
_ps
.chars;
3425
if (pos + 1 ==
_ps
.charsUsed)
3441
int offset = pos -
_ps
.charPos;
3444
chars =
_ps
.chars;
3445
pos =
_ps
.charPos + offset;
3452
ThrowInvalidChar(
_ps
.chars,
_ps
.charsUsed,
_ps
.charPos + offset);
3460
if (pos >
_ps
.charPos)
3469
if (
_ps
.charsUsed -
_ps
.charPos > 0)
3471
if (
_ps
.chars[
_ps
.charPos] != (char)0xD &&
_ps
.chars[
_ps
.charPos] != ']')
3475
Debug.Assert(
_ps
.isEof);
3499
pos =
_ps
.charPos;
3500
chars =
_ps
.chars;
3517
int startPos =
_ps
.charPos;
3519
_ps
.charPos = pos;
3546
_stringBuilder.Append(
_ps
.chars, startPos, endPos - startPos);
3553
_stringBuilder.Append(
_ps
.chars, startPos, endPos - startPos);
3684
if (
_ps
.chars[
_ps
.charPos] == '<' ||
_ps
.charsUsed -
_ps
.charPos == 0 || await ZeroEndingStreamAsync(
_ps
.charPos).ConfigureAwait(false))
3691
_curNode.SetLineInfo(
_ps
.LineNo,
_ps
.LinePos);
3693
if (
_ps
.chars[
_ps
.charPos] == '<' ||
_ps
.charsUsed -
_ps
.charPos == 0 || await ZeroEndingStreamAsync(
_ps
.charPos).ConfigureAwait(false))
3705
if (XmlCharType.IsCharData(
_ps
.chars[
_ps
.charPos]))
3711
ThrowInvalidChar(
_ps
.chars,
_ps
.charsUsed,
_ps
.charPos);
3718
Debug.Assert(
_ps
.chars[
_ps
.charPos] == '&');
3719
_ps
.charPos++;
3721
_curNode.SetLineInfo(
_ps
.LineNo,
_ps
.LinePos);
3729
Debug.Assert(
_ps
.chars[
_ps
.charPos] == '&');
3731
if (
_ps
.charPos + 1 ==
_ps
.charsUsed)
3740
if (
_ps
.chars[
_ps
.charPos + 1] == '#')
3775
_ps
.charPos++;
3776
int savedLinePos =
_ps
.LinePos;
3783
Throw(SR.Xml_ErrorParsingEntityName,
_ps
.LineNo, savedLinePos);
3789
if (
_ps
.chars[endPos] != ';')
3794
int entityLinePos =
_ps
.LinePos;
3795
string entityName = _nameTable.Add(
_ps
.chars,
_ps
.charPos, endPos -
_ps
.charPos);
3796
_ps
.charPos = endPos + 1;
3800
_reportedBaseUri =
_ps
.baseUriStr;
3801
_reportedEncoding =
_ps
.encoding;
3829
Throw(SR.Xml_UndeclaredEntity, name,
_ps
.LineNo, entityStartLinePos);
3842
Throw(SR.Xml_UnparsedEntityRef, name,
_ps
.LineNo, entityStartLinePos);
3847
Throw(SR.Xml_ExternalEntityInStandAloneDocument, entity.Name,
_ps
.LineNo, entityStartLinePos);
3854
Throw(SR.Xml_ExternalEntityInAttValue, name,
_ps
.LineNo, entityStartLinePos);
3868
_curNode.entityId =
_ps
.entityId;
3876
_curNode.entityId =
_ps
.entityId;
3889
_curNode.entityId =
_ps
.entityId;
3905
_curNode.SetLineInfo(
_ps
.LineNo,
_ps
.LinePos);
3912
string target = _nameTable.Add(
_ps
.chars,
_ps
.charPos, nameEndPos -
_ps
.charPos);
3918
_ps
.charPos = nameEndPos;
3933
char ch =
_ps
.chars[
_ps
.charPos];
3934
Debug.Assert(
_ps
.charPos <
_ps
.charsUsed);
3937
if (
_ps
.charsUsed -
_ps
.charPos < 2)
3941
if (ch != '?' ||
_ps
.chars[
_ps
.charPos + 1] != '>')
3943
Throw(SR.Xml_BadNameChar, XmlException.BuildCharExceptionArgs(
_ps
.chars,
_ps
.charsUsed,
_ps
.charPos));
3964
_curNode.SetValue(
_ps
.chars, startPos, endPos - startPos);
3969
piInDtdStringBuilder.Append(
_ps
.chars, startPos, endPos - startPos);
3999
sb.Append(
_ps
.chars, startPos, endPos - startPos);
4006
sb.Append(
_ps
.chars, startPos, endPos - startPos);
4023
if (
_ps
.charsUsed -
_ps
.charPos < 2)
4027
Throw(
_ps
.charsUsed, SR.Xml_UnexpectedEOF, "PI");
4031
int pos =
_ps
.charPos;
4032
char[] chars =
_ps
.chars;
4053
Debug.Assert(!
_ps
.eolNormalized);
4061
outStartPos =
_ps
.charPos;
4062
_ps
.charPos = pos + 2;
4066
else if (pos + 1 ==
_ps
.charsUsed)
4083
if (!
_ps
.eolNormalized && _parsingMode == ParsingMode.Full)
4086
if (pos -
_ps
.charPos > 0)
4102
_ps
.charPos++;
4107
else if (pos + 1 <
_ps
.charsUsed ||
_ps
.isEof)
4109
if (!
_ps
.eolNormalized)
4129
if (pos ==
_ps
.charsUsed)
4139
if (pos + 1 ==
_ps
.charsUsed)
4150
ThrowInvalidChar(chars,
_ps
.charsUsed, pos);
4166
outStartPos =
_ps
.charPos;
4167
_ps
.charPos = pos;
4201
_curNode.SetLineInfo(
_ps
.LineNo,
_ps
.LinePos);
4210
_curNode.SetValueNode(type,
_ps
.chars, startPos, endPos - startPos);
4218
_stringBuilder.Append(
_ps
.chars, startPos, endPos - startPos);
4225
_stringBuilder.Append(
_ps
.chars, startPos, endPos - startPos);
4247
if (
_ps
.charsUsed -
_ps
.charPos < 3)
4256
int pos =
_ps
.charPos;
4257
char[] chars =
_ps
.chars;
4279
Debug.Assert(!
_ps
.eolNormalized);
4287
outStartPos =
_ps
.charPos;
4288
_ps
.charPos = pos + 3;
4292
else if (pos + 2 ==
_ps
.charsUsed)
4301
else if (pos + 1 ==
_ps
.charsUsed)
4321
if (!
_ps
.eolNormalized && _parsingMode == ParsingMode.Full)
4323
if (pos -
_ps
.charPos > 0)
4339
_ps
.charPos++;
4344
else if (pos + 1 <
_ps
.charsUsed ||
_ps
.isEof)
4346
if (!
_ps
.eolNormalized)
4366
if (pos ==
_ps
.charsUsed)
4374
if (pos + 1 ==
_ps
.charsUsed)
4385
ThrowInvalidChar(chars,
_ps
.charsUsed, pos);
4400
outStartPos =
_ps
.charPos;
4402
_ps
.charPos = pos;
4417
while (
_ps
.charsUsed -
_ps
.charPos < 8)
4424
if (!
_ps
.chars.AsSpan(
_ps
.charPos).StartsWith("DOCTYPE"))
4428
if (!XmlCharType.IsWhiteSpace(
_ps
.chars[
_ps
.charPos + 7]))
4430
ThrowExpectingWhitespace(
_ps
.charPos + 7);
4435
Throw(
_ps
.charPos - 2, SR.Xml_MultipleDTDsProvided); // position just before <!DOCTYPE
4439
Throw(
_ps
.charPos - 2, SR.Xml_DtdAfterRootElement);
4442
_ps
.charPos += 8;
4449
_curNode.SetLineInfo(
_ps
.LineNo,
_ps
.LinePos);
4491
_ps
.charPos = pos;
4497
if (
_ps
.chars[
_ps
.charPos] == 'P')
4500
while (
_ps
.charsUsed -
_ps
.charPos < 6)
4508
if (!
_ps
.chars.AsSpan(
_ps
.charPos).StartsWith("PUBLIC"))
4512
_ps
.charPos += 6;
4517
ThrowExpectingWhitespace(
_ps
.charPos);
4526
ThrowExpectingWhitespace(
_ps
.charPos);
4534
else if (
_ps
.chars[
_ps
.charPos] == 'S')
4537
while (
_ps
.charsUsed -
_ps
.charPos < 6)
4545
if (!
_ps
.chars.AsSpan(
_ps
.charPos).StartsWith("SYSTEM"))
4549
_ps
.charPos += 6;
4554
ThrowExpectingWhitespace(
_ps
.charPos);
4562
else if (
_ps
.chars[
_ps
.charPos] != '[' &&
_ps
.chars[
_ps
.charPos] != '>')
4568
if (
_ps
.chars[
_ps
.charPos] == '[')
4570
_ps
.charPos++;
4575
if (
_ps
.chars[
_ps
.charPos] != '>')
4580
else if (
_ps
.chars[
_ps
.charPos] == '>')
4588
_ps
.charPos++;
4594
char quoteChar =
_ps
.chars[
_ps
.charPos];
4600
_ps
.charPos++;
4611
char[] chars =
_ps
.chars;
4612
int pos =
_ps
.charPos;
4626
_ps
.charPos = pos + 1;
4631
_ps
.charPos = pos;
4644
else if (pos + 1 <
_ps
.charsUsed ||
_ps
.isEof)
4670
if (pos + 3 >=
_ps
.charsUsed && !
_ps
.isEof)
4685
else if (pos + 1 >=
_ps
.charsUsed && !
_ps
.isEof)
4695
if (pos + 2 >=
_ps
.charsUsed && !
_ps
.isEof)
4713
if (pos + 1 >=
_ps
.charsUsed && !
_ps
.isEof)
4754
if (pos ==
_ps
.charsUsed)
4764
if (pos + 1 ==
_ps
.charsUsed)
4775
ThrowInvalidChar(chars,
_ps
.charsUsed, pos);
4784
if (
_ps
.charsUsed -
_ps
.charPos > 0)
4786
if (
_ps
.chars[
_ps
.charPos] != (char)0xD)
4791
Debug.Assert(
_ps
.isEof);
4798
chars =
_ps
.chars;
4799
pos =
_ps
.charPos;
4805
int pos =
_ps
.charPos;
4807
char[] chars =
_ps
.chars;
4822
int tmp1 = pos -
_ps
.charPos;
4823
if (sb != null && !
_ps
.eolNormalized)
4827
sb.Append(chars,
_ps
.charPos, tmp1);
4830
_ps
.charPos = pos + 1;
4834
else if (pos + 1 <
_ps
.charsUsed ||
_ps
.isEof)
4836
if (!
_ps
.eolNormalized)
4853
if (pos ==
_ps
.charsUsed)
4859
int tmp2 = pos -
_ps
.charPos;
4862
sb?.Append(
_ps
.chars,
_ps
.charPos, tmp2);
4863
_ps
.charPos = pos;
4872
int tmp3 = pos -
_ps
.charPos;
4875
sb?.Append(
_ps
.chars,
_ps
.charPos, tmp3);
4876
_ps
.charPos = pos;
4882
if (
_ps
.charsUsed -
_ps
.charPos == 0)
4886
if (
_ps
.chars[
_ps
.charPos] != (char)0xD)
4891
Debug.Assert(
_ps
.isEof);
4893
pos =
_ps
.charPos;
4894
chars =
_ps
.chars;
4912
switch (newPos = ParseNumericCharRefInline(
_ps
.charPos, expand, internalSubsetBuilder, out charCount, out entityType))
4920
Debug.Assert(
_ps
.chars[
_ps
.charPos] == '&');
4925
_ps
.charPos = newPos - charCount;
4944
switch (newPos = ParseNamedCharRefInline(
_ps
.charPos, expand, internalSubsetBuilder))
4954
Debug.Assert(
_ps
.chars[
_ps
.charPos] == '&');
4959
_ps
.charPos = newPos - 1;
4982
int pos =
_ps
.charPos + startOffset;
4985
char[] chars =
_ps
.chars;
4994
if (pos + 1 >=
_ps
.charsUsed)
5007
Throw(pos, SR.Xml_BadStartNameChar, XmlException.BuildCharExceptionArgs(chars,
_ps
.charsUsed, pos));
5034
colonOffset = pos -
_ps
.charPos;
5040
colonOffset = pos -
_ps
.charPos;
5046
else if (pos ==
_ps
.charsUsed)
5053
chars =
_ps
.chars;
5060
colonPos = (colonOffset == -1) ? -1 :
_ps
.charPos + colonOffset;
5067
int offset = pos -
_ps
.charPos;
5069
pos =
_ps
.charPos + offset;
5088
if (
_ps
.chars[endPos] != ';')
5093
string entityName = _nameTable.Add(
_ps
.chars,
_ps
.charPos, endPos -
_ps
.charPos);
5094
_ps
.charPos = endPos + 1;
5211
Debug.Assert(
_ps
.appendMode);
5212
int initialPos =
_ps
.charPos;
5219
_ps
.charPos = initialPos;
5225
Encoding? enc =
_ps
.encoding;
5245
if (_v1Compat && pos ==
_ps
.charsUsed - 1 &&
_ps
.chars[pos] == (char)0 && await ReadDataAsync().ConfigureAwait(false) == 0 &&
_ps
.isStreamEof)
5247
_ps
.charsUsed--;
5379
_curNode.AdjustLineInfo(_readValueOffset,
_ps
.eolNormalized, ref _incReadLineInfo);
5403
_incReadLineInfo.Set(
_ps
.LineNo,
_ps
.LinePos);
5413
charsRead = _incReadDecoder.Decode(
_ps
.chars, startPos, endPos - startPos);
5427
_curNode.SetValue(
_ps
.chars, startPos, endPos - startPos);
5429
AdjustLineInfo(
_ps
.chars, startPos - charsRead, startPos,
_ps
.eolNormalized, ref _incReadLineInfo);