示例#1
0
            /// <exception cref="TjsException"></exception>
            protected internal override int Process(Variant result, Variant[] param, Dispatch2
                                                    objthis)
            {
                RegExpNI _this = (RegExpNI)objthis.GetNativeInstance(RegExpClass.mClassID
                                                                     );

                if (_this == null)
                {
                    return(Error.E_NATIVECLASSCRASH);
                }
                if (param.Length != 1)
                {
                    return(Error.E_BADPARAMCOUNT);
                }
                string expr = param[0].GetString();

                if (expr == null || expr[0] == 0)
                {
                    return(Error.E_FAIL);
                }
                if (expr[0] != '/' || expr[1] != '/')
                {
                    return(Error.E_FAIL);
                }
                int exprstart = expr.IndexOf('/', 2);

                if (exprstart < 0)
                {
                    return(Error.E_FAIL);
                }
                int flags = RegExpNI.GetRegExpFlagsFromString(Sharpen.Runtime.Substring(expr, 2));
                int pflag = (flags & ~RegExpClass.tjsflagsmask);

                try
                {
                    if (pflag != 0)
                    {
                        _this.RegEx = Sharpen.Pattern.Compile(Sharpen.Runtime.Substring(expr, exprstart +
                                                                                        1), pflag);
                    }
                    else
                    {
                        _this.RegEx = Sharpen.Pattern.Compile(Sharpen.Runtime.Substring(expr, exprstart +
                                                                                        1));
                    }
                }
                //catch (PatternSyntaxException e)
                //{
                //    throw new TJSException(e.Message);
                //}
                catch (ArgumentException e)
                {
                    throw new TjsException(e.Message);
                }
                _this.mFlags = flags;
                return(Error.S_OK);
            }
示例#2
0
        /// <exception cref="VariantException"></exception>
        /// <exception cref="TjsException"></exception>
        private static void Compile(Variant[] param, RegExpNI _this)
        {
            string expr = param[0].AsString();
            int    flags;

            if (param.Length >= 2)
            {
                string fs = param[1].AsString();
                flags = RegExpNI.GetRegExpFlagsFromString(fs);
            }
            else
            {
                flags = RegExpNI.RegExpFlagToValue((char)0, 0);
            }
            if (expr.Length == 0)
            {
                expr = "(?:)";
            }
            // generate empty regular expression
            try
            {
                int pflag = (flags & ~tjsflagsmask);
                if (pflag != 0)
                {
                    _this.RegEx = Sharpen.Pattern.Compile(expr, pflag);
                }
                else
                {
                    _this.RegEx = Sharpen.Pattern.Compile(expr);
                }
            }
            //catch (PatternSyntaxException e)
            //{
            //    _this.RegEx = null;
            //    throw new TJSException(e.Message);
            //}
            catch (ArgumentException e)
            {
                _this.RegEx = null;
                throw new TjsException(e.Message);
            }
            _this.mFlags = flags;
        }