Inheritance: ScriptFunction
 internal RegExpObject(RegExpPrototype parent, string source, bool ignoreCase, bool global, bool multiline, RegExpConstructor regExpConst) : base(parent)
 {
     this.regExpConst = regExpConst;
     this.sourceInt = source;
     this.ignoreCaseInt = ignoreCase;
     this.globalInt = global;
     this.multilineInt = multiline;
     RegexOptions options = RegexOptions.CultureInvariant | RegexOptions.ECMAScript;
     if (ignoreCase)
     {
         options |= RegexOptions.IgnoreCase;
     }
     if (multiline)
     {
         options |= RegexOptions.Multiline;
     }
     try
     {
         this.regex = new Regex(source, options);
     }
     catch (ArgumentException)
     {
         throw new JScriptException(JSError.RegExpSyntax);
     }
     this.lastIndexInt = 0;
     base.noExpando = false;
 }
Exemplo n.º 2
0
 //Only to be used by StringPrototype
 internal RegExpObject(Regex regex)
   : base(null){
   this.regExpConst = null;
   this.sourceInt = "";
   this.ignoreCaseInt = (regex.Options & RegexOptions.IgnoreCase) != 0;
   this.globalInt = false;
   this.multilineInt = (regex.Options & RegexOptions.Multiline) != 0;
   this.regex = regex;
   this.lastIndexInt = 0;
   this.noExpando = true;
 }
Exemplo n.º 3
0
 internal GlobalObject(){
   this.originalActiveXObjectField = null;
   this.originalArrayField = null;
   this.originalBooleanField = null;
   this.originalDateField = null;
   this.originalEnumeratorField = null;
   this.originalEvalErrorField = null;
   this.originalErrorField = null;
   this.originalFunctionField = null;
   this.originalNumberField = null;
   this.originalObjectField = null;
   this.originalObjectPrototypeField = null;
   this.originalRangeErrorField = null;
   this.originalReferenceErrorField = null;
   this.originalRegExpField = null;
   this.originalStringField = null;
   this.originalSyntaxErrorField = null;
   this.originalTypeErrorField = null;
   this.originalVBArrayField = null;
   this.originalURIErrorField = null;
 }
Exemplo n.º 4
0
      internal RegExpObject(RegExpPrototype parent, String source,
          bool ignoreCase, bool global, bool multiline, RegExpConstructor regExpConst)
        : base(parent){
        this.regExpConst = regExpConst;
        this.sourceInt = source;
        this.ignoreCaseInt = ignoreCase;
        this.globalInt = global;
        this.multilineInt = multiline;

        RegexOptions flags = /* RegexOptions.Compiled | */ RegexOptions.ECMAScript;
        if (ignoreCase)
          flags |= RegexOptions.IgnoreCase;
        if (multiline)
          flags |= RegexOptions.Multiline;
        try{
          this.regex = new Regex(source, flags);
        }catch (System.ArgumentException){
          throw new JScriptException(JSError.RegExpSyntax);
        }
        this.lastIndexInt = 0;
        this.noExpando = false;
      }
Exemplo n.º 5
0
 internal GlobalObject()
 {
     this.originalActiveXObjectField   = null;
     this.originalArrayField           = null;
     this.originalBooleanField         = null;
     this.originalDateField            = null;
     this.originalEnumeratorField      = null;
     this.originalEvalErrorField       = null;
     this.originalErrorField           = null;
     this.originalFunctionField        = null;
     this.originalNumberField          = null;
     this.originalObjectField          = null;
     this.originalObjectPrototypeField = null;
     this.originalRangeErrorField      = null;
     this.originalReferenceErrorField  = null;
     this.originalRegExpField          = null;
     this.originalStringField          = null;
     this.originalSyntaxErrorField     = null;
     this.originalTypeErrorField       = null;
     this.originalVBArrayField         = null;
     this.originalURIErrorField        = null;
 }
        internal RegExpObject(RegExpPrototype parent, string source, bool ignoreCase, bool global, bool multiline, RegExpConstructor regExpConst) : base(parent)
        {
            this.regExpConst   = regExpConst;
            this.sourceInt     = source;
            this.ignoreCaseInt = ignoreCase;
            this.globalInt     = global;
            this.multilineInt  = multiline;
            RegexOptions options = RegexOptions.CultureInvariant | RegexOptions.ECMAScript;

            if (ignoreCase)
            {
                options |= RegexOptions.IgnoreCase;
            }
            if (multiline)
            {
                options |= RegexOptions.Multiline;
            }
            try
            {
                this.regex = new Regex(source, options);
            }
            catch (ArgumentException)
            {
                throw new JScriptException(JSError.RegExpSyntax);
            }
            this.lastIndexInt = 0;
            base.noExpando    = false;
        }
Exemplo n.º 7
0
        public static ArrayObject split(object thisObj, VsaEngine engine,
                                        object separator, object limit)
        {
            string      string_obj = Convert.ToString(thisObj);
            int         length     = string_obj.Length;
            int         max_count  = (limit != null) ? Convert.ToInt32(limit) : -1;
            ArrayObject result     = new ArrayObject();

            if (separator == null)
            {
                result.length          = (uint)1;
                result.elems [(uint)0] = string_obj;
                return(result);
            }

            int  start_pos = 0;
            int  end_pos   = -1;
            int  match_len = 0;
            uint count     = 0;
            int  sep_len   = 0;

            if (!(separator is RegExpObject))
            {
                string sep_str = Convert.ToString(separator);
                sep_len = sep_str.Length;

                if (string_obj.Length == 0)
                {
                    if (sep_len > 0)
                    {
                        result.length          = (uint)1;
                        result.elems [(uint)0] = string_obj;
                    }

                    return(result);
                }

                while (end_pos != length && (max_count == -1 || count < max_count))
                {
                    end_pos = (length != 0) ? string_obj.IndexOf(sep_str, start_pos) : length;
                    if (end_pos == -1)
                    {
                        end_pos = length;
                    }
                    else if (sep_len == 0)
                    {
                        end_pos++;
                    }

                    match_len            = end_pos - start_pos;
                    result.elems [count] = string_obj.Substring(start_pos, match_len);

                    start_pos += match_len + sep_len;
                    count++;
                }

                result.length = count;
                return(result);
            }

            RegExpObject    sep_re = (RegExpObject)separator;
            MatchCollection md     = sep_re.regex.Matches(string_obj);
            uint            n      = (uint)md.Count;

            Match match = null;

            for (int i = 0; i < n; i++)
            {
                if (max_count != -1 && count >= max_count)
                {
                    break;
                }

                match     = md [i];
                sep_len   = match.Length;
                end_pos   = match.Index;
                match_len = end_pos - start_pos;

                //
                // The specification says that "ab".split(/a*/) is ["", "b"], but would
                // that would also mean that "abcdef".split(/./).length would not be 6.
                // I'm currently going with the Rhino behavior that seems to make more
                // sense.
                //
                if (!(end_pos == 0 && sep_len == 0))
                {
                    result.elems [count] = string_obj.Substring(start_pos, match_len);
                    count++;
                }

                bool first_cap = true;
                foreach (Capture cap in match.Groups)
                {
                    if (max_count != -1 && count >= max_count)
                    {
                        break;
                    }

                    if (first_cap)
                    {
                        first_cap = false;
                        continue;
                    }

                    result.elems [count] = cap.Value;
                    count++;
                }

                start_pos += match_len + sep_len;
            }

            if (n > 0 && (max_count == -1 || count < max_count))
            {
                sep_re.lastIndex = match.Index + match.Length;
                RegExpConstructor.UpdateLastMatch(match, string_obj);

                if (start_pos < length)
                {
                    result.elems [count] = string_obj.Substring(start_pos);
                    count++;
                }
            }
            else if (n == 0)
            {
                result.elems [(uint)0] = string_obj;
                count++;
            }

            result.length = count;
            return(result);
        }