Esempio n. 1
0
        //------------------------------------------------------------
        // CNameManager.IsValidIdentifier (1)
        //
        /// <summary>
        /// <para>Checks for a valid identifier.
        /// The definition of a valid identifier can change depending on what flags are passed.</para>
        /// <para>Specifically,
        /// <list type="bullet">
        /// <item>If AllowAtIdentifiers is set in flags, '@' in the beginning is valid.</item>
        /// <item>Determine if an invalid character is in.</item>
        /// <item>Determine if the name is of a keyword.</item>
        /// </list>
        /// </para>
        /// </summary>
        /// <param name="name"></param>
        /// <param name="langVer">Specifiy whether according to ECMA standard or not.</param>
        /// <param name="flags"></param>
        /// <returns></returns>
        //------------------------------------------------------------
        internal bool IsValidIdentifier(
            string name,
            LangVersionEnum langVer,
            CheckIdentifierFlagsEnum flags)
        {
            if (name == null || name.Length == 0)
            {
                return(false);
            }
            int idx = 0;

            bool atKeyword = false;

            if (name[idx] == '@')
            {
                if ((flags & CheckIdentifierFlagsEnum.AllowAtIdentifiers) == 0)
                {
                    return(false);
                }
                atKeyword = true;
                if (name.Length <= 1)
                {
                    return(false);
                }
                ++idx;
            }

            for (; idx < name.Length; ++idx)
            {
                if (!CharUtil.IsIdentifierCharOrDigit(name[idx]))
                {
                    return(false);
                }
            }

            if ((flags & CheckIdentifierFlagsEnum.CheckKeywords) == 0 || atKeyword)
            {
                return(true);
            }

            int dummy;

            return(!IsKeyword(name, langVer, out dummy));
        }