private void ReadDeclaration() { int num; if (!this.buffered) { this.BufferElement(); } byte[] bytes = base.BufferReader.GetBuffer(5, out num); if (((bytes[num] != 0x3f) || (bytes[num + 1] != 120)) || (((bytes[num + 2] != 0x6d) || (bytes[num + 3] != 0x6c)) || ((charType[bytes[num + 4]] & 4) == 0))) { XmlExceptionHelper.ThrowProcessingInstructionNotSupported(this); } if (base.Node.ReadState != System.Xml.ReadState.Initial) { XmlExceptionHelper.ThrowDeclarationNotFirst(this); } base.BufferReader.Advance(5); int offset = num + 1; int length = 3; int num4 = base.BufferReader.Offset; this.SkipWhitespace(); this.ReadAttributes(); int num5 = base.BufferReader.Offset - num4; while (num5 > 0) { byte @byte = base.BufferReader.GetByte((num4 + num5) - 1); if ((charType[@byte] & 4) == 0) { break; } num5--; } bytes = base.BufferReader.GetBuffer(2, out num); if ((bytes[num] != 0x3f) || (bytes[num + 1] != 0x3e)) { XmlExceptionHelper.ThrowTokenExpected(this, "?>", Encoding.UTF8.GetString(bytes, num, 2)); } base.BufferReader.Advance(2); XmlBaseReader.XmlDeclarationNode node = base.MoveToDeclaration(); node.LocalName.SetValue(offset, length); node.Value.SetValue(ValueHandleType.UTF8, num4, num5); }
public int GetCharEntity(int offset, int length) { if (length < 3) { XmlExceptionHelper.ThrowInvalidCharRef(_reader); } byte[] buffer = _buffer; DiagnosticUtility.DebugAssert(buffer[offset] == '&', ""); DiagnosticUtility.DebugAssert(buffer[offset + length - 1] == ';', ""); switch (buffer[offset + 1]) { case (byte)'l': return(GetLessThanCharEntity(offset, length)); case (byte)'g': return(GetGreaterThanCharEntity(offset, length)); case (byte)'a': if (buffer[offset + 2] == (byte)'m') { return(GetAmpersandCharEntity(offset, length)); } else { return(GetApostropheCharEntity(offset, length)); } case (byte)'q': return(GetQuoteCharEntity(offset, length)); case (byte)'#': if (buffer[offset + 2] == (byte)'x') { return(GetHexCharEntity(offset, length)); } else { return(GetDecimalCharEntity(offset, length)); } default: XmlExceptionHelper.ThrowInvalidCharRef(_reader); return(0); } }
public static bool ToBoolean(string value) { bool flag; try { flag = XmlConvert.ToBoolean(value); } catch (ArgumentException exception) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlExceptionHelper.CreateConversionException(value, "Boolean", exception)); } catch (FormatException exception2) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlExceptionHelper.CreateConversionException(value, "Boolean", exception2)); } return(flag); }
public static UniqueId ToUniqueId(string value) { UniqueId id; try { id = new UniqueId(Trim(value)); } catch (ArgumentException exception) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlExceptionHelper.CreateConversionException(value, "UniqueId", exception)); } catch (FormatException exception2) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlExceptionHelper.CreateConversionException(value, "UniqueId", exception2)); } return(id); }
public static DateTime ToDateTime(string value) { DateTime time; try { time = XmlConvert.ToDateTime(value, XmlDateTimeSerializationMode.RoundtripKind); } catch (ArgumentException exception) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlExceptionHelper.CreateConversionException(value, "DateTime", exception)); } catch (FormatException exception2) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlExceptionHelper.CreateConversionException(value, "DateTime", exception2)); } return(time); }
static public decimal ToDecimal(string value) { try { return(XmlConvert.ToDecimal(value)); } catch (ArgumentException exception) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlExceptionHelper.CreateConversionException(value, "decimal", exception)); } catch (FormatException exception) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlExceptionHelper.CreateConversionException(value, "decimal", exception)); } catch (OverflowException exception) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlExceptionHelper.CreateConversionException(value, "decimal", exception)); } }
public static TimeSpan ToTimeSpan(string value) { try { return(XmlConvert.ToTimeSpan(value)); } catch (ArgumentException exception) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlExceptionHelper.CreateConversionException(value, "TimeSpan", exception)); } catch (FormatException exception) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlExceptionHelper.CreateConversionException(value, "TimeSpan", exception)); } catch (OverflowException exception) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlExceptionHelper.CreateConversionException(value, "TimeSpan", exception)); } }
public XmlDictionaryString GetDictionaryString(int key) { IXmlDictionary session; XmlDictionaryString str; if ((key & 1) != 0) { session = this.session; } else { session = this.dictionary; } if (!session.TryLookup((int)(key >> 1), out str)) { XmlExceptionHelper.ThrowInvalidBinaryFormat(this.reader); } return(str); }
public static Guid ToGuid(string value) { try { return(new Guid(Trim(value))); } catch (FormatException exception) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlExceptionHelper.CreateConversionException(value, "Guid", exception)); } catch (ArgumentException exception) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlExceptionHelper.CreateConversionException(value, "Guid", exception)); } catch (OverflowException exception) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlExceptionHelper.CreateConversionException(value, "Guid", exception)); } }
public static ulong ToUInt64(string value) { try { return(ulong.Parse(value, NumberStyles.Any, NumberFormatInfo.InvariantInfo)); } catch (ArgumentException exception) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlExceptionHelper.CreateConversionException(value, "UInt64", exception)); } catch (FormatException exception) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlExceptionHelper.CreateConversionException(value, "UInt64", exception)); } catch (OverflowException exception) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlExceptionHelper.CreateConversionException(value, "UInt64", exception)); } }
public virtual bool ReadToNextSibling(string name) { if (name == null || name.Length == 0) { throw XmlExceptionHelper.CreateInvalidNameArgumentException(name, nameof(name)); } name = this.NameTable.Add(name); XmlNodeType nodeType; do { this.SkipSubtree(); nodeType = this.NodeType; if (nodeType == XmlNodeType.Element && Ref.Equal(name, this.Name)) { return(true); } }while (nodeType != XmlNodeType.EndElement && !this.EOF); return(false); }
private int GetDecimalCharEntity(int offset, int length) { byte[] buffer = this.buffer; int num = 0; for (int i = 2; i < (length - 1); i++) { byte num3 = buffer[offset + i]; if ((num3 < 0x30) || (num3 > 0x39)) { XmlExceptionHelper.ThrowInvalidCharRef(this.reader); } num = (num * 10) + (num3 - 0x30); if (num > 0x10ffff) { XmlExceptionHelper.ThrowInvalidCharRef(this.reader); } } return(num); }
public XmlDictionaryString GetDictionaryString(int key) { IXmlDictionary keyDictionary; if ((key & 1) != 0) { keyDictionary = _session; } else { keyDictionary = _dictionary; } XmlDictionaryString s; if (!keyDictionary.TryLookup(key >> 1, out s)) { XmlExceptionHelper.ThrowInvalidBinaryFormat(_reader); } return(s); }
/// <summary> /// Split a QualifiedName into prefix and localname, w/o any checking. /// (Used for XmlReader/XPathNavigator MoveTo(name) methods) /// </summary> internal static void SplitQName(string name, out string prefix, out string lname) { int colonPos = name.IndexOf(':'); if (-1 == colonPos) { prefix = string.Empty; lname = name; } else if (0 == colonPos || (name.Length - 1) == colonPos) { throw new ArgumentException(SR.Format(SR.Xml_BadNameChar, XmlExceptionHelper.BuildCharExceptionArgs(':', '\0')), "name"); } else { prefix = name.Substring(0, colonPos); colonPos++; // move after colon lname = name.Substring(colonPos, name.Length - colonPos); } }
public virtual bool ReadToFollowing(string localName, string namespaceURI) { if (localName == null || localName.Length == 0) { throw XmlExceptionHelper.CreateInvalidNameArgumentException(localName, nameof(localName)); } if (namespaceURI == null) { throw new ArgumentNullException(nameof(namespaceURI)); } localName = this.NameTable.Add(localName); namespaceURI = this.NameTable.Add(namespaceURI); while (this.Read()) { if (this.NodeType == XmlNodeType.Element && Ref.Equal(localName, this.LocalName) && Ref.Equal(namespaceURI, this.NamespaceURI)) { return(true); } } return(false); }
// Reads to the following element with the given Name. public virtual bool ReadToFollowing(string name) { if (name == null || name.Length == 0) { throw XmlExceptionHelper.CreateInvalidNameArgumentException(name, "name"); } // atomize name name = NameTable.Add(name); // find following element with that name while (Read()) { if (NodeType == XmlNodeType.Element && Ref.Equal(name, Name)) { return(true); } } return(false); }
/// <summary> /// Throws an invalid name exception. /// </summary> /// <param name="s">String that was parsed.</param> /// <param name="offsetStartChar">Offset in string where parsing began.</param> /// <param name="offsetBadChar">Offset in string where parsing failed.</param> internal static void ThrowInvalidName(string s, int offsetStartChar, int offsetBadChar) { // If the name is empty, throw an exception if (offsetStartChar >= s.Length) { throw new XmlException(SR.Xml_EmptyName); } Debug.Assert(offsetBadChar < s.Length); if (xmlCharType.IsNCNameSingleChar(s[offsetBadChar]) && !XmlCharType.Instance.IsStartNCNameSingleChar(s[offsetBadChar])) { // The error character is a valid name character, but is not a valid start name character throw new XmlException(SR.Format(SR.Xml_BadStartNameChar, XmlExceptionHelper.BuildCharExceptionArgs(s, offsetBadChar))); } else { // The error character is an invalid name character throw new XmlException(SR.Format(SR.Xml_BadNameChar, XmlExceptionHelper.BuildCharExceptionArgs(s, offsetBadChar))); } }
public int ReadDictionaryKey() { int key = ReadMultiByteUInt31(); if ((key & 1) != 0) { if (_session == null) { XmlExceptionHelper.ThrowInvalidBinaryFormat(_reader); } int sessionKey = (key >> 1); XmlDictionaryString xmlString; if (!_session.TryLookup(sessionKey, out xmlString)) { if (sessionKey < XmlDictionaryString.MinKey || sessionKey > XmlDictionaryString.MaxKey) { XmlExceptionHelper.ThrowXmlDictionaryStringIDOutOfRange(_reader); } XmlExceptionHelper.ThrowXmlDictionaryStringIDUndefinedSession(_reader, sessionKey); } } else { if (_dictionary == null) { XmlExceptionHelper.ThrowInvalidBinaryFormat(_reader); } int staticKey = (key >> 1); XmlDictionaryString xmlString; if (!_dictionary.TryLookup(staticKey, out xmlString)) { if (staticKey < XmlDictionaryString.MinKey || staticKey > XmlDictionaryString.MaxKey) { XmlExceptionHelper.ThrowXmlDictionaryStringIDOutOfRange(_reader); } XmlExceptionHelper.ThrowXmlDictionaryStringIDUndefinedStatic(_reader, staticKey); } } return(key); }
public static float ToSingle(string value) { float num; try { num = XmlConvert.ToSingle(value); } catch (ArgumentException exception) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlExceptionHelper.CreateConversionException(value, "float", exception)); } catch (FormatException exception2) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlExceptionHelper.CreateConversionException(value, "float", exception2)); } catch (OverflowException exception3) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlExceptionHelper.CreateConversionException(value, "float", exception3)); } return(num); }
public TimeSpan ReadTimeSpan() { long value = 0; try { value = ReadInt64(); return(TimeSpan.FromTicks(value)); } catch (ArgumentException exception) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlExceptionHelper.CreateConversionException(value.ToString(CultureInfo.InvariantCulture), "TimeSpan", exception)); } catch (FormatException exception) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlExceptionHelper.CreateConversionException(value.ToString(CultureInfo.InvariantCulture), "TimeSpan", exception)); } catch (OverflowException exception) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlExceptionHelper.CreateConversionException(value.ToString(CultureInfo.InvariantCulture), "TimeSpan", exception)); } }
public DateTime ReadDateTime() { long value = 0; try { value = ReadInt64(); return(DateTime.FromBinary(value)); } catch (ArgumentException exception) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlExceptionHelper.CreateConversionException(value.ToString(CultureInfo.InvariantCulture), "DateTime", exception)); } catch (FormatException exception) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlExceptionHelper.CreateConversionException(value.ToString(CultureInfo.InvariantCulture), "DateTime", exception)); } catch (OverflowException exception) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlExceptionHelper.CreateConversionException(value.ToString(CultureInfo.InvariantCulture), "DateTime", exception)); } }
public unsafe decimal GetDecimal(int offset) { byte[] buffer = this.buffer; byte num = buffer[offset]; byte num2 = buffer[offset + 1]; byte num3 = buffer[offset + 2]; byte num4 = buffer[offset + 3]; int num5 = (((((num4 << 8) + num3) << 8) + num2) << 8) + num; if (((num5 & 0x7f00ffff) == 0) && ((num5 & 0xff0000) <= 0x1c0000)) { decimal num6; byte * numPtr = (byte *)&num6; for (int i = 0; i < 0x10; i++) { numPtr[i] = buffer[offset + i]; } return(num6); } XmlExceptionHelper.ThrowInvalidBinaryFormat(this.reader); return(0M); }
public int ReadMultiByteUInt31() { int @byte = this.GetByte(); this.Advance(1); if ((@byte & 0x80) != 0) { @byte &= 0x7f; int num2 = this.GetByte(); this.Advance(1); @byte |= (num2 & 0x7f) << 7; if ((num2 & 0x80) == 0) { return(@byte); } int num3 = this.GetByte(); this.Advance(1); @byte |= (num3 & 0x7f) << 14; if ((num3 & 0x80) == 0) { return(@byte); } int num4 = this.GetByte(); this.Advance(1); @byte |= (num4 & 0x7f) << 0x15; if ((num4 & 0x80) == 0) { return(@byte); } int num5 = this.GetByte(); this.Advance(1); @byte |= num5 << 0x1c; if ((num5 & 0xf8) != 0) { XmlExceptionHelper.ThrowInvalidBinaryFormat(this.reader); } } return(@byte); }
public int ReadDictionaryKey() { XmlDictionaryString str2; int num = this.ReadMultiByteUInt31(); if ((num & 1) != 0) { XmlDictionaryString str; if (this.session == null) { XmlExceptionHelper.ThrowInvalidBinaryFormat(this.reader); } int num2 = num >> 1; if (!this.session.TryLookup(num2, out str)) { if ((num2 < 0) || (num2 > 0x1fffffff)) { XmlExceptionHelper.ThrowXmlDictionaryStringIDOutOfRange(this.reader); } XmlExceptionHelper.ThrowXmlDictionaryStringIDUndefinedSession(this.reader, num2); } return(num); } if (this.dictionary == null) { XmlExceptionHelper.ThrowInvalidBinaryFormat(this.reader); } int key = num >> 1; if (!this.dictionary.TryLookup(key, out str2)) { if ((key < 0) || (key > 0x1fffffff)) { XmlExceptionHelper.ThrowXmlDictionaryStringIDOutOfRange(this.reader); } XmlExceptionHelper.ThrowXmlDictionaryStringIDUndefinedStatic(this.reader, key); } return(num); }
private void ReadStartElement() { if (!this.buffered) { this.BufferElement(); } XmlBaseReader.XmlElementNode node = base.EnterScope(); node.NameOffset = base.BufferReader.Offset; this.ReadQualifiedName(node.Prefix, node.LocalName); node.NameLength = base.BufferReader.Offset - node.NameOffset; byte @byte = base.BufferReader.GetByte(); while ((charType[@byte] & 4) != 0) { base.BufferReader.SkipByte(); @byte = base.BufferReader.GetByte(); } if ((@byte != 0x3e) && (@byte != 0x2f)) { this.ReadAttributes(); @byte = base.BufferReader.GetByte(); } node.Namespace = base.LookupNamespace(node.Prefix); bool flag = false; if (@byte == 0x2f) { flag = true; base.BufferReader.SkipByte(); } node.IsEmptyElement = flag; node.ExitScope = flag; if (base.BufferReader.GetByte() != 0x3e) { XmlExceptionHelper.ThrowTokenExpected(this, ">", (char)base.BufferReader.GetByte()); } base.BufferReader.SkipByte(); node.BufferOffset = base.BufferReader.Offset; }
public static Guid ToGuid(string value) { Guid guid; try { guid = Guid.Parse(Trim(value)); } catch (FormatException exception) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlExceptionHelper.CreateConversionException(value, "Guid", exception)); } catch (ArgumentException exception2) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlExceptionHelper.CreateConversionException(value, "Guid", exception2)); } catch (OverflowException exception3) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlExceptionHelper.CreateConversionException(value, "Guid", exception3)); } return(guid); }
private int GetHexCharEntity(int offset, int length) { byte[] buffer = _buffer; DiagnosticUtility.DebugAssert(buffer[offset + 0] == '&', ""); DiagnosticUtility.DebugAssert(buffer[offset + 1] == '#', ""); DiagnosticUtility.DebugAssert(buffer[offset + 2] == 'x', ""); DiagnosticUtility.DebugAssert(buffer[offset + length - 1] == ';', ""); int value = 0; for (int i = 3; i < length - 1; i++) { byte ch = buffer[offset + i]; int digit = 0; if (ch >= '0' && ch <= '9') { digit = (ch - '0'); } else if (ch >= 'a' && ch <= 'f') { digit = 10 + (ch - 'a'); } else if (ch >= 'A' && ch <= 'F') { digit = 10 + (ch - 'A'); } else { XmlExceptionHelper.ThrowInvalidCharRef(_reader); } DiagnosticUtility.DebugAssert(digit >= 0 && digit < 16, ""); value = value * 16 + digit; if (value > SurrogateChar.MaxValue) { XmlExceptionHelper.ThrowInvalidCharRef(_reader); } } return(value); }
private bool TryEnsureBytes(int count) { if (this.stream == null) { return(false); } if (this.offset > (0x7fffffff - count)) { XmlExceptionHelper.ThrowMaxBytesPerReadExceeded(this.reader, this.windowOffsetMax - this.windowOffset); } int num = this.offset + count; if (num >= this.offsetMax) { int num3; if (num > this.windowOffsetMax) { XmlExceptionHelper.ThrowMaxBytesPerReadExceeded(this.reader, this.windowOffsetMax - this.windowOffset); } if (num > this.buffer.Length) { byte[] dst = new byte[Math.Max(num, this.buffer.Length * 2)]; System.Buffer.BlockCopy(this.buffer, 0, dst, 0, this.offsetMax); this.buffer = dst; this.streamBuffer = dst; } for (int i = num - this.offsetMax; i > 0; i -= num3) { num3 = this.stream.Read(this.buffer, this.offsetMax, i); if (num3 == 0) { return(false); } this.offsetMax += num3; } } return(true); }
private int GetDecimalCharEntity(int offset, int length) { byte[] buffer = _buffer; DiagnosticUtility.DebugAssert(buffer[offset + 0] == '&', ""); DiagnosticUtility.DebugAssert(buffer[offset + 1] == '#', ""); DiagnosticUtility.DebugAssert(buffer[offset + length - 1] == ';', ""); int value = 0; for (int i = 2; i < length - 1; i++) { byte ch = buffer[offset + i]; if (ch < (byte)'0' || ch > (byte)'9') { XmlExceptionHelper.ThrowInvalidCharRef(_reader); } value = value * 10 + (ch - '0'); if (value > SurrogateChar.MaxValue) { XmlExceptionHelper.ThrowInvalidCharRef(_reader); } } return(value); }
private void ReadList(ValueHandle value) { _listValue ??= new ValueHandle(this); int count = 0; int offset = this.Offset; while (true) { XmlBinaryNodeType nodeType = GetNodeType(); SkipNodeType(); if (nodeType == XmlBinaryNodeType.StartListText) { XmlExceptionHelper.ThrowInvalidBinaryFormat(_reader); } if (nodeType == XmlBinaryNodeType.EndListText) { break; } ReadValue(nodeType, _listValue); count++; } value.SetValue(ValueHandleType.List, offset, count); }