public virtual XmlWhitespace CreateWhitespace(string text) { if (!XmlChar.IsWhitespace(text)) { throw new ArgumentException("Invalid whitespace characters."); } return(new XmlWhitespace(text, this)); }
internal XmlAttribute( string prefix, string localName, string namespaceURI, XmlDocument doc, bool atomizedNames, bool checkNamespace) : base(doc) { if (!atomizedNames) { if (prefix == null) { prefix = String.Empty; } if (namespaceURI == null) { namespaceURI = String.Empty; } } // Prefix "xml" should be also checked (http://www.w3.org/XML/xml-names-19990114-errata#NE05) // but MS.NET ignores such case if (checkNamespace) { if (prefix == "xmlns" || (prefix == "" && localName == "xmlns")) { if (namespaceURI != XmlNamespaceManager.XmlnsXmlns) { throw new ArgumentException("Invalid attribute namespace for namespace declaration."); } else if (prefix == "xml" && namespaceURI != XmlNamespaceManager.XmlnsXml) { throw new ArgumentException("Invalid attribute namespace for namespace declaration."); } } } if (!atomizedNames) { // There are no means to identify the DOM is // namespace-aware or not, so we can only // check Name validity. if (prefix != "" && !XmlChar.IsName(prefix)) { throw new ArgumentException("Invalid attribute prefix."); } else if (!XmlChar.IsName(localName)) { throw new ArgumentException("Invalid attribute local name."); } prefix = doc.NameTable.Add(prefix); localName = doc.NameTable.Add(localName); namespaceURI = doc.NameTable.Add(namespaceURI); } name = doc.NameCache.Add(prefix, localName, namespaceURI, true); }
public static int IndexOfNonWhitespace(string str) { for (int i = 0; i < str.Length; i++) { if (!XmlChar.IsWhitespace((int)str[i])) { return(i); } } return(-1); }
public static bool IsWhitespace(string str) { for (int i = 0; i < str.Length; i++) { if (!XmlChar.IsWhitespace((int)str[i])) { return(false); } } return(true); }
private int SkipIgnorableBase64Chars(char [] chars, int charsLength, int i) { while (chars [i] == '=' || XmlChar.IsWhitespace(chars [i])) { if (charsLength == ++i) { break; } } return(i); }
public static string VerifyPublicId(string publicId) { if (publicId == null) { throw new ArgumentNullException("publicId"); } if (XmlChar.IsPubid(publicId)) { return(publicId); } throw new XmlException(string.Format("'{0}' is not a valid PUBLIC ID", publicId)); }
public static string VerifyWhitespace(string content) { if (content == null) { throw new ArgumentNullException("content"); } if (XmlChar.IsWhitespace(content)) { return(content); } throw new XmlException(string.Format("'{0}' is not whitespace", content)); }
private int SkipWhitespace(string input, int index) { while (index < input.Length) { if (!XmlChar.IsWhitespace((int)input[index])) { break; } index++; } return(index); }
public static string VerifyNMTOKEN(string name) { if (name == null) { throw new ArgumentNullException("name"); } if (!XmlChar.IsNmToken(name)) { throw new XmlException("'" + name + "' is not a valid XML NMTOKEN"); } return(name); }
public static string VerifyNCName(string ncname) { if (ncname == null || ncname.Length == 0) { throw new ArgumentNullException("ncname"); } if (!XmlChar.IsNCName(ncname)) { throw new XmlException("'" + ncname + "' is not a valid XML NCName"); } return(ncname); }
public static string VerifyXmlChars(string content) { if (content == null) { throw new ArgumentNullException("content"); } var idx = XmlChar.IndexOfInvalid(content, true); if (idx < 0) { return(content); } throw new XmlException(string.Format("Invalid XML character was found in the content, at index {0}.", idx)); }
public static int IndexOfInvalid(string s, bool allowSurrogate) { for (int i = 0; i < s.Length; i++) { if (XmlChar.IsInvalid((int)s[i])) { if (!allowSurrogate || i + 1 == s.Length || s[i] < '\ud800' || s[i] >= '\udc00' || s[i + 1] < '\udc00' || s[i + 1] >= '') { return(i); } i++; } } return(-1); }
public static bool IsNmToken(string str) { if (str.Length == 0) { return(false); } for (int i = 0; i < str.Length; i++) { if (!XmlChar.IsNameChar((int)str[i])) { return(false); } } return(true); }
internal static bool IsInvalid(char c, bool firstOnlyLetter) { if (c == ':') // Special case. allowed in EncodeName, but encoded in EncodeLocalName { return(false); } if (firstOnlyLetter) { return(!XmlChar.IsFirstNameChar(c)); } else { return(!XmlChar.IsNameChar(c)); } }
internal virtual void WriteNmTokenInternal(string name) { bool valid = true; switch (Settings.ConformanceLevel) { case ConformanceLevel.Document: case ConformanceLevel.Fragment: valid = XmlChar.IsNmToken(name); break; } if (!valid) { throw new ArgumentException("Argument name is not a valid NMTOKEN."); } WriteString(name); }
public static bool IsName(string str) { if (str.Length == 0) { return(false); } if (!XmlChar.IsFirstNameChar((int)str[0])) { return(false); } for (int i = 1; i < str.Length; i++) { if (!XmlChar.IsNameChar((int)str[i])) { return(false); } } return(true); }
public static int IndexOfInvalid(char[] s, int start, int length, bool allowSurrogate) { int num = start + length; if (s.Length < num) { throw new ArgumentOutOfRangeException("length"); } for (int i = start; i < num; i++) { if (XmlChar.IsInvalid((int)s[i])) { if (!allowSurrogate || i + 1 == num || s[i] < '\ud800' || s[i] >= '\udc00' || s[i + 1] < '\udc00' || s[i + 1] >= '') { return(i); } i++; } } return(-1); }
internal XmlAttribute(string prefix, string localName, string namespaceURI, XmlDocument doc, bool atomizedNames, bool checkNamespace) : base(doc) { if (!atomizedNames) { if (prefix == null) { prefix = string.Empty; } if (namespaceURI == null) { namespaceURI = string.Empty; } } if (checkNamespace && (prefix == "xmlns" || (prefix == string.Empty && localName == "xmlns"))) { if (namespaceURI != "http://www.w3.org/2000/xmlns/") { throw new ArgumentException("Invalid attribute namespace for namespace declaration."); } if (prefix == "xml" && namespaceURI != "http://www.w3.org/XML/1998/namespace") { throw new ArgumentException("Invalid attribute namespace for namespace declaration."); } } if (!atomizedNames) { if (prefix != string.Empty && !XmlChar.IsName(prefix)) { throw new ArgumentException("Invalid attribute prefix."); } if (!XmlChar.IsName(localName)) { throw new ArgumentException("Invalid attribute local name."); } prefix = doc.NameTable.Add(prefix); localName = doc.NameTable.Add(localName); namespaceURI = doc.NameTable.Add(namespaceURI); } this.name = doc.NameCache.Add(prefix, localName, namespaceURI, true); }
private void ParseInput(string input) { int num = this.SkipWhitespace(input, 0); if (num + 7 > input.Length || input.IndexOf("version", num, 7) != num) { throw new XmlException("Missing 'version' specification."); } num = this.SkipWhitespace(input, num + 7); char c = input[num]; if (c != '=') { throw new XmlException("Invalid 'version' specification."); } num++; num = this.SkipWhitespace(input, num); c = input[num]; if (c != '"' && c != '\'') { throw new XmlException("Invalid 'version' specification."); } num++; int num2 = input.IndexOf(c, num); if (num2 < 0 || input.IndexOf("1.0", num, 3) != num) { throw new XmlException("Invalid 'version' specification."); } num += 4; if (num == input.Length) { return; } if (!XmlChar.IsWhitespace((int)input[num])) { throw new XmlException("Invalid XML declaration."); } num = this.SkipWhitespace(input, num + 1); if (num == input.Length) { return; } if (input.Length > num + 8 && input.IndexOf("encoding", num, 8) > 0) { num = this.SkipWhitespace(input, num + 8); c = input[num]; if (c != '=') { throw new XmlException("Invalid 'version' specification."); } num++; num = this.SkipWhitespace(input, num); c = input[num]; if (c != '"' && c != '\'') { throw new XmlException("Invalid 'encoding' specification."); } num2 = input.IndexOf(c, num + 1); if (num2 < 0) { throw new XmlException("Invalid 'encoding' specification."); } this.Encoding = input.Substring(num + 1, num2 - num - 1); num = num2 + 1; if (num == input.Length) { return; } if (!XmlChar.IsWhitespace((int)input[num])) { throw new XmlException("Invalid XML declaration."); } num = this.SkipWhitespace(input, num + 1); } if (input.Length > num + 10 && input.IndexOf("standalone", num, 10) > 0) { num = this.SkipWhitespace(input, num + 10); c = input[num]; if (c != '=') { throw new XmlException("Invalid 'version' specification."); } num++; num = this.SkipWhitespace(input, num); c = input[num]; if (c != '"' && c != '\'') { throw new XmlException("Invalid 'standalone' specification."); } num2 = input.IndexOf(c, num + 1); if (num2 < 0) { throw new XmlException("Invalid 'standalone' specification."); } string text = input.Substring(num + 1, num2 - num - 1); string text2 = text; if (text2 != null) { if (XmlDeclaration.< > f__switch$map4A == null) { XmlDeclaration.< > f__switch$map4A = new Dictionary <string, int>(2) { { "yes", 0 }, { "no", 0 } }; } int num3; if (XmlDeclaration.< > f__switch$map4A.TryGetValue(text2, out num3)) { if (num3 == 0) { this.Standalone = text; num = num2 + 1; num = this.SkipWhitespace(input, num); goto IL_308; } } } throw new XmlException("Invalid standalone specification."); } IL_308: if (num != input.Length) { throw new XmlException("Invalid XML declaration."); } }
void ParseInput(string input) { int index = SkipWhitespace(input, 0); if (index + 7 > input.Length || input.IndexOf("version", index, 7) != index) { throw new XmlException("Missing 'version' specification."); } index = SkipWhitespace(input, index + 7); char c = input [index]; if (c != '=') { throw new XmlException("Invalid 'version' specification."); } index++; index = SkipWhitespace(input, index); c = input [index]; if (c != '"' && c != '\'') { throw new XmlException("Invalid 'version' specification."); } index++; int end = input.IndexOf(c, index); if (end < 0 || input.IndexOf("1.0", index, 3) != index) { throw new XmlException("Invalid 'version' specification."); } index += 4; if (index == input.Length) { return; } if (!XmlChar.IsWhitespace(input [index])) { throw new XmlException("Invalid XML declaration."); } index = SkipWhitespace(input, index + 1); if (index == input.Length) { return; } if (input.Length > index + 8 && input.IndexOf("encoding", index, 8) > 0) { index = SkipWhitespace(input, index + 8); c = input [index]; if (c != '=') { throw new XmlException("Invalid 'version' specification."); } index++; index = SkipWhitespace(input, index); c = input [index]; if (c != '"' && c != '\'') { throw new XmlException("Invalid 'encoding' specification."); } end = input.IndexOf(c, index + 1); if (end < 0) { throw new XmlException("Invalid 'encoding' specification."); } Encoding = input.Substring(index + 1, end - index - 1); index = end + 1; if (index == input.Length) { return; } if (!XmlChar.IsWhitespace(input [index])) { throw new XmlException("Invalid XML declaration."); } index = SkipWhitespace(input, index + 1); } if (input.Length > index + 10 && input.IndexOf("standalone", index, 10) > 0) { index = SkipWhitespace(input, index + 10); c = input [index]; if (c != '=') { throw new XmlException("Invalid 'version' specification."); } index++; index = SkipWhitespace(input, index); c = input [index]; if (c != '"' && c != '\'') { throw new XmlException("Invalid 'standalone' specification."); } end = input.IndexOf(c, index + 1); if (end < 0) { throw new XmlException("Invalid 'standalone' specification."); } string tmp = input.Substring(index + 1, end - index - 1); switch (tmp) { case "yes": case "no": break; default: throw new XmlException("Invalid standalone specification."); } Standalone = tmp; index = end + 1; index = SkipWhitespace(input, index); } if (index != input.Length) { throw new XmlException("Invalid XML declaration."); } }
private void Initialize(Stream stream) { buffer = new byte [6]; this.stream = stream; enc = StrictUTF8; // Default to UTF8 if we can't guess it bufLength = stream.Read(buffer, 0, buffer.Length); if (bufLength == -1 || bufLength == 0) { return; } int c = ReadByteSpecial(); switch (c) { case 0xFF: c = ReadByteSpecial(); if (c == 0xFE) { // BOM-ed little endian utf-16 enc = Encoding.Unicode; } else { // It doesn't start from "<?xml" then its encoding is utf-8 bufPos = 0; } break; case 0xFE: c = ReadByteSpecial(); if (c == 0xFF) { // BOM-ed big endian utf-16 enc = Encoding.BigEndianUnicode; return; } else { // It doesn't start from "<?xml" then its encoding is utf-8 bufPos = 0; } break; case 0xEF: c = ReadByteSpecial(); if (c == 0xBB) { c = ReadByteSpecial(); if (c != 0xBF) { bufPos = 0; } } else { buffer [--bufPos] = 0xEF; } break; case 0: // It could still be 1234/2143/3412 variants of UTF32, but only 1234 version is available on .NET. c = ReadByteSpecial(); if (c == 0) { enc = Strict1234UTF32; } else { enc = StrictBigEndianUTF16; } break; case '<': c = ReadByteSpecial(); if (c == 0) { if (ReadByteSpecial() == 0) { enc = Encoding.UTF32; // little endian UTF32 } else { enc = Encoding.Unicode; // little endian UTF16 } } else if (bufLength >= 4 && GetStringFromBytes(1, 4) == "?xml") { // try to get encoding name from XMLDecl. bufPos += 4; c = SkipWhitespace(); // version. It is optional here. if (c == 'v') { while (c >= 0) { c = ReadByteSpecial(); if (c == '0') // 0 of 1.0 { ReadByteSpecial(); break; } } c = SkipWhitespace(); } if (c == 'e') { if (GetStringFromBytes(bufPos, 7) == "ncoding") { bufPos += 7; c = SkipWhitespace(); if (c != '=') { throw encodingException; } c = SkipWhitespace(); int quoteChar = c; StringBuilder sb = new StringBuilder(); while (true) { c = ReadByteSpecial(); if (c == quoteChar) { break; } else if (c < 0) { throw encodingException; } sb.Append((char)c); } string encodingName = sb.ToString(); if (!XmlChar.IsValidIANAEncoding(encodingName)) { throw encodingException; } enc = Encoding.GetEncoding(encodingName); } } } #if TARGET_JVM else { if (bufLength >= 10 && Encoding.Unicode.GetString(buffer, 2, 8) == "?xml") { enc = Encoding.Unicode; } } #endif bufPos = 0; break; default: bufPos = 0; break; } }
public static bool IsPublicIdChar(char ch) { return(XmlChar.IsPubidChar(ch)); }
public static bool IsPubidChar(int ch) { return((XmlChar.IsWhitespace(ch) && ch != 9) | (97 <= ch && ch <= 122) | (65 <= ch && ch <= 90) | (48 <= ch && ch <= 57) | "-'()+,./:=?;!*#@$_%".IndexOf((char)ch) >= 0); }
public static bool IsXmlChar(char ch) { return(XmlChar.IsValid(ch)); }
public static bool IsValid(int ch) { return(!XmlChar.IsInvalid(ch)); }
public static bool IsStartNCNameChar(char ch) { return(XmlChar.IsFirstNameChar(ch)); }
public static bool IsNameToken(string s) { return(s != null && XmlChar.IsNmToken(s)); }
private void Initialize(Stream stream) { this.buffer = new byte[64]; this.stream = stream; this.enc = XmlInputStream.StrictUTF8; this.bufLength = stream.Read(this.buffer, 0, this.buffer.Length); if (this.bufLength == -1 || this.bufLength == 0) { return; } int i = this.ReadByteSpecial(); int num = i; if (num != 254) { if (num != 255) { if (num != 60) { if (num != 239) { this.bufPos = 0; } else { i = this.ReadByteSpecial(); if (i == 187) { i = this.ReadByteSpecial(); if (i != 191) { this.bufPos = 0; } } else { this.buffer[--this.bufPos] = 239; } } } else { if (this.bufLength >= 5 && XmlInputStream.GetStringFromBytes(this.buffer, 1, 4) == "?xml") { this.bufPos += 4; i = this.SkipWhitespace(); if (i == 118) { while (i >= 0) { i = this.ReadByteSpecial(); if (i == 48) { this.ReadByteSpecial(); break; } } i = this.SkipWhitespace(); } if (i == 101) { int num2 = this.bufLength - this.bufPos; if (num2 >= 7 && XmlInputStream.GetStringFromBytes(this.buffer, this.bufPos, 7) == "ncoding") { this.bufPos += 7; i = this.SkipWhitespace(); if (i != 61) { throw XmlInputStream.encodingException; } i = this.SkipWhitespace(); int num3 = i; StringBuilder stringBuilder = new StringBuilder(); for (;;) { i = this.ReadByteSpecial(); if (i == num3) { break; } if (i < 0) { goto Block_19; } stringBuilder.Append((char)i); } string text = stringBuilder.ToString(); if (!XmlChar.IsValidIANAEncoding(text)) { throw XmlInputStream.encodingException; } this.enc = Encoding.GetEncoding(text); goto IL_272; Block_19: throw XmlInputStream.encodingException; } } } IL_272: this.bufPos = 0; } } else { i = this.ReadByteSpecial(); if (i == 254) { this.enc = Encoding.Unicode; } else { this.bufPos = 0; } } } else { i = this.ReadByteSpecial(); if (i == 255) { this.enc = Encoding.BigEndianUnicode; return; } this.bufPos = 0; } }
public static bool IsWhitespaceChar(char ch) { return(XmlChar.IsWhitespace(ch)); }
public static bool IsNCNameChar(char ch) { return(XmlChar.IsNCNameChar(ch)); }