System.Xml.ValidateNames.ParseNmtoken C# (CSharp) Méthode

ParseNmtoken() static private méthode

Attempts to parse the input string as an Nmtoken (see the XML spec production [7] && XML Namespaces spec). Quits parsing when an invalid Nmtoken char is reached or the end of string is reached. Returns the number of valid Nmtoken chars that were parsed.
static private ParseNmtoken ( string s, int offset ) : int
s string
offset int
Résultat int
        internal static unsafe int ParseNmtoken(string s, int offset)
        {
            Debug.Assert(s != null && offset <= s.Length);

            // Keep parsing until the end of string or an invalid NCName character is reached
            int i = offset;
            while (i < s.Length)
            {
                if (s_xmlCharType.IsNCNameSingleChar(s[i]))
                {
                    i++;
                }
#if XML10_FIFTH_EDITION
                else if (xmlCharType.IsNCNameSurrogateChar(s, i)) {
                    i += 2;
                }
#endif
                else
                {
                    break;
                }
            }

            return i - offset;
        }

Usage Example

        // NOTE: This does not correctly check start name char, but we cannot change it since it would be a breaking change.
        internal static void CheckName(String name)
        {
            int endPos = ValidateNames.ParseNmtoken(name, 0);

            if (endPos < name.Length)
            {
                throw new XmlException(SR.Format(SR.Xml_BadNameChar, XmlExceptionHelper.BuildCharExceptionArgs(name, endPos)));
            }
        }