Esempio n. 1
0
        private string To_XML_Safe_Name(string Name)
        {
            int idx = Name.IndexOf('-');

            if (idx >= 0 && Name.Length < 2)
            {
                throw new DomSyntaxError();
            }
            if (idx >= 0 && (Name[idx + 1] >= 'a' || Name[idx + 1] <= 'z'))
            {
                throw new DomSyntaxError();
            }

            bool hasAlpha = false;

            for (int i = 0; i < Name.Length; i++)
            {
                if (UnicodeCommon.Is_ASCII_Upper_Alpha(Name[i]))
                {
                    hasAlpha = true; break;
                }
            }

            /* 2) For each ASCII upper alpha in name, insert a U+002D HYPHEN-MINUS character (-) before the character and replace the character with the same character converted to ASCII lowercase. */
            StringBuilder sb = new StringBuilder();

            if (hasAlpha)
            {
                for (int i = 0; i < Name.Length; i++)
                {
                    if (UnicodeCommon.Is_ASCII_Upper_Alpha(Name[i]))
                    {
                        sb.Append('-');
                        sb.Append(UnicodeCommon.To_ASCII_Lower_Alpha(Name[i]));
                    }
                    else
                    {
                        sb.Append(Name[i]);
                    }
                }
            }
            else
            {
                sb.Append(Name);
            }
            /* 3) Insert the string data- at the front of name. */
            sb.Insert(0, "data-");

            string safeName = sb.ToString();

            /* 4) If name does not match the XML Name production, throw an "InvalidCharacterError" DOMException. */
            if (!XMLCommon.Is_Valid_Name(safeName))
            {
                throw new InvalidCharacterError($"The Name '{safeName}' is not a valid XML name production.");
            }

            return(safeName);
        }
Esempio n. 2
0
        /// <summary>
        /// Deletes a named value from the list.
        /// </summary>
        /// <param name="Name"></param>
        public void delete(string Name)
        {
            bool hasAlpha = false;

            for (int i = 0; i < Name.Length; i++)
            {
                if (UnicodeCommon.Is_ASCII_Upper_Alpha(Name[i]))
                {
                    hasAlpha = true; break;
                }
            }

            /* 1) For each ASCII upper alpha in name, insert a U+002D HYPHEN-MINUS character (-) before the character and replace the character with the same character converted to ASCII lowercase. */
            StringBuilder sb = new StringBuilder();

            if (hasAlpha)
            {
                for (int i = 0; i < Name.Length; i++)
                {
                    if (UnicodeCommon.Is_ASCII_Upper_Alpha(Name[i]))
                    {
                        sb.Append(UnicodeCommon.CHAR_HYPHEN_MINUS);
                        sb.Append(UnicodeCommon.To_ASCII_Lower_Alpha(Name[i]));
                    }
                    else
                    {
                        sb.Append(Name[i]);
                    }
                }
            }
            else
            {
                sb.Append(Name);
            }
            /* 2) Insert the string data- at the front of name. */
            sb.Insert(0, "data-");
            Name = sb.ToString();
            /* 3) Remove an attribute by name given name and the DOMStringMap's associated element. */
            if (Owner.find_attribute(Name, out Attr attr))
            {
                Owner.remove_attribute(attr);
            }
        }