static private CreateInvalidHighSurrogateCharException ( char hi ) : |
||
hi | char | |
return |
private static unsafe byte *EncodeSurrogate(char *pSrc, char *pSrcEnd, byte *pDst) { int highChar = pSrc[0]; if (highChar > 0xdbff) { throw XmlConvert.CreateInvalidHighSurrogateCharException((char)highChar); } if ((pSrc + 1) >= pSrcEnd) { throw new ArgumentException(Res.GetString("Xml_InvalidSurrogateMissingLowChar")); } int lowChar = pSrc[1]; if (lowChar < 0xdc00) { throw XmlConvert.CreateInvalidSurrogatePairException((char)lowChar, (char)highChar); } highChar = XmlCharType.CombineSurrogateChar(lowChar, highChar); pDst[0] = (byte)(240 | (highChar >> 0x12)); pDst[1] = (byte)(0x80 | ((highChar >> 12) & 0x3f)); pDst[2] = (byte)(0x80 | ((highChar >> 6) & 0x3f)); pDst[3] = (byte)(0x80 | (highChar & 0x3f)); pDst += 4; return(pDst); }
internal void WriteRawWithSurrogateChecking(string text) { if (text == null) { return; } if (cacheAttrValue) { attrValue.Append(text); } int len = text.Length; int i = 0; char ch = (char)0; for (;;) { unsafe { while (i < len && ((xmlCharType.charProperties[ch = text[i]] & XmlCharType.fCharData) != 0 || // ( xmlCharType.IsCharData( ( ch = text[i] ) ) ch < 0x20)) { i++; } } if (i == len) { break; } if (XmlCharType.IsHighSurrogate(ch)) { if (i + 1 < len) { char lowChar = text[i + 1]; if (XmlCharType.IsLowSurrogate(lowChar)) { i += 2; continue; } else { throw XmlConvert.CreateInvalidSurrogatePairException(lowChar, ch); } } throw new ArgumentException(Res.GetString(Res.Xml_InvalidSurrogateMissingLowChar)); } else if (XmlCharType.IsLowSurrogate(ch)) { throw XmlConvert.CreateInvalidHighSurrogateCharException(ch); } else { i++; } } textWriter.Write(text); return; }
internal void WriteRawWithSurrogateChecking(string text) { if (text == null) { return; } if (_cacheAttrValue) { _attrValue.Append(text); } int len = text.Length; int i = 0; char ch = (char)0; while (true) { unsafe { while (i < len && (_xmlCharType.IsCharData((ch = text[i])) || ch < 0x20)) { i++; } } if (i == len) { break; } if (XmlCharType.IsHighSurrogate(ch)) { if (i + 1 < len) { char lowChar = text[i + 1]; if (XmlCharType.IsLowSurrogate(lowChar)) { i += 2; continue; } else { throw XmlConvert.CreateInvalidSurrogatePairException(lowChar, ch); } } throw new ArgumentException(SR.Xml_InvalidSurrogateMissingLowChar); } else if (XmlCharType.IsLowSurrogate(ch)) { throw XmlConvert.CreateInvalidHighSurrogateCharException(ch); } else { i++; } } _textWriter.Write(text); return; }
internal unsafe void WriteRawWithSurrogateChecking(string text) { if (text == null) { return; } if (this.cacheAttrValue) { this.attrValue.Append(text); } int length = text.Length; int num2 = 0; char ch = '\0'; Label_002A: while ((num2 < length) && (((this.xmlCharType.charProperties[ch = text[num2]] & 0x10) != 0) || (ch < ' '))) { num2++; } if (num2 != length) { if (XmlCharType.IsHighSurrogate(ch)) { if ((num2 + 1) >= length) { throw new ArgumentException(Res.GetString("Xml_InvalidSurrogateMissingLowChar")); } char ch2 = text[num2 + 1]; if (!XmlCharType.IsLowSurrogate(ch2)) { throw XmlConvert.CreateInvalidSurrogatePairException(ch2, ch); } num2 += 2; } else { if (XmlCharType.IsLowSurrogate(ch)) { throw XmlConvert.CreateInvalidHighSurrogateCharException(ch); } num2++; } goto Label_002A; } this.textWriter.Write(text); }
internal void Write(string text) { if (text == null) { return; } if (_cacheAttrValue) { _attrValue.Append(text); } // scan through the string to see if there are any characters to be escaped int len = text.Length; int i = 0; int startPos = 0; char ch = (char)0; while (true) { while (i < len && _xmlCharType.IsAttributeValueChar(ch = text[i])) { i++; } if (i == len) { // reached the end of the string -> write it whole out _textWriter.Write(text); return; } if (_inAttribute) { if (ch == 0x9) { i++; continue; } } else { if (ch == 0x9 || ch == 0xA || ch == 0xD || ch == '"' || ch == '\'') { i++; continue; } } // some character that needs to be escaped is found: break; } char[] helperBuffer = new char[256]; while (true) { if (startPos < i) { WriteStringFragment(text, startPos, i - startPos, helperBuffer); } if (i == len) { break; } switch (ch) { case (char)0x9: _textWriter.Write(ch); break; case (char)0xA: case (char)0xD: if (_inAttribute) { WriteCharEntityImpl(ch); } else { _textWriter.Write(ch); } break; case '<': WriteEntityRefImpl("lt"); break; case '>': WriteEntityRefImpl("gt"); break; case '&': WriteEntityRefImpl("amp"); break; case '\'': if (_inAttribute && _quoteChar == ch) { WriteEntityRefImpl("apos"); } else { _textWriter.Write('\''); } break; case '"': if (_inAttribute && _quoteChar == ch) { WriteEntityRefImpl("quot"); } else { _textWriter.Write('"'); } break; default: if (XmlCharType.IsHighSurrogate(ch)) { if (i + 1 < len) { WriteSurrogateChar(text[++i], ch); } else { throw XmlConvert.CreateInvalidSurrogatePairException(text[i], ch); } } else if (XmlCharType.IsLowSurrogate(ch)) { throw XmlConvert.CreateInvalidHighSurrogateCharException(ch); } else { Debug.Assert((ch < 0x20 && !_xmlCharType.IsWhiteSpace(ch)) || (ch > 0xFFFD)); WriteCharEntityImpl(ch); } break; } i++; startPos = i; while (i < len && _xmlCharType.IsAttributeValueChar(ch = text[i])) { i++; } } }
internal void Write(char[] array, int offset, int count) { if (null == array) { throw new ArgumentNullException(nameof(array)); } if (0 > offset) { throw new ArgumentOutOfRangeException(nameof(offset)); } if (0 > count) { throw new ArgumentOutOfRangeException(nameof(count)); } if (count > array.Length - offset) { throw new ArgumentOutOfRangeException(nameof(count)); } if (_cacheAttrValue) { _attrValue.Append(array, offset, count); } int endPos = offset + count; int i = offset; char ch = (char)0; while (true) { int startPos = i; while (i < endPos && _xmlCharType.IsAttributeValueChar(ch = array[i])) { i++; } if (startPos < i) { _textWriter.Write(array, startPos, i - startPos); } if (i == endPos) { break; } switch (ch) { case (char)0x9: _textWriter.Write(ch); break; case (char)0xA: case (char)0xD: if (_inAttribute) { WriteCharEntityImpl(ch); } else { _textWriter.Write(ch); } break; case '<': WriteEntityRefImpl("lt"); break; case '>': WriteEntityRefImpl("gt"); break; case '&': WriteEntityRefImpl("amp"); break; case '\'': if (_inAttribute && _quoteChar == ch) { WriteEntityRefImpl("apos"); } else { _textWriter.Write('\''); } break; case '"': if (_inAttribute && _quoteChar == ch) { WriteEntityRefImpl("quot"); } else { _textWriter.Write('"'); } break; default: if (XmlCharType.IsHighSurrogate(ch)) { if (i + 1 < endPos) { WriteSurrogateChar(array[++i], ch); } else { throw new ArgumentException(SR.Xml_SurrogatePairSplit); } } else if (XmlCharType.IsLowSurrogate(ch)) { throw XmlConvert.CreateInvalidHighSurrogateCharException(ch); } else { Debug.Assert((ch < 0x20 && !_xmlCharType.IsWhiteSpace(ch)) || (ch > 0xFFFD)); WriteCharEntityImpl(ch); } break; } i++; } }
internal void Write(char[] array, int offset, int count) { if (null == array) { throw new ArgumentNullException("array"); } if (0 > offset) { throw new ArgumentOutOfRangeException("offset"); } if (0 > count) { throw new ArgumentOutOfRangeException("count"); } if (count > array.Length - offset) { throw new ArgumentOutOfRangeException("count"); } if (cacheAttrValue) { attrValue.Append(array, offset, count); } int endPos = offset + count; int i = offset; char ch = (char)0; for (;;) { int startPos = i; unsafe { while (i < endPos && (xmlCharType.charProperties[ch = array[i]] & XmlCharType.fAttrValue) != 0) // ( xmlCharType.IsAttributeValueChar( ( ch = array[i] ) ) ) ) { { i++; } } if (startPos < i) { textWriter.Write(array, startPos, i - startPos); } if (i == endPos) { break; } switch (ch) { case (char)0x9: textWriter.Write(ch); break; case (char)0xA: case (char)0xD: if (inAttribute) { WriteCharEntityImpl(ch); } else { textWriter.Write(ch); } break; case '<': WriteEntityRefImpl("lt"); break; case '>': WriteEntityRefImpl("gt"); break; case '&': WriteEntityRefImpl("amp"); break; case '\'': if (inAttribute && quoteChar == ch) { WriteEntityRefImpl("apos"); } else { textWriter.Write('\''); } break; case '"': if (inAttribute && quoteChar == ch) { WriteEntityRefImpl("quot"); } else { textWriter.Write('"'); } break; default: if (XmlCharType.IsHighSurrogate(ch)) { if (i + 1 < endPos) { WriteSurrogateChar(array[++i], ch); } else { throw new ArgumentException(Res.GetString(Res.Xml_SurrogatePairSplit)); } } else if (XmlCharType.IsLowSurrogate(ch)) { throw XmlConvert.CreateInvalidHighSurrogateCharException(ch); } else { Debug.Assert((ch < 0x20 && !xmlCharType.IsWhiteSpace(ch)) || (ch > 0xFFFD)); WriteCharEntityImpl(ch); } break; } i++; } }
internal void Write(char ch) { if (cacheAttrValue) { attrValue.Append(ch); } bool isAttrValue; unsafe { isAttrValue = (xmlCharType.charProperties[ch] & XmlCharType.fAttrValue) != 0; // xmlCharType.IsAttributeValueChar( ch ) } if (isAttrValue) { textWriter.Write(ch); } else { switch (ch) { case (char)0x9: textWriter.Write(ch); break; case (char)0xA: case (char)0xD: if (inAttribute) { WriteCharEntityImpl(ch); } else { textWriter.Write(ch); } break; case '<': WriteEntityRefImpl("lt"); break; case '>': WriteEntityRefImpl("gt"); break; case '&': WriteEntityRefImpl("amp"); break; case '\'': if (inAttribute && quoteChar == ch) { WriteEntityRefImpl("apos"); } else { textWriter.Write('\''); } break; case '"': if (inAttribute && quoteChar == ch) { WriteEntityRefImpl("quot"); } else { textWriter.Write('"'); } break; default: if ((int)ch >= SurHighStart && (int)ch <= SurHighEnd) { throw new ArgumentException(Res.GetString(Res.Xml_InvalidSurrogateMissingLowChar)); } else if ((int)ch >= SurLowStart && (int)ch <= SurLowEnd) { throw XmlConvert.CreateInvalidHighSurrogateCharException(ch); } else { Debug.Assert((ch < 0x20 && !xmlCharType.IsWhiteSpace(ch)) || (ch > 0xFFFD)); WriteCharEntityImpl(ch); } break; } } }
internal unsafe void Write(string text) { char[] chArray; if (text == null) { return; } if (this.cacheAttrValue) { this.attrValue.Append(text); } int length = text.Length; int num2 = 0; int offset = 0; char ch = '\0'; Label_002C: while ((num2 < length) && ((this.xmlCharType.charProperties[ch = text[num2]] & 0x80) != 0)) { num2++; } if (num2 == length) { this.textWriter.Write(text); return; } if (this.inAttribute) { if (ch != '\t') { goto Label_0091; } num2++; goto Label_002C; } if (((ch == '\t') || (ch == '\n')) || (((ch == '\r') || (ch == '"')) || (ch == '\''))) { num2++; goto Label_002C; } Label_0091: chArray = new char[0x100]; while (true) { if (offset < num2) { this.WriteStringFragment(text, offset, num2 - offset, chArray); } if (num2 == length) { return; } switch (ch) { case '\t': this.textWriter.Write(ch); break; case '\n': case '\r': if (!this.inAttribute) { this.textWriter.Write(ch); } else { this.WriteCharEntityImpl(ch); } break; case '"': if (this.inAttribute && (this.quoteChar == ch)) { this.WriteEntityRefImpl("quot"); } else { this.textWriter.Write('"'); } break; case '&': this.WriteEntityRefImpl("amp"); break; case '\'': if (!this.inAttribute || (this.quoteChar != ch)) { this.textWriter.Write('\''); } else { this.WriteEntityRefImpl("apos"); } break; case '<': this.WriteEntityRefImpl("lt"); break; case '>': this.WriteEntityRefImpl("gt"); break; default: if (XmlCharType.IsHighSurrogate(ch)) { if ((num2 + 1) >= length) { throw XmlConvert.CreateInvalidSurrogatePairException(text[num2], ch); } this.WriteSurrogateChar(text[++num2], ch); } else { if (XmlCharType.IsLowSurrogate(ch)) { throw XmlConvert.CreateInvalidHighSurrogateCharException(ch); } this.WriteCharEntityImpl(ch); } break; } num2++; offset = num2; while ((num2 < length) && ((this.xmlCharType.charProperties[ch = text[num2]] & 0x80) != 0)) { num2++; } } }
internal unsafe void Write(char[] array, int offset, int count) { if (array == null) { throw new ArgumentNullException("array"); } if (0 > offset) { throw new ArgumentOutOfRangeException("offset"); } if (0 > count) { throw new ArgumentOutOfRangeException("count"); } if (count > (array.Length - offset)) { throw new ArgumentOutOfRangeException("count"); } if (this.cacheAttrValue) { this.attrValue.Append(array, offset, count); } int num = offset + count; int index = offset; char ch = '\0'; while (true) { int num3 = index; while ((index < num) && ((this.xmlCharType.charProperties[ch = array[index]] & 0x80) != 0)) { index++; } if (num3 < index) { this.textWriter.Write(array, num3, index - num3); } if (index == num) { return; } switch (ch) { case '\t': this.textWriter.Write(ch); break; case '\n': case '\r': if (!this.inAttribute) { this.textWriter.Write(ch); } else { this.WriteCharEntityImpl(ch); } break; case '"': if (this.inAttribute && (this.quoteChar == ch)) { this.WriteEntityRefImpl("quot"); } else { this.textWriter.Write('"'); } break; case '&': this.WriteEntityRefImpl("amp"); break; case '\'': if (!this.inAttribute || (this.quoteChar != ch)) { this.textWriter.Write('\''); } else { this.WriteEntityRefImpl("apos"); } break; case '<': this.WriteEntityRefImpl("lt"); break; case '>': this.WriteEntityRefImpl("gt"); break; default: if (XmlCharType.IsHighSurrogate(ch)) { if ((index + 1) >= num) { throw new ArgumentException(Res.GetString("Xml_SurrogatePairSplit")); } this.WriteSurrogateChar(array[++index], ch); } else { if (XmlCharType.IsLowSurrogate(ch)) { throw XmlConvert.CreateInvalidHighSurrogateCharException(ch); } this.WriteCharEntityImpl(ch); } break; } index++; } }