コード例 #1
0
ファイル: String.cs プロジェクト: modulexcite/NiL.JS
 public static JSObject match(JSObject self, Arguments args)
 {
     if (self.valueType <= JSObjectType.Undefined || (self.valueType >= JSObjectType.Object && self.Value == null))
         throw new JSException(new TypeError("String.prototype.match called on null or undefined"));
     var a0 = args[0];
     if (a0.valueType == JSObjectType.Object && a0.oValue is RegExp)
     {
         var regex = a0.oValue as RegExp;
         if (!regex._global)
         {
             regex.lastIndex.valueType = JSObjectType.Int;
             regex.lastIndex.iValue = 0;
             return regex.exec(self);
         }
         else
         {
             var match = regex.regEx.Match(self.ToString());
             int index = 0;
             var res = new Array();
             while (match.Success)
             {
                 res.data[index++] = match.Value;
                 match = match.NextMatch();
             }
             return res;
         }
     }
     else
     {
         var match = new Regex((a0.valueType > JSObjectType.Undefined ? (object)a0 : "").ToString(), RegexOptions.ECMAScript).Match(self.ToString());
         var res = new Array(match.Groups.Count);
         for (int i = 0; i < match.Groups.Count; i++)
             res.data[i] = match.Groups[i].Value;
         res.GetMember("index", true, true).Assign(match.Index);
         res.GetMember("input", true, true).Assign(self);
         return res;
     }
 }