Пример #1
0
        /// <summary>
        /// Creates a new <see cref="ASQName"/> object from a namespace and a local name.
        /// </summary>
        /// <param name="ns">The namespace of the XML name. If this is null, the QName will match
        /// XML elements and attributes in any namespace.</param>
        /// <param name="localName">The local name of the XML name. If this is the string "*",
        /// the QName will match XML elements and attributes with any local name.</param>
        public ASQName(ASNamespace?ns, string localName)
        {
            if (ns != null)
            {
                (uri, prefix) = (ns.uri, ns.prefix);
            }

            this.localName = ASString.AS_convertString(localName);
        }
Пример #2
0
        /// <summary>
        /// Creates a new <see cref="ASQName"/> object from a local name. The default namespace will
        /// be used.
        /// </summary>
        /// <param name="localName">The local name of the XML name. This is the name of the XML
        /// element or attribute without the namespace. If this is the string "*", the QName will
        /// match XML elements and attributes with any name in any namespace. Otherwise, its namespace
        /// will be set to the default XML namespace.</param>
        public ASQName(string?localName)
        {
            if (localName != null && localName.Length == 1 && localName[0] == '*')
            {
                (uri, prefix) = (null, null);
            }
            else
            {
                ASNamespace defaultNS = ASNamespace.getDefault();
                (uri, prefix) = (defaultNS.uri, defaultNS.prefix);
            }

            this.localName = ASString.AS_convertString(localName);
        }
Пример #3
0
        /// <summary>
        /// Initializes the RegExp object using the given pattern and flags.
        /// </summary>
        /// <param name="pattern">The regular expression pattern string.</param>
        /// <param name="flags">The flags string of the regular expression.</param>
        private void _init(string?pattern, string?flags)
        {
            pattern = ASString.AS_convertString(pattern);
            flags   = ASString.AS_convertString(flags);

            m_source = pattern;
            RegexOptions regexOptions = RegexOptions.CultureInvariant | RegexOptions.ECMAScript;

            for (int i = 0; i < flags.Length; i++)
            {
                switch (flags[i])
                {
                case 'i':
                    regexOptions |= RegexOptions.IgnoreCase;
                    break;

                case 'x':
                    m_auxFlags |= AUX_FLAG_EXTENDED;
                    break;

                case 'm':
                    m_auxFlags |= AUX_FLAG_MULTILINE;
                    break;

                case 's':
                    m_auxFlags |= AUX_FLAG_DOTALL;
                    break;

                case 'g':
                    m_auxFlags |= AUX_FLAG_GLOBAL;
                    break;
                }
            }

            var transpiler = new RegexTranspiler();

            transpiler.transpile(
                pattern,
                (m_auxFlags & AUX_FLAG_MULTILINE) != 0,
                (m_auxFlags & AUX_FLAG_DOTALL) != 0,
                (m_auxFlags & AUX_FLAG_EXTENDED) != 0
                );

            m_internalRegex = new Regex(transpiler.transpiledPattern, regexOptions);

            m_groupNames = transpiler.getGroupNames();
            m_groupCount = transpiler.groupCount;
        }
Пример #4
0
        /// <summary>
        /// Creates an <see cref="XMLGenName"/> instance from a <see cref="QName"/>.
        /// </summary>
        /// <returns>The created <see cref="XMLGenName"/> instance.</returns>
        /// <param name="qname">A <see cref="QName"/> instance.</param>
        /// <param name="bindOptions">The binding options used in the lookup for which a generalized
        /// name must be created. The following flags are used here:
        /// <see cref="BindOptions.ATTRIBUTE"/> and <see cref="BindOptions.RUNTIME_NAME"/>.</param>
        public static XMLGenName fromQName(QName qname, BindOptions bindOptions)
        {
            bool   isAttr = (bindOptions & BindOptions.ATTRIBUTE) != 0;
            string?uri    = qname.ns.uri;
            string?localName;

            if ((bindOptions & BindOptions.RUNTIME_NAME) != 0)
            {
                localName = ASString.AS_convertString(qname.localName);
            }
            else
            {
                localName = qname.localName;
            }

            if (localName == null || localName.Length == 0)
            {
                return(new XMLGenName(uri: uri, localName: localName, isAttr: isAttr));
            }

            char firstChar = localName[0];

            if (qname.ns.isPublic && (uint)(firstChar - '0') <= 9)
            {
                NumberFormatHelper.parseArrayIndex(localName, allowLeadingZeroes: false, out uint arrindex);
                if ((int)arrindex >= 0)
                {
                    return(new XMLGenName(index: (int)arrindex, isIndex: true, isAttr: isAttr));
                }
            }

            if (firstChar == '@' && (bindOptions & BindOptions.ATTRIBUTE) == 0)
            {
                isAttr    = true;
                localName = localName.Substring(1);
            }

            if (localName.Length == 1 && localName[0] == '*')
            {
                localName = null;
            }

            return(new XMLGenName(uri: uri, localName: localName, isAttr: isAttr));
        }
Пример #5
0
        /// <summary>
        /// Creates a new <see cref="ASNamespace"/> with a URI and a prefix.
        /// </summary>
        ///
        /// <param name="prefix">The prefix of the namespace. If this is not a valid XML name, the
        /// namespace is considered to be prefixless and cannot be used with methods requiring prefixed
        /// namespaces.</param>
        /// <param name="uri">
        /// The URI of the namespace. If this is the empty string, the prefix must be
        /// the empty string, otherwise an error is thrown.
        /// </param>
        ///
        /// <exception cref="AVM2Exception">
        /// <list type="bullet">
        /// <item>
        /// <description>TypeError #1098: If <paramref name="uri"/> is the empty string, but
        /// <paramref name="prefix"/> is not the empty string.</description>
        /// </item>
        /// </list>
        /// </exception>
        public ASNamespace(string prefix, string uri)
        {
            prefix = ASString.AS_convertString(prefix);
            uri    = ASString.AS_convertString(uri);

            if (uri.Length == 0)
            {
                if (prefix.Length != 0)
                {
                    throw ErrorHelper.createError(ErrorCode.XML_ILLEGAL_PREFIX_PUBLIC_NAMESPACE, prefix);
                }
                (this.prefix, this.uri) = ("", "");
            }
            else
            {
                this.prefix = (prefix.Length == 0 || XMLHelper.isValidName(prefix)) ? prefix : null;
                this.uri    = uri;
            }
        }
Пример #6
0
        /// <summary>
        /// Creates a new <see cref="ASQName"/> object with a prefixed namespace specified by a URI
        /// and prefix, and a local name.
        /// </summary>
        ///
        /// <param name="prefix">The prefix of the namespace of the XML name.</param>
        /// <param name="uri">The URI of the namespace of the XML name. If this is null, the QName will
        /// match XML elements and attributes in any namespace and <paramref name="prefix"/> is ignored.</param>
        /// <param name="localName">The local name of the XML name. This is the name of the XML
        /// element or attribute without the namespace. If this is the string "*", the QName
        /// will match XML elements and attributes with any local name.</param>
        ///
        /// <exception cref="AVM2Exception">
        /// <list type="bullet">
        /// <item>
        /// <description>TypeError #1098: If <paramref name="uri"/> is the empty string, but
        /// <paramref name="prefix"/> is not the empty string.</description>
        /// </item>
        /// </list>
        /// </exception>
        ///
        /// <remarks>
        /// If <paramref name="prefix"/> is null, the QName will not have a prefix. This differs from
        /// the behaviour of the <see cref="ASNamespace(String,String)"/> constructor, which converts
        /// a null prefix to the string "null".
        /// </remarks>
        public ASQName(string?prefix, string?uri, string localName)
        {
            if (uri == null)
            {
                (this.uri, this.prefix) = (null, null);
            }
            else if (uri.Length == 0)
            {
                if (prefix != null && prefix.Length != 0)
                {
                    throw ErrorHelper.createError(ErrorCode.XML_ILLEGAL_PREFIX_PUBLIC_NAMESPACE, prefix);
                }
                (this.uri, this.prefix) = ("", "");
            }
            else
            {
                bool isValidPrefix = prefix == null || prefix.Length == 0 || XMLHelper.isValidName(prefix);
                (this.uri, this.prefix) = (uri, isValidPrefix ? prefix : null);
            }

            this.localName = ASString.AS_convertString(localName);
        }
Пример #7
0
 /// <summary>
 /// Creates a new <see cref="ASQName"/> object with a non-prefixed namespace specified by a
 /// URI and a local name.
 /// </summary>
 ///
 /// <param name="uri">The URI of the namespace of the XML name. If this is null, the QName
 /// will match XML elements and attributes in any namespace.</param>
 /// <param name="localName">The local name of the XML name. If this is the string "*",
 /// the QName will match XML elements and attributes with any local name.</param>
 public ASQName(string?uri, string localName)
 {
     this.prefix    = (uri != null && uri.Length == 0) ? "" : null;
     this.uri       = uri;
     this.localName = ASString.AS_convertString(localName);
 }
Пример #8
0
 /// <summary>
 /// Creates a new <see cref="ASNamespace"/> with a URI and no prefix.
 /// </summary>
 /// <param name="uri">The URI of the namespace.</param>
 /// <remarks>
 /// The prefix of the namespace will not be set (i.e. is set to null), except when the URI is
 /// the empty string, in which case the prefix will be set to the empty string.
 /// </remarks>
 public ASNamespace(string uri)
 {
     this.uri    = ASString.AS_convertString(uri);
     this.prefix = (this.uri.Length == 0) ? "" : null;
 }