while (true)
{
int startPos = i;
- unsafe
+ while (i < endPos && _xmlCharType.IsAttributeValueChar(ch = array[i]))
{
- while (i < endPos && _xmlCharType.IsAttributeValueChar(ch = array[i]))
- {
- i++;
- }
+ i++;
}
if (startPos < i)
char ch = (char)0;
while (true)
{
- unsafe
+ while (i < len && _xmlCharType.IsAttributeValueChar(ch = text[i]))
{
- while (i < len && _xmlCharType.IsAttributeValueChar(ch = text[i]))
- {
- i++;
- }
+ i++;
}
+
if (i == len)
{
// reached the end of the string -> write it whole out
}
i++;
startPos = i;
- unsafe
+ while (i < len && _xmlCharType.IsAttributeValueChar(ch = text[i]))
{
- while (i < len && _xmlCharType.IsAttributeValueChar(ch = text[i]))
- {
- i++;
- }
+ i++;
}
}
}
while (true)
{
- unsafe
+ while (i < len && (_xmlCharType.IsCharData((ch = text[i])) || ch < 0x20))
{
- while (i < len && (_xmlCharType.IsCharData((ch = text[i])) || ch < 0x20))
- {
- i++;
- }
+ i++;
}
if (i == len)
{
char[] chars;
Continue:
chars = _ps.chars;
- unsafe
+ while (_xmlCharType.IsAttributeValueChar(chars[pos]))
{
- while (_xmlCharType.IsAttributeValueChar(chars[pos]))
- {
- pos++;
- }
+ pos++;
}
if (_ps.chars[pos] == quoteChar)
// case occurs (like end of buffer, invalid name char)
ContinueStartName:
// check element name start char
- unsafe
+ if (_xmlCharType.IsStartNCNameSingleChar(chars[pos]))
+ {
+ pos++;
+ }
+#if XML10_FIFTH_EDITION
+ else if (pos + 1 < ps.charsUsed && xmlCharType.IsNCNameSurrogateChar(chars[pos + 1], chars[pos]))
+ {
+ pos += 2;
+ }
+#endif
+ else
{
- if (_xmlCharType.IsStartNCNameSingleChar(chars[pos]))
+ goto ParseQNameSlow;
+ }
+
+ ContinueName:
+ // parse element name
+ while (true)
+ {
+ if (_xmlCharType.IsNCNameSingleChar(chars[pos]))
{
pos++;
}
#if XML10_FIFTH_EDITION
- else if (pos + 1 < ps.charsUsed && xmlCharType.IsNCNameSurrogateChar(chars[pos + 1], chars[pos]))
+ else if (pos < ps.charsUsed && xmlCharType.IsNCNameSurrogateChar(chars[pos + 1], chars[pos]))
{
pos += 2;
}
#endif
else
{
- goto ParseQNameSlow;
- }
- }
-
- ContinueName:
- unsafe
- {
- // parse element name
- while (true)
- {
- if (_xmlCharType.IsNCNameSingleChar(chars[pos]))
- {
- pos++;
- }
-#if XML10_FIFTH_EDITION
- else if (pos < ps.charsUsed && xmlCharType.IsNCNameSurrogateChar(chars[pos + 1], chars[pos]))
- {
- pos += 2;
- }
-#endif
- else
- {
- break;
- }
+ break;
}
}
char ch = chars[pos];
// whitespace after element name -> there are probably some attributes
- bool isWs;
- unsafe
- {
- isWs = _xmlCharType.IsWhiteSpace(ch);
- }
+ bool isWs = _xmlCharType.IsWhiteSpace(ch);
if (isWs)
{
_ps.charPos = pos;
goto ReadData;
}
- unsafe
- {
- if (_xmlCharType.IsNCNameSingleChar(chars[pos]) || (chars[pos] == ':')
+ if (_xmlCharType.IsNCNameSingleChar(chars[pos]) || (chars[pos] == ':')
#if XML10_FIFTH_EDITION
- || xmlCharType.IsNCNameHighSurrogateChar(chars[pos])
+ || xmlCharType.IsNCNameHighSurrogateChar(chars[pos])
#endif
- )
- {
- ThrowTagMismatch(startTagNode);
- }
+ )
+ {
+ ThrowTagMismatch(startTagNode);
}
// eat whitespace
// eat whitespace
int lineNoDelta = 0;
char tmpch0;
- unsafe
+ while (_xmlCharType.IsWhiteSpace(tmpch0 = chars[pos]))
{
- while (_xmlCharType.IsWhiteSpace(tmpch0 = chars[pos]))
+ if (tmpch0 == (char)0xA)
{
- if (tmpch0 == (char)0xA)
+ OnNewLine(pos + 1);
+ lineNoDelta++;
+ }
+ else if (tmpch0 == (char)0xD)
+ {
+ if (chars[pos + 1] == (char)0xA)
+ {
+ OnNewLine(pos + 2);
+ lineNoDelta++;
+ pos++;
+ }
+ else if (pos + 1 != _ps.charsUsed)
{
OnNewLine(pos + 1);
lineNoDelta++;
}
- else if (tmpch0 == (char)0xD)
+ else
{
- if (chars[pos + 1] == (char)0xA)
- {
- OnNewLine(pos + 2);
- lineNoDelta++;
- pos++;
- }
- else if (pos + 1 != _ps.charsUsed)
- {
- OnNewLine(pos + 1);
- lineNoDelta++;
- }
- else
- {
- _ps.charPos = pos;
- goto ReadData;
- }
+ _ps.charPos = pos;
+ goto ReadData;
}
- pos++;
}
+ pos++;
}
char tmpch1;
int startNameCharSize = 0;
- unsafe
+ if (_xmlCharType.IsStartNCNameSingleChar(tmpch1 = chars[pos]))
{
- if (_xmlCharType.IsStartNCNameSingleChar(tmpch1 = chars[pos]))
- {
- startNameCharSize = 1;
- }
+ startNameCharSize = 1;
+ }
#if XML10_FIFTH_EDITION
- else if (pos + 1 < ps.charsUsed && xmlCharType.IsNCNameSurrogateChar(chars[pos + 1], tmpch1))
- {
- startNameCharSize = 2;
- }
-#endif
+ else if (pos + 1 < ps.charsUsed && xmlCharType.IsNCNameSurrogateChar(chars[pos + 1], tmpch1))
+ {
+ startNameCharSize = 2;
}
+#endif
if (startNameCharSize == 0)
{
ContinueParseName:
char tmpch2;
- unsafe
+ while (true)
{
- while (true)
+ if (_xmlCharType.IsNCNameSingleChar(tmpch2 = chars[pos]))
{
- if (_xmlCharType.IsNCNameSingleChar(tmpch2 = chars[pos]))
- {
- pos++;
- }
+ pos++;
+ }
#if XML10_FIFTH_EDITION
- else if (pos + 1 < ps.charsUsed && xmlCharType.IsNCNameSurrogateChar(chars[pos + 1], tmpch2))
- {
- pos += 2;
- }
+ else if (pos + 1 < ps.charsUsed && xmlCharType.IsNCNameSurrogateChar(chars[pos + 1], tmpch2))
+ {
+ pos += 2;
+ }
#endif
- else
- {
- break;
- }
+ else
+ {
+ break;
}
}
colonPos = pos;
pos++;
- unsafe
+ if (_xmlCharType.IsStartNCNameSingleChar(chars[pos]))
{
- if (_xmlCharType.IsStartNCNameSingleChar(chars[pos]))
- {
- pos++;
- goto ContinueParseName;
- }
+ pos++;
+ goto ContinueParseName;
+ }
#if XML10_FIFTH_EDITION
- else if ( pos + 1 < ps.charsUsed && xmlCharType.IsNCNameSurrogateChar( chars[pos + 1], chars[pos] ) ) {
- pos += 2;
- goto ContinueParseName;
- }
-#endif
+ else if ( pos + 1 < ps.charsUsed && xmlCharType.IsNCNameSurrogateChar( chars[pos + 1], chars[pos] ) ) {
+ pos += 2;
+ goto ContinueParseName;
}
+#endif
// else fallback to full name parsing routine
pos = ParseQName(out colonPos);
chars = _ps.chars;
// parse attribute value
char tmpch3;
- unsafe
+ while (_xmlCharType.IsAttributeValueChar(tmpch3 = chars[pos]))
{
- while (_xmlCharType.IsAttributeValueChar(tmpch3 = chars[pos]))
- {
- pos++;
- }
+ pos++;
}
+
if (tmpch3 == quoteChar)
{
#if DEBUG
while (true)
{
// parse the rest of the attribute value
- unsafe
+ while (_xmlCharType.IsAttributeValueChar(chars[pos]))
{
- while (_xmlCharType.IsAttributeValueChar(chars[pos]))
- {
- pos++;
- }
+ pos++;
}
if (pos - _ps.charPos > 0)
while (true)
{
// parse text content
- unsafe
+ while (_xmlCharType.IsTextChar(c = chars[pos]))
{
- while (_xmlCharType.IsTextChar(c = chars[pos]))
- {
- orChars |= (int)c;
- pos++;
- }
+ orChars |= (int)c;
+ pos++;
}
switch (c)
while (true)
{
char tmpch;
- unsafe
+ while (_xmlCharType.IsTextChar(tmpch = chars[pos]) && tmpch != '?')
{
- while (_xmlCharType.IsTextChar(tmpch = chars[pos]) && tmpch != '?')
- {
- pos++;
- }
+ pos++;
}
switch (chars[pos])
while (true)
{
char tmpch;
- unsafe
+ while (_xmlCharType.IsTextChar(tmpch = chars[pos]) && tmpch != stopChar)
{
- while (_xmlCharType.IsTextChar(tmpch = chars[pos]) && tmpch != stopChar)
- {
- pos++;
- }
+ pos++;
}
// possibly end of comment or cdata section
{
char ch;
- unsafe
+ while (_xmlCharType.IsAttributeValueChar(ch = chars[pos]) && chars[pos] != stopChar && ch != '-' && ch != '?')
{
- while (_xmlCharType.IsAttributeValueChar(ch = chars[pos]) && chars[pos] != stopChar && ch != '-' && ch != '?')
- {
- pos++;
- }
+ pos++;
}
// closing stopChar outside of literal and ignore/include sections -> save value & return
char[] chars = _ps.chars;
// start name char
- unsafe
+ if (_xmlCharType.IsStartNCNameSingleChar(chars[pos]))
{
- if (_xmlCharType.IsStartNCNameSingleChar(chars[pos]))
- {
- pos++;
- }
+ pos++;
+ }
#if XML10_FIFTH_EDITION
- else if (pos + 1 < ps.charsUsed && xmlCharType.IsNCNameSurrogateChar(chars[pos + 1], chars[pos]))
- {
- pos += 2;
- }
+ else if (pos + 1 < ps.charsUsed && xmlCharType.IsNCNameSurrogateChar(chars[pos + 1], chars[pos]))
+ {
+ pos += 2;
+ }
#endif
- else
+ else
+ {
+ if (pos + 1 >= _ps.charsUsed)
{
- if (pos + 1 >= _ps.charsUsed)
- {
- if (ReadDataInName(ref pos))
- {
- goto ContinueStartName;
- }
- Throw(pos, SR.Xml_UnexpectedEOF, "Name");
- }
- if (chars[pos] != ':' || _supportNamespaces)
+ if (ReadDataInName(ref pos))
{
- Throw(pos, SR.Xml_BadStartNameChar, XmlException.BuildCharExceptionArgs(chars, _ps.charsUsed, pos));
+ goto ContinueStartName;
}
+ Throw(pos, SR.Xml_UnexpectedEOF, "Name");
+ }
+ if (chars[pos] != ':' || _supportNamespaces)
+ {
+ Throw(pos, SR.Xml_BadStartNameChar, XmlException.BuildCharExceptionArgs(chars, _ps.charsUsed, pos));
}
}
ContinueName:
// parse name
- unsafe
+ while (true)
{
- while (true)
+ if (_xmlCharType.IsNCNameSingleChar(chars[pos]))
{
- if (_xmlCharType.IsNCNameSingleChar(chars[pos]))
- {
- pos++;
- }
+ pos++;
+ }
#if XML10_FIFTH_EDITION
- else if ( pos + 1 < ps.charsUsed && xmlCharType.IsNCNameSurrogateChar( chars[pos + 1], chars[pos] ) ) {
- pos += 2;
- }
+ else if ( pos + 1 < ps.charsUsed && xmlCharType.IsNCNameSurrogateChar( chars[pos + 1], chars[pos] ) ) {
+ pos += 2;
+ }
#endif
- else
- {
- break;
- }
+ else
+ {
+ break;
}
}
_incReadLineInfo.Set(_ps.LineNo, _ps.LinePos);
char c;
- unsafe
+ if (_incReadState == IncrementalReadState.Attributes)
{
- if (_incReadState == IncrementalReadState.Attributes)
+ while (_xmlCharType.IsAttributeValueChar(c = chars[pos]) && c != '/')
{
- while (_xmlCharType.IsAttributeValueChar(c = chars[pos]) && c != '/')
- {
- pos++;
- }
+ pos++;
}
- else
+ }
+ else
+ {
+ while (_xmlCharType.IsAttributeValueChar(c = chars[pos]))
{
- while (_xmlCharType.IsAttributeValueChar(c = chars[pos]))
- {
- pos++;
- }
+ pos++;
}
}
while (true)
{
- unsafe
- {
- while (_xmlCharType.IsAttributeValueChar(chars[pos]))
- pos++;
- }
+ while (_xmlCharType.IsAttributeValueChar(chars[pos]))
+ pos++;
switch (chars[pos])
{
// case occurs (like end of buffer, invalid name char)
ContinueStartName:
// check element name start char
- unsafe
+ if (_xmlCharType.IsStartNCNameSingleChar(chars[pos]))
{
- if (_xmlCharType.IsStartNCNameSingleChar(chars[pos]))
- {
- pos++;
- }
+ pos++;
+ }
#if XML10_FIFTH_EDITION
- else if ( pos + 1 < ps.charsUsed && xmlCharType.IsNCNameSurrogateChar(chars[pos + 1], chars[pos])) {
- pos += 2;
- }
+ else if ( pos + 1 < ps.charsUsed && xmlCharType.IsNCNameSurrogateChar(chars[pos + 1], chars[pos])) {
+ pos += 2;
+ }
#endif
- else
- {
- goto ParseQNameSlow;
- }
+ else
+ {
+ goto ParseQNameSlow;
}
ContinueName:
- unsafe
+ // parse element name
+ while (true)
{
- // parse element name
- while (true)
+ if (_xmlCharType.IsNCNameSingleChar(chars[pos]))
{
- if (_xmlCharType.IsNCNameSingleChar(chars[pos]))
- {
- pos++;
- }
+ pos++;
+ }
#if XML10_FIFTH_EDITION
- else if ( pos < ps.charsUsed && xmlCharType.IsNCNameSurrogateChar(chars[pos + 1], chars[pos])) {
- pos += 2;
- }
+ else if ( pos < ps.charsUsed && xmlCharType.IsNCNameSurrogateChar(chars[pos + 1], chars[pos])) {
+ pos += 2;
+ }
#endif
- else
- {
- break;
- }
+ else
+ {
+ break;
}
}
bool tagMismatch = false;
- unsafe
- {
- if (_xmlCharType.IsNCNameSingleChar(chars[pos]) || (chars[pos] == ':')
+ if (_xmlCharType.IsNCNameSingleChar(chars[pos]) || (chars[pos] == ':')
#if XML10_FIFTH_EDITION
- || xmlCharType.IsNCNameHighSurrogateChar(chars[pos])
+ || xmlCharType.IsNCNameHighSurrogateChar(chars[pos])
#endif
)
- {
- tagMismatch = true;
- }
+ {
+ tagMismatch = true;
}
if (tagMismatch)
char tmpch1;
int startNameCharSize = 0;
- unsafe
+ if (_xmlCharType.IsStartNCNameSingleChar(tmpch1 = chars[pos]))
{
- if (_xmlCharType.IsStartNCNameSingleChar(tmpch1 = chars[pos]))
- {
- startNameCharSize = 1;
- }
+ startNameCharSize = 1;
+ }
#if XML10_FIFTH_EDITION
- else if ( pos + 1 < ps.charsUsed && xmlCharType.IsNCNameSurrogateChar(chars[pos + 1], tmpch1 )) {
- startNameCharSize = 2;
- }
-#endif
+ else if ( pos + 1 < ps.charsUsed && xmlCharType.IsNCNameSurrogateChar(chars[pos + 1], tmpch1 )) {
+ startNameCharSize = 2;
}
+#endif
if (startNameCharSize == 0)
{
ContinueParseName:
char tmpch2;
- unsafe
+ while (true)
{
- while (true)
+ if (_xmlCharType.IsNCNameSingleChar(tmpch2 = chars[pos]))
{
- if (_xmlCharType.IsNCNameSingleChar(tmpch2 = chars[pos]))
- {
- pos++;
- }
+ pos++;
+ }
#if XML10_FIFTH_EDITION
- else if (pos + 1 < ps.charsUsed && xmlCharType.IsNCNameSurrogateChar(chars[pos + 1], tmpch2)) {
- pos += 2;
- }
+ else if (pos + 1 < ps.charsUsed && xmlCharType.IsNCNameSurrogateChar(chars[pos + 1], tmpch2)) {
+ pos += 2;
+ }
#endif
- else
- {
- break;
- }
+ else
+ {
+ break;
}
}
colonPos = pos;
pos++;
- unsafe
+ if (_xmlCharType.IsStartNCNameSingleChar(chars[pos]))
{
- if (_xmlCharType.IsStartNCNameSingleChar(chars[pos]))
- {
- pos++;
- goto ContinueParseName;
- }
+ pos++;
+ goto ContinueParseName;
+ }
#if XML10_FIFTH_EDITION
- else if ( pos + 1 < ps.charsUsed && xmlCharType.IsNCNameSurrogateChar(chars[pos + 1], chars[pos])) {
- pos += 2;
- goto ContinueParseName;
- }
-#endif
+ else if ( pos + 1 < ps.charsUsed && xmlCharType.IsNCNameSurrogateChar(chars[pos + 1], chars[pos])) {
+ pos += 2;
+ goto ContinueParseName;
}
+#endif
// else fallback to full name parsing routine
ContinueStartName:
char[] chars = _ps.chars;
- //a tmp flag, used to avoid await keyword in unsafe context.
- bool awaitReadDataInNameAsync = false;
// start name char
- unsafe
+ if (_xmlCharType.IsStartNCNameSingleChar(chars[pos]))
{
- if (_xmlCharType.IsStartNCNameSingleChar(chars[pos]))
- {
- pos++;
- }
+ pos++;
+ }
#if XML10_FIFTH_EDITION
- else if ( pos + 1 < ps.charsUsed && xmlCharType.IsNCNameSurrogateChar(chars[pos + 1], chars[pos])) {
- pos += 2;
- }
+ else if ( pos + 1 < ps.charsUsed && xmlCharType.IsNCNameSurrogateChar(chars[pos + 1], chars[pos])) {
+ pos += 2;
+ }
#endif
- else
+ else
+ {
+ if (pos + 1 >= _ps.charsUsed)
{
- if (pos + 1 >= _ps.charsUsed)
- {
- awaitReadDataInNameAsync = true;
- }
- else if (chars[pos] != ':' || _supportNamespaces)
+ var tuple_27 = await ReadDataInNameAsync(pos).ConfigureAwait(false);
+ pos = tuple_27.Item1;
+
+ if (tuple_27.Item2)
{
- Throw(pos, SR.Xml_BadStartNameChar, XmlException.BuildCharExceptionArgs(chars, _ps.charsUsed, pos));
+ goto ContinueStartName;
}
+ Throw(pos, SR.Xml_UnexpectedEOF, "Name");
}
- }
-
- if (awaitReadDataInNameAsync)
- {
- var tuple_27 = await ReadDataInNameAsync(pos).ConfigureAwait(false);
- pos = tuple_27.Item1;
-
- if (tuple_27.Item2)
+ else if (chars[pos] != ':' || _supportNamespaces)
{
- goto ContinueStartName;
+ Throw(pos, SR.Xml_BadStartNameChar, XmlException.BuildCharExceptionArgs(chars, _ps.charsUsed, pos));
}
- Throw(pos, SR.Xml_UnexpectedEOF, "Name");
}
ContinueName:
// parse name
- unsafe
+ while (true)
{
- while (true)
+ if (_xmlCharType.IsNCNameSingleChar(chars[pos]))
{
- if (_xmlCharType.IsNCNameSingleChar(chars[pos]))
- {
- pos++;
- }
+ pos++;
+ }
#if XML10_FIFTH_EDITION
- else if ( pos + 1 < ps.charsUsed && xmlCharType.IsNCNameSurrogateChar(chars[pos + 1], chars[pos])) {
- pos += 2;
- }
+ else if ( pos + 1 < ps.charsUsed && xmlCharType.IsNCNameSurrogateChar(chars[pos + 1], chars[pos])) {
+ pos += 2;
+ }
#endif
- else
- {
- break;
- }
+ else
+ {
+ break;
}
}
// Unfortunatelly the names of elements and attributes are not validated by the XmlTextWriter.
// Also this method does not check wheather the character after ':' is a valid start name character. It accepts
// all valid name characters at that position. This can't be changed because of backwards compatibility.
- private unsafe void ValidateName(string name, bool isNCName)
+ private void ValidateName(string name, bool isNCName)
{
if (name == null || name.Length == 0)
{
return pDst + 3;
}
- protected unsafe void ValidateContentChars(string chars, string propertyName, bool allowOnlyWhitespace)
+ protected void ValidateContentChars(string chars, string propertyName, bool allowOnlyWhitespace)
{
if (allowOnlyWhitespace)
{
return s;
}
- private unsafe void CheckNCName(string ncname)
+ private void CheckNCName(string ncname)
{
Debug.Assert(ncname != null && ncname.Length > 0);
while (true)
{
- unsafe
+ if (_xmlCharType.IsStartNCNameSingleChar(_chars[_curPos]) || _chars[_curPos] == ':')
{
- if (_xmlCharType.IsStartNCNameSingleChar(_chars[_curPos]) || _chars[_curPos] == ':')
- {
- _curPos++;
- }
+ _curPos++;
+ }
#if XML10_FIFTH_EDITION
- else if ( curPos + 1 < charsUsed && xmlCharType.IsNCNameSurrogateChar(chars[curPos+1], chars[curPos])) {
- curPos += 2;
- }
+ else if ( curPos + 1 < charsUsed && xmlCharType.IsNCNameSurrogateChar(chars[curPos+1], chars[curPos])) {
+ curPos += 2;
+ }
#endif
- else
+ else
+ {
+ if (_curPos + 1 >= _charsUsed)
{
- if (_curPos + 1 >= _charsUsed)
+ if (ReadDataInName())
{
- if (ReadDataInName())
- {
- continue;
- }
- Throw(_curPos, SR.Xml_UnexpectedEOF, "Name");
- }
- else
- {
- Throw(_curPos, SR.Xml_BadStartNameChar, XmlException.BuildCharExceptionArgs(_chars, _charsUsed, _curPos));
+ continue;
}
+ Throw(_curPos, SR.Xml_UnexpectedEOF, "Name");
+ }
+ else
+ {
+ Throw(_curPos, SR.Xml_BadStartNameChar, XmlException.BuildCharExceptionArgs(_chars, _charsUsed, _curPos));
}
}
ContinueName:
- unsafe
+ while (true)
{
- while (true)
+ if (_xmlCharType.IsNCNameSingleChar(_chars[_curPos]))
{
- if (_xmlCharType.IsNCNameSingleChar(_chars[_curPos]))
- {
- _curPos++;
- }
+ _curPos++;
+ }
#if XML10_FIFTH_EDITION
- else if ( curPos + 1 < charsUsed && xmlCharType.IsNameSurrogateChar(chars[curPos + 1], chars[curPos]) ) {
- curPos += 2;
- }
+ else if ( curPos + 1 < charsUsed && xmlCharType.IsNameSurrogateChar(chars[curPos + 1], chars[curPos]) ) {
+ curPos += 2;
+ }
#endif
- else
- {
- break;
- }
+ else
+ {
+ break;
}
}
while (true)
{
- unsafe
+ while (true)
{
- while (true)
+ if (_xmlCharType.IsNCNameSingleChar(_chars[_curPos]) || _chars[_curPos] == ':')
{
- if (_xmlCharType.IsNCNameSingleChar(_chars[_curPos]) || _chars[_curPos] == ':')
- {
- _curPos++;
- }
+ _curPos++;
+ }
#if XML10_FIFTH_EDITION
- else if (curPos + 1 < charsUsed && xmlCharType.IsNCNameSurrogateChar(chars[curPos + 1], chars[curPos])) {
- curPos += 2;
- }
+ else if (curPos + 1 < charsUsed && xmlCharType.IsNCNameSurrogateChar(chars[curPos + 1], chars[curPos])) {
+ curPos += 2;
+ }
#endif
- else
- {
- break;
- }
+ else
+ {
+ break;
}
}
while (true)
{
- //a tmp flag, used to avoid await keyword in unsafe context.
- bool awaitReadDataInNameAsync = false;
- unsafe
+ if (_xmlCharType.IsStartNCNameSingleChar(_chars[_curPos]) || _chars[_curPos] == ':')
{
- if (_xmlCharType.IsStartNCNameSingleChar(_chars[_curPos]) || _chars[_curPos] == ':')
- {
- _curPos++;
- }
+ _curPos++;
+ }
#if XML10_FIFTH_EDITION
- else if ( curPos + 1 < charsUsed && xmlCharType.IsNCNameSurrogateChar(chars[curPos+1], chars[curPos])) {
- curPos += 2;
- }
+ else if ( curPos + 1 < charsUsed && xmlCharType.IsNCNameSurrogateChar(chars[curPos+1], chars[curPos])) {
+ curPos += 2;
+ }
#endif
- else
+ else
+ {
+ if (_curPos + 1 >= _charsUsed)
{
- if (_curPos + 1 >= _charsUsed)
- {
- awaitReadDataInNameAsync = true;
- }
- else
+ if (await ReadDataInNameAsync().ConfigureAwait(false))
{
- Throw(_curPos, SR.Xml_BadStartNameChar, XmlException.BuildCharExceptionArgs(_chars, _charsUsed, _curPos));
+ continue;
}
+ Throw(_curPos, SR.Xml_UnexpectedEOF, "Name");
}
- }
-
- if (awaitReadDataInNameAsync)
- {
- if (await ReadDataInNameAsync().ConfigureAwait(false))
+ else
{
- continue;
+ Throw(_curPos, SR.Xml_BadStartNameChar, XmlException.BuildCharExceptionArgs(_chars, _charsUsed, _curPos));
}
- Throw(_curPos, SR.Xml_UnexpectedEOF, "Name");
}
ContinueName:
- unsafe
+ while (true)
{
- while (true)
+ if (_xmlCharType.IsNCNameSingleChar(_chars[_curPos]))
{
- if (_xmlCharType.IsNCNameSingleChar(_chars[_curPos]))
- {
- _curPos++;
- }
+ _curPos++;
+ }
#if XML10_FIFTH_EDITION
- else if ( curPos + 1 < charsUsed && xmlCharType.IsNameSurrogateChar(chars[curPos + 1], chars[curPos]) ) {
- curPos += 2;
- }
+ else if ( curPos + 1 < charsUsed && xmlCharType.IsNameSurrogateChar(chars[curPos + 1], chars[curPos]) ) {
+ curPos += 2;
+ }
#endif
- else
- {
- break;
- }
+ else
+ {
+ break;
}
}
while (true)
{
- unsafe
+ while (true)
{
- while (true)
+ if (_xmlCharType.IsNCNameSingleChar(_chars[_curPos]) || _chars[_curPos] == ':')
{
- if (_xmlCharType.IsNCNameSingleChar(_chars[_curPos]) || _chars[_curPos] == ':')
- {
- _curPos++;
- }
+ _curPos++;
+ }
#if XML10_FIFTH_EDITION
- else if (curPos + 1 < charsUsed && xmlCharType.IsNCNameSurrogateChar(chars[curPos + 1], chars[curPos])) {
- curPos += 2;
- }
+ else if (curPos + 1 < charsUsed && xmlCharType.IsNCNameSurrogateChar(chars[curPos + 1], chars[curPos])) {
+ curPos += 2;
+ }
#endif
- else
- {
- break;
- }
+ else
+ {
+ break;
}
}
/// Quits parsing when an invalid Nmtoken char is reached or the end of string is reached.
/// Returns the number of valid Nmtoken chars that were parsed.
/// </summary>
- internal static unsafe int ParseNmtoken(string s, int offset)
+ internal static int ParseNmtoken(string s, int offset)
{
Debug.Assert(s != null && offset <= s.Length);
/// Quits parsing when an invalid Nmtoken char is reached or the end of string is reached.
/// Returns the number of valid Nmtoken chars that were parsed.
/// </summary>
- internal static unsafe int ParseNmtokenNoNamespaces(string s, int offset)
+ internal static int ParseNmtokenNoNamespaces(string s, int offset)
{
Debug.Assert(s != null && offset <= s.Length);
/// Quits parsing when an invalid Name char is reached or the end of string is reached.
/// Returns the number of valid Name chars that were parsed.
/// </summary>
- internal static unsafe int ParseNameNoNamespaces(string s, int offset)
+ internal static int ParseNameNoNamespaces(string s, int offset)
{
Debug.Assert(s != null && offset <= s.Length);
/// Quits parsing when an invalid NCName char is reached or the end of string is reached.
/// Returns the number of valid NCName chars that were parsed.
/// </summary>
- internal static unsafe int ParseNCName(string s, int offset)
+ internal static int ParseNCName(string s, int offset)
{
Debug.Assert(s != null && offset <= s.Length);
}
}
- // NOTE: This method will not be inlined (because it uses byte* charProperties)
public bool IsWhiteSpace(char ch)
{
return (charProperties[ch] & fWhitespace) != 0;
}
- // NOTE: This method will not be inlined (because it uses byte* charProperties)
public bool IsNCNameSingleChar(char ch)
{
return (charProperties[ch] & fNCNameSC) != 0;
}
- // NOTE: This method will not be inlined (because it uses byte* charProperties)
public bool IsStartNCNameSingleChar(char ch)
{
return (charProperties[ch] & fNCStartNameSC) != 0;
return IsNCNameSingleChar(ch) || ch == ':';
}
- // NOTE: This method will not be inlined (because it uses byte* charProperties)
public bool IsCharData(char ch)
{
return (charProperties[ch] & fCharData) != 0;
}
// TextChar = CharData - { 0xA, 0xD, '<', '&', ']' }
- // NOTE: This method will not be inlined (because it uses byte* charProperties)
internal bool IsTextChar(char ch)
{
return (charProperties[ch] & fText) != 0;
}
// AttrValueChar = CharData - { 0xA, 0xD, 0x9, '<', '>', '&', '\'', '"' }
- // NOTE: This method will not be inlined (because it uses byte* charProperties)
internal bool IsAttributeValueChar(char ch)
{
return (charProperties[ch] & fAttrValue) != 0;
}
// XML 1.0 Fourth Edition definitions
- //
- // NOTE: This method will not be inlined (because it uses byte* charProperties)
public bool IsLetter(char ch)
{
return (charProperties[ch] & fLetter) != 0;
}
- // NOTE: This method will not be inlined (because it uses byte* charProperties)
// This method uses the XML 4th edition name character ranges
public bool IsNCNameCharXml4e(char ch)
{
return null;
}
- internal static unsafe string VerifyQName(string name, ExceptionType exceptionType)
+ internal static string VerifyQName(string name, ExceptionType exceptionType)
{
if (name == null || name.Length == 0)
{
// Start name character types - as defined in Namespaces XML 1.0 spec (second edition) production [6] NCNameStartChar
// combined with the production [4] NameStartChar of XML 1.0 spec
- public static unsafe bool IsStartNCNameChar(char ch)
+ public static bool IsStartNCNameChar(char ch)
{
return s_xmlCharType.IsStartNCNameSingleChar(ch);
}
// Name character types - as defined in Namespaces XML 1.0 spec (second edition) production [6] NCNameStartChar
// combined with the production [4] NameChar of XML 1.0 spec
- public static unsafe bool IsNCNameChar(char ch)
+ public static bool IsNCNameChar(char ch)
{
return s_xmlCharType.IsNCNameSingleChar(ch);
}
#endif
// Valid XML character - as defined in XML 1.0 spec (fifth edition) production [2] Char
- public static unsafe bool IsXmlChar(char ch)
+ public static bool IsXmlChar(char ch)
{
return s_xmlCharType.IsCharData(ch);
}
}
// Valid Xml whitespace - as defined in XML 1.0 spec (fifth edition) production [3] S
- public static unsafe bool IsWhitespaceChar(char ch)
+ public static bool IsWhitespaceChar(char ch)
{
return s_xmlCharType.IsWhiteSpace(ch);
}
VerifyCharData(data, exceptionType, exceptionType);
}
- internal static unsafe void VerifyCharData(string data, ExceptionType invCharExceptionType, ExceptionType invSurrogateExceptionType)
+ internal static void VerifyCharData(string data, ExceptionType invCharExceptionType, ExceptionType invSurrogateExceptionType)
{
if (data == null || data.Length == 0)
{
}
}
- internal static unsafe void VerifyCharData(char[] data, int offset, int len, ExceptionType exceptionType)
+ internal static void VerifyCharData(char[] data, int offset, int len, ExceptionType exceptionType)
{
if (data == null || len == 0)
{