BuildCharExceptionArgs() static private method

static private BuildCharExceptionArgs ( char invChar, char nextChar ) : string[]
invChar char
nextChar char
return string[]
示例#1
0
        private void CheckWhitespace(string value)
        {
            int invCharIndex = this.xmlCharType.IsOnlyWhitespaceWithPos(value);

            if (invCharIndex != -1)
            {
                this.Throw("Xml_InvalidWhitespaceCharacter", XmlException.BuildCharExceptionArgs(value, invCharIndex));
            }
        }
示例#2
0
        private void CheckWhitespace(string value)
        {
            int i;

            if ((i = _xmlCharType.IsOnlyWhitespaceWithPos(value)) != -1)
            {
                Throw(SR.Xml_InvalidWhitespaceCharacter, XmlException.BuildCharExceptionArgs(value, i));
            }
        }
示例#3
0
        protected void ValidateContentChars(string chars, string propertyName, bool allowOnlyWhitespace)
        {
            if (allowOnlyWhitespace)
            {
                if (!this.xmlCharType.IsOnlyWhitespace(chars))
                {
                    throw new ArgumentException(Res.GetString("Xml_IndentCharsNotWhitespace", new object[] { propertyName }));
                }
                return;
            }
            string str = null;

            for (int i = 0; i < chars.Length; i++)
            {
                if (this.xmlCharType.IsTextChar(chars[i]))
                {
                    continue;
                }
                switch (chars[i])
                {
                case '<':
                case ']':
                case '&':
                    str = Res.GetString("Xml_InvalidCharacter", XmlException.BuildCharExceptionArgs(chars, i));
                    goto Label_0132;

                case '\t':
                case '\n':
                case '\r':
                {
                    continue;
                }
                }
                if (XmlCharType.IsHighSurrogate(chars[i]))
                {
                    if (((i + 1) < chars.Length) && XmlCharType.IsLowSurrogate(chars[i + 1]))
                    {
                        i++;
                        continue;
                    }
                    str = Res.GetString("Xml_InvalidSurrogateMissingLowChar");
                    goto Label_0132;
                }
                if (XmlCharType.IsLowSurrogate(chars[i]))
                {
                    object[] args = new object[] { ((uint)chars[i]).ToString("X", CultureInfo.InvariantCulture) };
                    str = Res.GetString("Xml_InvalidSurrogateHighChar", args);
                    goto Label_0132;
                }
            }
            return;

            Label_0132 :;
            throw new ArgumentException(Res.GetString("Xml_InvalidCharsInIndent", new string[] { propertyName, str }));
        }
示例#4
0
 internal static void ThrowInvalidName(string s, int offsetStartChar, int offsetBadChar)
 {
     if (offsetStartChar >= s.Length)
     {
         throw new XmlException("Xml_EmptyName", string.Empty);
     }
     if (xmlCharType.IsNCNameSingleChar(s[offsetBadChar]) && !XmlCharType.Instance.IsStartNCNameSingleChar(s[offsetBadChar]))
     {
         throw new XmlException("Xml_BadStartNameChar", XmlException.BuildCharExceptionArgs(s, offsetBadChar));
     }
     throw new XmlException("Xml_BadNameChar", XmlException.BuildCharExceptionArgs(s, offsetBadChar));
 }
示例#5
0
 internal static Exception GetInvalidNameException(string s, int offsetStartChar, int offsetBadChar)
 {
     if (offsetStartChar >= s.Length)
     {
         return(new XmlException("Xml_EmptyName", string.Empty));
     }
     if (xmlCharType.IsNCNameSingleChar(s[offsetBadChar]) && !xmlCharType.IsStartNCNameSingleChar(s[offsetBadChar]))
     {
         return(new XmlException("Xml_BadStartNameChar", XmlException.BuildCharExceptionArgs(s, offsetBadChar)));
     }
     return(new XmlException("Xml_BadNameChar", XmlException.BuildCharExceptionArgs(s, offsetBadChar)));
 }
        private void ValidateQName(string name)
        {
            if (name.Length == 0)
            {
                throw new ArgumentException(SR.Xml_EmptyName);
            }
            int colonPos;
            int len = ValidateNames.ParseQName(name, 0, out colonPos);

            if (len != name.Length)
            {
                string res = (len == 0 || (colonPos > -1 && len == colonPos + 1)) ? SR.Xml_BadStartNameChar : SR.Xml_BadNameChar;
                throw new ArgumentException(string.Format(res, XmlException.BuildCharExceptionArgs(name, len)));
            }
        }
        private void ValidateQName(string name)
        {
            int num;

            if (name.Length == 0)
            {
                throw new ArgumentException(Res.GetString("Xml_EmptyName"));
            }
            int invCharIndex = ValidateNames.ParseQName(name, 0, out num);

            if (invCharIndex != name.Length)
            {
                string str = ((invCharIndex == 0) || ((num > -1) && (invCharIndex == (num + 1)))) ? "Xml_BadStartNameChar" : "Xml_BadNameChar";
                throw new ArgumentException(Res.GetString(str, XmlException.BuildCharExceptionArgs(name, invCharIndex)));
            }
        }
示例#8
0
        // Verification method for XML whitespace characters as defined in XML spec production [3] S.
        // Throws XmlException if invalid character is found, otherwise returns the input string.
        public static string VerifyWhitespace(string content)
        {
            if (content == null)
            {
                throw new ArgumentNullException("content");
            }

            // returns the position of invalid character or -1
            int pos = s_xmlCharType.IsOnlyWhitespaceWithPos(content);

            if (pos != -1)
            {
                throw new XmlException(SR.Xml_InvalidWhitespaceCharacter, XmlException.BuildCharExceptionArgs(content, pos), 0, pos + 1);
            }
            return(content);
        }
示例#9
0
        internal static string VerifyQName(string name, ExceptionType exceptionType)
        {
            if (name == null || name.Length == 0)
            {
                throw new ArgumentNullException("name");
            }

            int colonPosition = -1;

            int endPos = ValidateNames.ParseQName(name, 0, out colonPosition);

            if (endPos != name.Length)
            {
                throw CreateException(SR.Xml_BadNameChar, XmlException.BuildCharExceptionArgs(name, endPos), exceptionType, 0, endPos + 1);
            }
            return(name);
        }
示例#10
0
        internal static string VerifyNMTOKEN(string name, ExceptionType exceptionType)
        {
            if (name == null)
            {
                throw new ArgumentNullException("name");
            }
            if (name.Length == 0)
            {
                throw CreateException(SR.Xml_InvalidNmToken, name, exceptionType);
            }

            int endPos = ValidateNames.ParseNmtokenNoNamespaces(name, 0);

            if (endPos != name.Length)
            {
                throw CreateException(SR.Xml_BadNameChar, XmlException.BuildCharExceptionArgs(name, endPos), exceptionType, 0, endPos + 1);
            }
            return(name);
        }
示例#11
0
        /// <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, XmlException.BuildCharExceptionArgs(':', '\0')), nameof(name));
            }
            else
            {
                prefix = name.Substring(0, colonPos);
                colonPos++; // move after colon
                lname = name.Substring(colonPos, name.Length - colonPos);
            }
        }
示例#12
0
        internal static void SplitQName(string name, out string prefix, out string lname)
        {
            int index = name.IndexOf(':');

            if (-1 == index)
            {
                prefix = string.Empty;
                lname  = name;
            }
            else
            {
                if ((index == 0) || ((name.Length - 1) == index))
                {
                    throw new ArgumentException(Res.GetString("Xml_BadNameChar", XmlException.BuildCharExceptionArgs(':', '\0')), "name");
                }
                prefix = name.Substring(0, index);
                index++;
                lname = name.Substring(index, name.Length - index);
            }
        }
示例#13
0
        internal static Exception GetInvalidNameException(string s, int offsetStartChar, int offsetBadChar)
        {
            // If the name is empty, throw an exception
            if (offsetStartChar >= s.Length)
            {
                return(new XmlException(SR.Xml_EmptyName, string.Empty));
            }

            Debug.Assert(offsetBadChar < s.Length);

            if (s_xmlCharType.IsNCNameSingleChar(s[offsetBadChar]) && !s_xmlCharType.IsStartNCNameSingleChar(s[offsetBadChar]))
            {
                // The error character is a valid name character, but is not a valid start name character
                return(new XmlException(SR.Xml_BadStartNameChar, XmlException.BuildCharExceptionArgs(s, offsetBadChar)));
            }
            else
            {
                // The error character is an invalid name character
                return(new XmlException(SR.Xml_BadNameChar, XmlException.BuildCharExceptionArgs(s, offsetBadChar)));
            }
        }
示例#14
0
 public override Task WriteWhitespaceAsync(string ws)
 {
     if (ws == null)
     {
         ws = string.Empty;
     }
     // "checkNames" is intentional here; if false, the whitespace is checked in XmlWellformedWriter
     if (_checkNames)
     {
         int i;
         if ((i = _xmlCharType.IsOnlyWhitespaceWithPos(ws)) != -1)
         {
             throw new ArgumentException(SR.Format(SR.Xml_InvalidWhitespaceCharacter, XmlException.BuildCharExceptionArgs(ws, i)));
         }
     }
     if (_replaceNewLines)
     {
         ws = ReplaceNewLines(ws);
     }
     return(writer.WriteWhitespaceAsync(ws));
 }
        public override void WriteWhitespace(string ws)
        {
            int num;

            if (ws == null)
            {
                ws = string.Empty;
            }
            if (this.checkNames && ((num = this.xmlCharType.IsOnlyWhitespaceWithPos(ws)) != -1))
            {
                throw new ArgumentException(Res.GetString("Xml_InvalidWhitespaceCharacter", XmlException.BuildCharExceptionArgs(ws, num)));
            }
            if (this.replaceNewLines)
            {
                ws = this.ReplaceNewLines(ws);
            }
            base.writer.WriteWhitespace(ws);
        }
示例#16
0
        public override bool Read()
        {
            switch (_state)
            {
            case State.Initial:
                _state = State.Interactive;
                if (base.reader.ReadState == ReadState.Initial)
                {
                    goto case State.Interactive;
                }
                break;

            case State.Error:
                return(false);

            case State.InReadBinary:
                FinishReadBinary();
                _state = State.Interactive;
                goto case State.Interactive;

            case State.Interactive:
                if (!base.reader.Read())
                {
                    return(false);
                }
                break;

            default:
                Debug.Assert(false);
                return(false);
            }

            XmlNodeType nodeType = base.reader.NodeType;

            if (!_checkCharacters)
            {
                switch (nodeType)
                {
                case XmlNodeType.Comment:
                    if (_ignoreComments)
                    {
                        return(Read());
                    }
                    break;

                case XmlNodeType.Whitespace:
                    if (_ignoreWhitespace)
                    {
                        return(Read());
                    }
                    break;

                case XmlNodeType.ProcessingInstruction:
                    if (_ignorePis)
                    {
                        return(Read());
                    }
                    break;

                case XmlNodeType.DocumentType:
                    if (_dtdProcessing == DtdProcessing.Prohibit)
                    {
                        Throw(SR.Xml_DtdIsProhibitedEx, string.Empty);
                    }
                    else if (_dtdProcessing == DtdProcessing.Ignore)
                    {
                        return(Read());
                    }
                    break;
                }
                return(true);
            }
            else
            {
                switch (nodeType)
                {
                case XmlNodeType.Element:
                    if (_checkCharacters)
                    {
                        // check element name
                        ValidateQName(base.reader.Prefix, base.reader.LocalName);

                        // check values of attributes
                        if (base.reader.MoveToFirstAttribute())
                        {
                            do
                            {
                                ValidateQName(base.reader.Prefix, base.reader.LocalName);
                                CheckCharacters(base.reader.Value);
                            } while (base.reader.MoveToNextAttribute());

                            base.reader.MoveToElement();
                        }
                    }
                    break;

                case XmlNodeType.Text:
                case XmlNodeType.CDATA:
                    if (_checkCharacters)
                    {
                        CheckCharacters(base.reader.Value);
                    }
                    break;

                case XmlNodeType.EntityReference:
                    if (_checkCharacters)
                    {
                        // check name
                        ValidateQName(base.reader.Name);
                    }
                    break;

                case XmlNodeType.ProcessingInstruction:
                    if (_ignorePis)
                    {
                        return(Read());
                    }
                    if (_checkCharacters)
                    {
                        ValidateQName(base.reader.Name);
                        CheckCharacters(base.reader.Value);
                    }
                    break;

                case XmlNodeType.Comment:
                    if (_ignoreComments)
                    {
                        return(Read());
                    }
                    if (_checkCharacters)
                    {
                        CheckCharacters(base.reader.Value);
                    }
                    break;

                case XmlNodeType.DocumentType:
                    if (_dtdProcessing == DtdProcessing.Prohibit)
                    {
                        Throw(SR.Xml_DtdIsProhibitedEx, string.Empty);
                    }
                    else if (_dtdProcessing == DtdProcessing.Ignore)
                    {
                        return(Read());
                    }
                    if (_checkCharacters)
                    {
                        ValidateQName(base.reader.Name);
                        CheckCharacters(base.reader.Value);

                        string str;
                        str = base.reader.GetAttribute("SYSTEM");
                        if (str != null)
                        {
                            CheckCharacters(str);
                        }

                        str = base.reader.GetAttribute("PUBLIC");
                        if (str != null)
                        {
                            int i;
                            if ((i = _xmlCharType.IsPublicId(str)) >= 0)
                            {
                                Throw(SR.Xml_InvalidCharacter, XmlException.BuildCharExceptionArgs(str, i));
                            }
                        }
                    }
                    break;

                case XmlNodeType.Whitespace:
                    if (_ignoreWhitespace)
                    {
                        return(Read());
                    }
                    if (_checkCharacters)
                    {
                        CheckWhitespace(base.reader.Value);
                    }
                    break;

                case XmlNodeType.SignificantWhitespace:
                    if (_checkCharacters)
                    {
                        CheckWhitespace(base.reader.Value);
                    }
                    break;

                case XmlNodeType.EndElement:
                    if (_checkCharacters)
                    {
                        ValidateQName(base.reader.Prefix, base.reader.LocalName);
                    }
                    break;

                default:
                    break;
                }
                _lastNodeType = nodeType;
                return(true);
            }
        }
示例#17
0
        public override bool Read()
        {
            XmlNodeType type;

            switch (this.state)
            {
            case State.Initial:
                this.state = State.Interactive;
                if (base.reader.ReadState != System.Xml.ReadState.Initial)
                {
                    goto Label_0055;
                }
                break;

            case State.InReadBinary:
                this.FinishReadBinary();
                this.state = State.Interactive;
                break;

            case State.Error:
                return(false);

            case State.Interactive:
                break;

            default:
                return(false);
            }
            if (!base.reader.Read())
            {
                return(false);
            }
Label_0055:
            type = base.reader.NodeType;
            if (this.checkCharacters)
            {
                switch (type)
                {
                case XmlNodeType.Element:
                    if (this.checkCharacters)
                    {
                        this.ValidateQName(base.reader.Prefix, base.reader.LocalName);
                        if (base.reader.MoveToFirstAttribute())
                        {
                            do
                            {
                                this.ValidateQName(base.reader.Prefix, base.reader.LocalName);
                                this.CheckCharacters(base.reader.Value);
                            }while (base.reader.MoveToNextAttribute());
                            base.reader.MoveToElement();
                        }
                    }
                    break;

                case XmlNodeType.Text:
                case XmlNodeType.CDATA:
                    if (this.checkCharacters)
                    {
                        this.CheckCharacters(base.reader.Value);
                    }
                    break;

                case XmlNodeType.EntityReference:
                    if (this.checkCharacters)
                    {
                        this.ValidateQName(base.reader.Name);
                    }
                    break;

                case XmlNodeType.ProcessingInstruction:
                    if (!this.ignorePis)
                    {
                        if (this.checkCharacters)
                        {
                            this.ValidateQName(base.reader.Name);
                            this.CheckCharacters(base.reader.Value);
                        }
                        break;
                    }
                    return(this.Read());

                case XmlNodeType.Comment:
                    if (!this.ignoreComments)
                    {
                        if (this.checkCharacters)
                        {
                            this.CheckCharacters(base.reader.Value);
                        }
                        break;
                    }
                    return(this.Read());

                case XmlNodeType.DocumentType:
                    if (this.dtdProcessing != DtdProcessing.Prohibit)
                    {
                        if (this.dtdProcessing == DtdProcessing.Ignore)
                        {
                            return(this.Read());
                        }
                    }
                    else
                    {
                        this.Throw("Xml_DtdIsProhibitedEx", string.Empty);
                    }
                    if (this.checkCharacters)
                    {
                        int num;
                        this.ValidateQName(base.reader.Name);
                        this.CheckCharacters(base.reader.Value);
                        string attribute = base.reader.GetAttribute("SYSTEM");
                        if (attribute != null)
                        {
                            this.CheckCharacters(attribute);
                        }
                        attribute = base.reader.GetAttribute("PUBLIC");
                        if ((attribute != null) && ((num = this.xmlCharType.IsPublicId(attribute)) >= 0))
                        {
                            this.Throw("Xml_InvalidCharacter", XmlException.BuildCharExceptionArgs(attribute, num));
                        }
                    }
                    break;

                case XmlNodeType.Whitespace:
                    if (!this.ignoreWhitespace)
                    {
                        if (this.checkCharacters)
                        {
                            this.CheckWhitespace(base.reader.Value);
                        }
                        break;
                    }
                    return(this.Read());

                case XmlNodeType.SignificantWhitespace:
                    if (this.checkCharacters)
                    {
                        this.CheckWhitespace(base.reader.Value);
                    }
                    break;

                case XmlNodeType.EndElement:
                    if (this.checkCharacters)
                    {
                        this.ValidateQName(base.reader.Prefix, base.reader.LocalName);
                    }
                    break;
                }
            }
            else
            {
                switch (type)
                {
                case XmlNodeType.ProcessingInstruction:
                    if (!this.ignorePis)
                    {
                        break;
                    }
                    return(this.Read());

                case XmlNodeType.Comment:
                    if (!this.ignoreComments)
                    {
                        break;
                    }
                    return(this.Read());

                case XmlNodeType.DocumentType:
                    if (this.dtdProcessing != DtdProcessing.Prohibit)
                    {
                        if (this.dtdProcessing == DtdProcessing.Ignore)
                        {
                            return(this.Read());
                        }
                        break;
                    }
                    this.Throw("Xml_DtdIsProhibitedEx", string.Empty);
                    break;

                case XmlNodeType.Whitespace:
                    if (!this.ignoreWhitespace)
                    {
                        break;
                    }
                    return(this.Read());
                }
                return(true);
            }
            this.lastNodeType = type;
            return(true);
        }
        private void ValidateNCName(string ncname)
        {
            if (ncname.Length == 0)
            {
                throw new ArgumentException(SR.Xml_EmptyName);
            }
            int len = ValidateNames.ParseNCName(ncname, 0);

            if (len != ncname.Length)
            {
                throw new ArgumentException(string.Format(len == 0 ? SR.Xml_BadStartNameChar : SR.Xml_BadNameChar, XmlException.BuildCharExceptionArgs(ncname, len)));
            }
        }
示例#19
0
        public override async Task WriteDocTypeAsync(string name, string pubid, string sysid, string subset)
        {
            try
            {
                if (name == null || name.Length == 0)
                {
                    throw new ArgumentException(SR.Xml_EmptyName);
                }
                XmlConvert.VerifyQName(name, ExceptionType.XmlException);

                if (_conformanceLevel == ConformanceLevel.Fragment)
                {
                    throw new InvalidOperationException(SR.Xml_DtdNotAllowedInFragment);
                }

                await AdvanceStateAsync(Token.Dtd).ConfigureAwait(false);

                if (_dtdWritten)
                {
                    _currentState = State.Error;
                    throw new InvalidOperationException(SR.Xml_DtdAlreadyWritten);
                }

                if (_conformanceLevel == ConformanceLevel.Auto)
                {
                    _conformanceLevel = ConformanceLevel.Document;
                    _stateTable       = s_stateTableDocument;
                }

                int i;

                // check characters
                if (_checkCharacters)
                {
                    if (pubid != null)
                    {
                        if ((i = _xmlCharType.IsPublicId(pubid)) >= 0)
                        {
                            throw new ArgumentException(SR.Format(SR.Xml_InvalidCharacter, XmlException.BuildCharExceptionArgs(pubid, i)), "pubid");
                        }
                    }
                    if (sysid != null)
                    {
                        if ((i = _xmlCharType.IsOnlyCharData(sysid)) >= 0)
                        {
                            throw new ArgumentException(SR.Format(SR.Xml_InvalidCharacter, XmlException.BuildCharExceptionArgs(sysid, i)), "sysid");
                        }
                    }
                    if (subset != null)
                    {
                        if ((i = _xmlCharType.IsOnlyCharData(subset)) >= 0)
                        {
                            throw new ArgumentException(SR.Format(SR.Xml_InvalidCharacter, XmlException.BuildCharExceptionArgs(subset, i)), "subset");
                        }
                    }
                }

                // write doctype
                await _writer.WriteDocTypeAsync(name, pubid, sysid, subset).ConfigureAwait(false);

                _dtdWritten = true;
            }
            catch
            {
                _currentState = State.Error;
                throw;
            }
        }
示例#20
0
 public override void WriteWhitespace(string ws)
 {
     if (ws == null)
     {
         ws = string.Empty;
     }
     // "checkNames" is intentional here; if false, the whitespaces are checked in XmlWellformedWriter
     if (checkNames)
     {
         int i;
         if ((i = xmlCharType.IsOnlyWhitespaceWithPos(ws)) != -1)
         {
             throw new ArgumentException(Res.GetString(Res.Xml_InvalidWhitespaceCharacter, XmlException.BuildCharExceptionArgs(ws, i)));
         }
     }
     if (replaceNewLines)
     {
         ws = ReplaceNewLines(ws);
     }
     writer.WriteWhitespace(ws);
 }
示例#21
0
 internal static Exception CreateInvalidCharException(string data, int invCharPos, ExceptionType exceptionType)
 {
     return(CreateException(SR.Xml_InvalidCharacter, XmlException.BuildCharExceptionArgs(data, invCharPos), exceptionType, 0, invCharPos + 1));
 }
        private void ValidateNCName(string ncname)
        {
            if (ncname.Length == 0)
            {
                throw new ArgumentException(Res.GetString("Xml_EmptyName"));
            }
            int invCharIndex = ValidateNames.ParseNCName(ncname, 0);

            if (invCharIndex != ncname.Length)
            {
                throw new ArgumentException(Res.GetString((invCharIndex == 0) ? "Xml_BadStartNameChar" : "Xml_BadNameChar", XmlException.BuildCharExceptionArgs(ncname, invCharIndex)));
            }
        }
示例#23
0
 internal static Exception CreateInvalidNameCharException(string name, int index, ExceptionType exceptionType)
 {
     return(CreateException(index == 0 ? SR.Xml_BadStartNameChar : SR.Xml_BadNameChar, XmlException.BuildCharExceptionArgs(name, index), exceptionType, 0, index + 1));
 }
示例#24
0
 internal static Exception CreateInvalidCharException(char invChar, char nextChar, ExceptionType exceptionType)
 {
     return(CreateException(SR.Xml_InvalidCharacter, XmlException.BuildCharExceptionArgs(invChar, nextChar), exceptionType));
 }