Exemplo n.º 1
0
        public mdr.DObject ExecImplementation(string S)
        {
            if (S == null)
            {
                return(Runtime.Instance.DefaultDNull);
            }
            Match match = MatchImplementation(S);

            if (match == null)
            {
                return(Runtime.Instance.DefaultDNull);
            }

            int n = match.Captures.Count;

            mdr.DArray result = new mdr.DArray(n);
            result.SetField("index", match.Index);
            result.SetField("input", S);
            //result.SetField(0, match.Value);
            if (MatchedGroups != null)
            {
                for (int g = 0; g < MatchedGroups.Count; g++)
                {
                    if (MatchedGroups[g].Captures.Count > 0)
                    {
                        result.SetField(g, MatchedGroups[g].Captures[0].Value);
                    }
                }
            }
            return(result);
        }
Exemplo n.º 2
0
        // ECMA-262 section 15.5.4.10
        void match(ref mdr.CallFrame callFrame)
        {
            Debug.WriteLine("Calling JSString.match()");
            string S = callFrame.This.ToString();

            mdr.DRegExp rx = callFrame.Arg0.AsDObject() as mdr.DRegExp;
            if (rx == null)
            {
                rx = new mdr.DRegExp(callFrame.Arg0.AsString());
            }
            if (!rx.Global)
            {
                callFrame.Return.Set(rx.ExecImplementation(S));
                return;
            }

            mdr.DArray result = new mdr.DArray();
            int        i      = 0;

            foreach (Match match in (rx.Value).Matches(S))
            {
                foreach (Group group in match.Groups)
                {
                    //result.SetField(i++, new mdr.DString(group.Value.ToString()));
                    result.SetField(i++, group.Value);
                }
            }
            callFrame.Return.Set(result);
        }
Exemplo n.º 3
0
        // ECMA-262 section 15.5.4.14
        void split(ref mdr.CallFrame callFrame)
        {
            Debug.WriteLine("Calling JSString.split()");

            var S = Operations.Convert.ToString.Run(callFrame.This);

            mdr.DArray A = new mdr.DArray();

            var limit = (callFrame.PassedArgsCount > 1 && callFrame.Arg1.ValueType != mdr.ValueTypes.Undefined)
        ? Operations.Convert.ToUInt32.Run(ref callFrame.Arg1)
        : UInt32.MaxValue;

            if (limit == 0)
            {
                callFrame.Return.Set(A);
                return;
            }

            if (callFrame.PassedArgsCount == 0 || callFrame.Arg0.ValueType == mdr.ValueTypes.Undefined)
            {
                A.SetField(0, S);
                callFrame.Return.Set(A);
                return;
            }

            if (string.IsNullOrEmpty(S))
            {
                if (callFrame.PassedArgsCount != 0
                    //&& callFrame.Arg0.ValueType != mdr.ValueTypes.Undefined
                    && callFrame.Arg0.ValueType == mdr.ValueTypes.String &&
                    !String.IsNullOrEmpty(callFrame.Arg0.AsString()))
                {
                    //A.SetField(0, new mdr.DString(""));
                    A.SetField(0, "");
                }
                callFrame.Return.Set(A);
                return;
            }

            int s = S.Length;

            string[] result;
            if (callFrame.Arg0.ValueType == mdr.ValueTypes.String)
            {
                string separator = callFrame.Arg0.AsString();
                if (String.IsNullOrEmpty(separator))
                {
                    int i = 0;
                    result = new string[s];
                    foreach (char c in S)
                    {
                        result[i++] = new string(c, 1);
                    }
                }
                else
                {
                    result = S.Split(new string[] { separator }, StringSplitOptions.None);
                }
            }
            else
            {
                Debug.Assert(callFrame.Arg0.ValueType == mdr.ValueTypes.Object, "Does not know what to do with argument type {0} in split", callFrame.Arg0.ValueType);
                mdr.DRegExp regexpSeparator = callFrame.Arg0.AsDObject() as mdr.DRegExp;
                Debug.Assert(regexpSeparator != null, "Does not know what to do with argument type {0} in split", callFrame.Arg0.ValueType);
                //string pattern = regexpSeparator.Value.ToString();
                //result = Regex.Split(S, pattern, RegexOptions.ECMAScript);
                result = regexpSeparator.Value.Split(S);
            }

            for (int i = 0; i < result.Length && i < limit; i++)
            {
                //A.SetField(i, new mdr.DString(result[i]));
                A.SetField(i, result[i]);
            }

            callFrame.Return.Set(A);
        }
Exemplo n.º 4
0
    // ECMA-262 section 15.5.4.14
    void split(ref mdr.CallFrame callFrame)
    {
      Debug.WriteLine("Calling JSString.split()");

      var S = Operations.Convert.ToString.Run(callFrame.This);

      mdr.DArray A = new mdr.DArray();

      var limit = (callFrame.PassedArgsCount > 1 && callFrame.Arg1.ValueType != mdr.ValueTypes.Undefined)
        ? Operations.Convert.ToUInt32.Run(ref callFrame.Arg1)
        : UInt32.MaxValue;

      if (limit == 0)
      {
        callFrame.Return.Set(A);
        return;
      }

      if (callFrame.PassedArgsCount == 0 || callFrame.Arg0.ValueType == mdr.ValueTypes.Undefined)
      {
        A.SetField(0, S);
        callFrame.Return.Set(A);
        return;
      }

      if (string.IsNullOrEmpty(S))
      {
        if (callFrame.PassedArgsCount != 0
          //&& callFrame.Arg0.ValueType != mdr.ValueTypes.Undefined
          && callFrame.Arg0.ValueType == mdr.ValueTypes.String
          && !String.IsNullOrEmpty(callFrame.Arg0.AsString()))
        {
          //A.SetField(0, new mdr.DString(""));
          A.SetField(0, "");
        }
        callFrame.Return.Set(A);
        return;
      }

      int s = S.Length;

      string[] result;
      if (callFrame.Arg0.ValueType == mdr.ValueTypes.String)
      {
        string separator = callFrame.Arg0.AsString();
        if (String.IsNullOrEmpty(separator))
        {
          int i = 0;
          result = new string[s];
          foreach (char c in S)
            result[i++] = new string(c, 1);
        }
        else
        {
          result = S.Split(new string[] { separator }, StringSplitOptions.None);
        }
      }
      else
      {
        Debug.Assert(callFrame.Arg0.ValueType == mdr.ValueTypes.Object, "Does not know what to do with argument type {0} in split", callFrame.Arg0.ValueType);
        mdr.DRegExp regexpSeparator = callFrame.Arg0.AsDObject() as mdr.DRegExp;
        Debug.Assert(regexpSeparator != null, "Does not know what to do with argument type {0} in split", callFrame.Arg0.ValueType);
        //string pattern = regexpSeparator.Value.ToString();
        //result = Regex.Split(S, pattern, RegexOptions.ECMAScript);
        result = regexpSeparator.Value.Split(S);
      }

      for (int i = 0; i < result.Length && i < limit; i++)
      {
        //A.SetField(i, new mdr.DString(result[i]));
        A.SetField(i, result[i]);
      }

      callFrame.Return.Set(A);
    }
Exemplo n.º 5
0
    // ECMA-262 section 15.5.4.10
    void match(ref mdr.CallFrame callFrame)
    {
      Debug.WriteLine("Calling JSString.match()");
      string S = callFrame.This.ToString();
      mdr.DRegExp rx = callFrame.Arg0.AsDObject() as mdr.DRegExp;
      if (rx == null)
        rx = new mdr.DRegExp(callFrame.Arg0.AsString());
      if (!rx.Global)
      {
        callFrame.Return.Set(rx.ExecImplementation(S));
        return;
      }

      mdr.DArray result = new mdr.DArray();
      int i = 0;
      foreach (Match match in (rx.Value).Matches(S))
      {
        foreach (Group group in match.Groups)
        {
          //result.SetField(i++, new mdr.DString(group.Value.ToString()));
          result.SetField(i++, group.Value);
        }
      }
      callFrame.Return.Set(result);
    }
Exemplo n.º 6
0
        public mdr.DObject ExecImplementation(string S)
        {
            if (S == null)
                return Runtime.Instance.DefaultDNull;
            Match match = MatchImplementation(S);
            if (match == null)
                return Runtime.Instance.DefaultDNull;

            int n = match.Captures.Count;
            mdr.DArray result = new mdr.DArray(n);
            result.SetField("index", match.Index);
            result.SetField("input", S);
            //result.SetField(0, match.Value);
            if (MatchedGroups != null)
            {
              for (int g = 0; g < MatchedGroups.Count; g++)
              {
                 if (MatchedGroups[g].Captures.Count > 0)
                 {
                    result.SetField(g, MatchedGroups[g].Captures[0].Value);
                 }
              }
            }
            return result;
        }