public 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 (;;) { 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 new Exception("throw XmlConvert.CreateInvalidSurrogatePairException(lowChar, ch);"); //throw XmlConvert.CreateInvalidSurrogatePairException(lowChar, ch); } } throw new Exception("throw new ArgumentException(SR.Xml_InvalidSurrogateMissingLowChar);"); } else if (XmlCharType.IsLowSurrogate(ch)) { throw new Exception("throw XmlConvert.CreateInvalidHighSurrogateCharException(ch);"); //throw XmlConvert.CreateInvalidHighSurrogateCharException(ch); } else { i++; } } _textWriter.Write(text); return; }
internal static void VerifyCharData(string data, ExceptionType invCharExceptionType, ExceptionType invSurrogateExceptionType) { if (data == null || data.Length == 0) { return; } int i = 0; int len = data.Length; for (; ;) { while (i < len && s_xmlCharType.IsCharData(data[i])) { i++; } if (i == len) { return; } char ch = data[i]; if (XmlCharType.IsHighSurrogate(ch)) { if (i + 1 == len) { throw CreateException(SR.Xml_InvalidSurrogateMissingLowChar, invSurrogateExceptionType, 0, i + 1); } ch = data[i + 1]; if (XmlCharType.IsLowSurrogate(ch)) { i += 2; continue; } else { throw CreateInvalidSurrogatePairException(data[i + 1], data[i], invSurrogateExceptionType, 0, i + 1); } } throw CreateInvalidCharException(data, i, invCharExceptionType); } }