Monobjc.Tools.Generator.Parsers.Sgml.AttDef.SetPresence C# (CSharp) Method

SetPresence() public method

Sets the attribute presence declaration.
public SetPresence ( string token ) : bool
token string The string representation of the attribute presence, corresponding to one of the values in the enumeration.
return bool
        public bool SetPresence(string token)
        {
            bool hasDefault = true;
            if (string.Equals(token, "FIXED", StringComparison.OrdinalIgnoreCase))
            {
                this.m_presence = AttributePresence.Fixed;
            }
            else if (string.Equals(token, "REQUIRED", StringComparison.OrdinalIgnoreCase))
            {
                this.m_presence = AttributePresence.Required;
                hasDefault = false;
            }
            else if (string.Equals(token, "IMPLIED", StringComparison.OrdinalIgnoreCase))
            {
                this.m_presence = AttributePresence.Implied;
                hasDefault = false;
            }
            else
            {
                throw new SgmlParseException(string.Format(CultureInfo.CurrentUICulture, "Attribute value '{0}' not supported", token));
            }

            return hasDefault;
        }

Usage Example

Esempio n. 1
0
        private void ParseAttDefault(char ch, AttDef attdef)
        {
            if (ch == '%')
            {
                Entity e = this.ParseParameterEntity(WhiteSpace);
                this.PushEntity(this.m_current.ResolvedUri, e);
                this.ParseAttDefault(this.m_current.Lastchar, attdef);
                this.PopEntity(); // bugbug - are we at the end of the entity?
                ch = this.m_current.Lastchar;
                return;
            }

            bool hasdef = true;
            if (ch == '#')
            {
                this.m_current.ReadChar();
                string token = this.m_current.ScanToken(this.m_sb, WhiteSpace, true);
                hasdef = attdef.SetPresence(token);
                ch = this.m_current.SkipWhitespace();
            }
            if (hasdef)
            {
                if (ch == '\'' || ch == '"')
                {
                    string lit = this.m_current.ScanLiteral(this.m_sb, ch);
                    attdef.Default = lit;
                    ch = this.m_current.SkipWhitespace();
                }
                else
                {
                    string name = this.m_current.ScanToken(this.m_sb, WhiteSpace, false);
                    name = name.ToUpperInvariant();
                    attdef.Default = name; // bugbug - must be one of the enumerated names.
                    ch = this.m_current.SkipWhitespace();
                }
            }
        }