Inheritance: ICollection, IEnumerable
Ejemplo n.º 1
0
		private void AddPeople(string groupName, string singular, string plural, StringBuilder sb, GroupCollection groups) {
			if (groups[groupName].Success) {
				if (sb.Length != 0) sb.AppendLine();
				string people=htmlRx.Replace(groups[groupName].Value, string.Empty);
				sb.Append(people.Contains(",") ? plural:singular).Append(people);
			}
		}
Ejemplo n.º 2
0
        private void SetScorePosition(IScore score, GroupCollection parts)
        {
            var offset = string.IsNullOrEmpty(parts[2].Value) ? parts[1].Length : Convert.ToInt32(parts[2].Value);
            var timing = parts[1].Value.Last() == '\\' ? OffsetTiming.Early : OffsetTiming.Late;

            score.SetPosition(timing == OffsetTiming.Early ? -offset : offset);
        }
 static public int getItem(IntPtr l)
 {
     try {
         System.Text.RegularExpressions.GroupCollection self = (System.Text.RegularExpressions.GroupCollection)checkSelf(l);
         LuaTypes t = LuaDLL.lua_type(l, 2);
         if (matchType(l, 2, t, typeof(System.Int32)))
         {
             int v;
             checkType(l, 2, out v);
             var ret = self[v];
             pushValue(l, true);
             pushValue(l, ret);
             return(2);
         }
         else if (matchType(l, 2, t, typeof(System.String)))
         {
             string v;
             checkType(l, 2, out v);
             var ret = self[v];
             pushValue(l, true);
             pushValue(l, ret);
             return(2);
         }
         pushValue(l, false);
         LuaDLL.lua_pushstring(l, "No matched override function to call");
         return(2);
     }
     catch (Exception e) {
         return(error(l, e));
     }
 }
 protected virtual IEnumerable<string> GetValues(GroupCollection groups)
 {
     for (var i = 1; i < groups.Count; i++)
     {
         yield return groups[i].Value;
     }
 }
Ejemplo n.º 5
0
////////////////////// GroupCollection ///////////////////////////////////////
// constructors

// fields

// properties
    static void GroupCollection_Count(JSVCall vc)
    {
        System.Text.RegularExpressions.GroupCollection _this = (System.Text.RegularExpressions.GroupCollection)vc.csObj;
        var result = _this.Count;

        JSApi.setInt32((int)JSApi.SetType.Rval, (System.Int32)(result));
    }
Ejemplo n.º 6
0
        protected override void ExtraVideoMatch(VideoInfo video, GroupCollection matchGroups)
        {

            TrackingInfo ti = new TrackingInfo();

            // for southpark world
            System.Text.RegularExpressions.Group epGroup = matchGroups["Episode"];
            if (epGroup.Success)
                ti.Regex = Regex.Match(epGroup.Value, @"(?<Season>\d\d)(?<Episode>\d\d)");

            // for nl and de
            if (ti.Season == 0)
                ti.Regex = Regex.Match(video.VideoUrl, @"\/S(?<Season>\d{1,3})E(?<Episode>\d{1,3})-", RegexOptions.IgnoreCase);

            if (ti.Season != 0)
            {
                ti.Title = "South Park";
                ti.VideoKind = VideoKind.TvSeries;
                video.Other = new VideoInfoOtherHelper() { TI = ti };
            }
            else
                video.Other = new VideoInfoOtherHelper();
            int time;
            if (Int32.TryParse(video.Airdate, out time))
            {
                video.Airdate = epoch.AddSeconds(time).ToString();
            }
        }
Ejemplo n.º 7
0
    static void GroupCollection_IsSynchronized(JSVCall vc)
    {
        System.Text.RegularExpressions.GroupCollection _this = (System.Text.RegularExpressions.GroupCollection)vc.csObj;
        var result = _this.IsSynchronized;

        JSApi.setBooleanS((int)JSApi.SetType.Rval, (System.Boolean)(result));
    }
Ejemplo n.º 8
0
        static public axis fromJson(string json)
        {
            if (jsonParser == null)
            {
                jsonParser = new Regex("\"input\": \"(.*)\",.*" +
                                       "\"key\": \"(.*)\",.*" +
                                       "\"type\": \"(.*)\",.*" +
                                       "\"isKey\": \"(.*)\",.*" +
                                       "\"name\": \"(.*)\",.*" +
                                       "\"rest\": \"(.*)\"");
            }
            MatchCollection matches = jsonParser.Matches(json);
            GroupCollection groups  = matches[0].Groups;

            string   input  = groups[1].Value;
            int      ikey   = Int32.Parse(groups[2].Value);
            KeyCode  key    = (KeyCode)ikey;
            int      itype  = Int32.Parse(groups[3].Value);
            axisType type   = (axisType)itype;
            int      iIsKey = Int32.Parse(groups[4].Value);
            bool     isKey  = (iIsKey != 0);
            string   name   = groups[5].Value;
            float    rest   = float.Parse(groups[6].Value, CultureInfo.InvariantCulture);

            axis a = new axis();

            a.input = input;
            a.key   = key;
            a.type  = type;
            a.isKey = isKey;
            a.name  = name;
            a.rest  = rest;
            return(a);
        }
Ejemplo n.º 9
0
        protected override PhenomInfoWithNSW _Decode(System.Text.RegularExpressions.GroupCollection groups)
        {
            PhenomInfoWithNSW ret = null;

            if (groups[0].Success)
            {
                ret = new PhenomInfoWithNSW();

                if (groups[1].Success)
                {
                    ret.IsNSW = true;
                }
                else
                {
                    ret = new PhenomInfoWithNSW();

                    string str = groups[2].Value;
                    Match  m   = Regex.Match(str, RegEx);
                    List <ePhenomCollection> colls = null;

                    colls = DecodePhenomSets(m);

                    ret.AddRange(colls);
                }
            }

            return(ret);
        }
Ejemplo n.º 10
0
    static void GroupCollection_SyncRoot(JSVCall vc)
    {
        System.Text.RegularExpressions.GroupCollection _this = (System.Text.RegularExpressions.GroupCollection)vc.csObj;
        var result = _this.SyncRoot;

        JSMgr.datax.setWhatever((int)JSApi.SetType.Rval, result);
    }
Ejemplo n.º 11
0
        public static bool TestCondition(string variable, string condition, bool noCase, out GroupCollection groupCollection)
        {
            groupCollection = null;

            // negate condition ?
            var negate = false;
            if (condition.StartsWith("!")) {
                negate = true;
                condition = condition.Substring(1);
            }

            if (condition.StartsWith("=")) {
                condition = condition.Substring(1);
                return negate ^
                       String.Equals(variable, condition,
                                     noCase ? StringComparison.OrdinalIgnoreCase : StringComparison.Ordinal);
            }

            if (condition.StartsWith("<")) {
                condition = condition.Substring(1);
                return negate ^ String.CompareOrdinal(variable, condition) == -1;
            }

            if (condition.StartsWith(">")) {
                condition = condition.Substring(1);
                return negate ^ String.CompareOrdinal(variable, condition) == 1;
            }

            // otherwise it's a regular expression
            var match = Regex.Match(variable, condition, noCase ? RegexOptions.IgnoreCase : RegexOptions.None);
            groupCollection = match.Groups;
            return negate ^ match.Success;
        }
        public string GetFormattedName(string fileName, IEnumerable <FileTag> fileTagList)
        {
            string FileNewName = Format;

            fileTagList.DefaultIfEmpty(DefaultFileTagObject);
            try {
                System.Text.RegularExpressions.GroupCollection NameRegexMatchGroups = NameRegex.Match(fileName).Groups;
                Match FormatGroupsRegexMatch = FormatGroupsRegex.Match(FileNewName), FormatAttributesRegexMatch;
                while (FormatGroupsRegexMatch.Success)
                {
                    FileNewName = FileNewName.Replace(FormatGroupsRegexMatch.ToString(),
                                                      NameRegexMatchGroups[Convert.ToInt32(FormatGroupsRegexMatch.Groups[1].Value)].ToString());
                    FormatGroupsRegexMatch = FormatGroupsRegexMatch.NextMatch();
                }
                FormatAttributesRegexMatch = FormatAttributesRegex.Match(FileNewName);
                FileTag FileTagObject;
                while (FormatAttributesRegexMatch.Success)
                {
                    FileTagObject = fileTagList.FirstOrDefault(fO => fO.TagName == FormatAttributesRegexMatch.Groups[1].Value);
                    FileNewName   = FileNewName.Replace(FormatAttributesRegexMatch.ToString(), FileTagObject.TagValue);
                    FormatAttributesRegexMatch = FormatAttributesRegexMatch.NextMatch();
                }
            } catch (Exception ex) {
                Log.Write("Task::GetFormattedName() Error -> " + ex.Message);
                FileNewName = fileName;
            }
            return(FileNewName);
        }
Ejemplo n.º 13
0
    static void GroupCollection_Item_String(JSVCall vc)
    {
        System.String arg0 = (System.String)JSApi.getStringS((int)JSApi.GetType.Arg);
        System.Text.RegularExpressions.GroupCollection _this = (System.Text.RegularExpressions.GroupCollection)vc.csObj;
        var result = _this[arg0];

        JSMgr.datax.setObject((int)JSApi.SetType.Rval, result);
    }
Ejemplo n.º 14
0
		void SetStackTraceFilePosition(GroupCollection groups)
		{
			string fileName = groups[1].Value;
			int line = Convert.ToInt32(groups[2].Value);
			int column = 1;
			
			StackTraceFilePosition = new FilePosition(fileName, line, column);
		}
Ejemplo n.º 15
0
 private void InitializeFrom(StringScanner/*!*/ other) {
     _currentPosition = other._currentPosition;
     _foundPosition = other._foundPosition;
     _lastMatch = other._lastMatch;
     _lastMatchingGroups = other._lastMatchingGroups;
     _previousPosition = other._previousPosition;
     _scanString = other.ScanString;
 }
Ejemplo n.º 16
0
 private int SelectValue( GroupCollection groups, ref string str )
 {
     int q = 4;
       do {
     str = groups[ q ].Value;
     q += 2;
       } while( q <= 8 && str.Length == 0 );
       return q - 2;
 }
 private static string[] ConvertRegexGroupsToArray(GroupCollection groups)
 {
     var ret = new string[groups.Count - 1];
     for (var i = 1; i < groups.Count; i++)
     {
         ret[i - 1] = groups[i].Value;
     }
     return ret.Where(x => !String.IsNullOrWhiteSpace(x)).ToArray(); // HACK: This should be changed in the Regex behaviour and this hack should be removed (wait for internet to see the best way)
 }
Ejemplo n.º 18
0
        protected override IEnumerable<string> GetValues(GroupCollection groups)
        {
            for (var i = 1; i < groups.Count; i++)
            {
                if (groups[i].Success) return new[] {groups[i].Value};
            }

            return new string[0];
        }
Ejemplo n.º 19
0
 // �e���v���[�g�t�@�C���� Regex �p�[�X
 public string Parse(MarkedData md, string templateData)
 {
     // ���݂̃f�[�^��L���v�`��
     myCaptureDataList = GetCapture(templateData, md.InnerData);
     if(myCaptureDataList == null){
         Log.AddWarning("�e���v���[�g�Ɏg�p���錻�݃f�[�^�̃L���v�`�����ł��܂���ł����B");
         return CreateSample(templateData);
     }
     return CreateResult(templateData);
 }
Ejemplo n.º 20
0
        private static DynamicDictionary GetParameters(Regex regex, GroupCollection groups)
        {
            dynamic data = new DynamicDictionary();

            for (var i = 1; i <= groups.Count; i++)
            {
                data[regex.GroupNameFromNumber(i)] = groups[i].Value;
            }

            return data;
        }
        private static DynamicDictionary GetParameters(Regex regex, GroupCollection groups)
        {
            dynamic data = new DynamicDictionary();

            for (int i = 1; i <= groups.Count; i++)
            {
                data[regex.GroupNameFromNumber(i)] = Uri.UnescapeDataString(groups[i].Value);
            }

            return data;
        }
Ejemplo n.º 22
0
        private void Initialise()
        {
            System.Text.RegularExpressions.Match match
                = System.Text.RegularExpressions.Regex.Match(this.Value, archetypeIdPattern, RegexOptions.Compiled | RegexOptions.Singleline);

            if (!match.Success)
            {
                throw new InvalidOperationException("Archetype ID not valid format");
            }

            this.matchGroups = match.Groups;
        }
Ejemplo n.º 23
0
 private void Add(GroupCollection g, string category, IDictionary<string, double> externalDictionary, string success, string fail)
 {
     var number = g[1].Value;
       var unit = g[2].Value;
       var wordToAdd = g[3].Value;
       var duration = BanTime(number, unit);
       if (!category.Contains("Regex")) wordToAdd = wordToAdd.ToLower();
       if (Datastore.AddToStateString(category, wordToAdd, duration.TotalSeconds, externalDictionary))
     Send(wordToAdd + success);
       else
     Send(wordToAdd + fail + Tools.PrettyDeltaTime(duration));
 }
Ejemplo n.º 24
0
		private Match (Regex regex, IMachine machine,
						GroupCollection groups,
						string text, int text_length,
						int index, int length, int n_caps)
			: base (text, index, length, n_caps) {
			this.regex = regex;
			this.machine = machine;
			this.text_length = text_length;

			this.groups = groups;
			groups.SetValue (this, 0);
		}
 static public int get_Count(IntPtr l)
 {
     try {
         System.Text.RegularExpressions.GroupCollection self = (System.Text.RegularExpressions.GroupCollection)checkSelf(l);
         pushValue(l, true);
         pushValue(l, self.Count);
         return(2);
     }
     catch (Exception e) {
         return(error(l, e));
     }
 }
Ejemplo n.º 26
0
        private void AddToList(GroupCollection groups, List<string> values, string[] ignoreValues)
        {
            string key = groups["name"].Value;
            string value = groups["value"].Value;

            if (!String.IsNullOrEmpty(key) && !String.IsNullOrEmpty(value))
            {
                string valueToAdd = String.Format("{0}={1}", key, HttpUtility.UrlEncode(value));
                if (ignoreValues == null || Array.IndexOf(ignoreValues, valueToAdd) == -1)
                    values.Add(valueToAdd);
            }
        }
Ejemplo n.º 27
0
        override public UrlParams parsePostBody(string input)
        {
            string pattern = @"^start=([0-9]*)&limit=([0-9]*)$";
            Regex  rgx     = new Regex(pattern, RegexOptions.IgnoreCase);

            System.Text.RegularExpressions.GroupCollection matches = rgx.Match(input).Groups;
            if (matches.Count > 0)
            {
                result.Start = int.Parse(matches[1].ToString());
                result.Limit = int.Parse(matches[2].ToString());
            }
            return(result);
        }
Ejemplo n.º 28
0
 private static IEnumerable<string> DevNamesFrom(GroupCollection groups)
 {
     int skip = 1;
     foreach (Group @group in groups)
     {
         if (skip > 0)
         {
             skip--;
             continue;
         }
         yield return @group.Value;
     }
 }
        public static void AddNewAlias(GroupCollection aliasGroup)
        {
            string aliasName = aliasGroup[1].ToString();
            SteamID steamID = (SteamID) UInt64.Parse(aliasGroup[2].ToString());

            StreamWriter sw = File.AppendText("alias_list.txt");

            sw.WriteLine("{0}:{1}", aliasName, steamID.ConvertToUInt64());

            sw.Close();

            Roulette.BuildAliasList();
        }
 static public int GetEnumerator(IntPtr l)
 {
     try {
         System.Text.RegularExpressions.GroupCollection self = (System.Text.RegularExpressions.GroupCollection)checkSelf(l);
         var ret = self.GetEnumerator();
         pushValue(l, true);
         pushValue(l, ret);
         return(2);
     }
     catch (Exception e) {
         return(error(l, e));
     }
 }
Ejemplo n.º 31
0
        override public UrlParams parsePostBody(string input)
        {
            string pattern = @"^action=(getRate)&code=([A-Z]*)&date=([0-9\-T\:]*)$";
            Regex  rgx     = new Regex(pattern, RegexOptions.IgnoreCase);

            System.Text.RegularExpressions.GroupCollection matches = rgx.Match(input).Groups;
            if (matches.Count > 0)
            {
                result.Action = matches[1].ToString();
                result.Code   = matches[2].ToString();
                result.Date   = DateTime.Parse(matches[3].ToString());
            }
            return(result);
        }
 internal void InitializeParams(GroupCollection groups)
 {
     int iterator = 0;
     foreach (Group group in groups)
     {
         if (iterator != 0)
         {
             foreach (Capture capture in group.Captures)
             {
                 parameters.Set(capture.Value, iterator - 1);
             }
         }
         iterator++;
     }
 }
Ejemplo n.º 33
0
        protected override CloudInfo _Decode(System.Text.RegularExpressions.GroupCollection groups)
        {
            CloudInfo ret = null;

            if (groups[0].Success)
            {
                ret = new CloudInfo();

                if (groups[2].Success)
                {
                    ret.SetNSC();
                }
                else if (groups[3].Success)
                {
                    ret.SetSKC();
                }
                else if (groups[4].Success)
                {
                    ret.SetCLR();
                }
                else if (groups[5].Success)
                {
                    if (groups[5].Value == "///")
                    {
                        ret.SetVerticalVisibility(null);
                    }
                    else
                    {
                        ret.SetVerticalVisibility(
                            groups[5].GetIntValue());
                    }
                }
                else
                {
                    string str = groups[1].Value;
                    Match  m   = Regex.Match(str, R_CLOUD_ITEM);

                    while (m.Success)
                    {
                        ret.Add(xDecodeCloud(m));

                        m = m.NextMatch();
                    }
                }
            }

            return(ret);
        }
 static public int CopyTo(IntPtr l)
 {
     try {
         System.Text.RegularExpressions.GroupCollection self = (System.Text.RegularExpressions.GroupCollection)checkSelf(l);
         System.Array a1;
         checkType(l, 2, out a1);
         System.Int32 a2;
         checkType(l, 3, out a2);
         self.CopyTo(a1, a2);
         pushValue(l, true);
         return(1);
     }
     catch (Exception e) {
         return(error(l, e));
     }
 }
Ejemplo n.º 35
0
        internal Match(string text, Matcher matcher, Regex regex, int start)
            : base(text, start, start)
        {
            this.matcher = matcher;
            this.regex = regex;

            bool success = matcher.Find(start);
            if (success)
            {
                UpdateRegion(matcher.Start(), matcher.End());
                groupCollection = new GroupCollection(text, matcher, this);  
            }
            else
            {
                UpdateRegion(-1, -1);
            }
        }
Ejemplo n.º 36
0
        private static string ResultFileNameFromPatterns( string[] patterns, GroupCollection parts )
        {
            var rslt = new System.Text.StringBuilder();
            var ptr_parts = new List<string[]>();
            for( int i = 0; i < patterns.Length; ++i )
                ptr_parts.Add(patterns[i].Split('*'));

            int ptr_part_num = ptr_parts[0].Length;
            for( int i = 0; i < ptr_part_num; ++i )
            {
                if( i > 0 )
                    rslt.Append(parts[i].Value);

                rslt.Append(string.Join(string.Empty, ptr_parts.Select(ptrs => ptrs[i]).Distinct()));
            }

            return rslt.ToString();
        }
Ejemplo n.º 37
0
        public void httpBodyInfoHandle(HttpListenerContext context, GroupCollection url)
        {
            try {
                HttpListenerResponse response = context.Response;
                CelestialBody body = KerbalGIS.findBody (url [1].Value);
                if (body == null || body.BiomeMap.Attributes.Length <= 1) {
                    httpError (context);
                    return;
                }

                string ret = Info.getJSONInfo (body);

                response.StatusCode = 200;
                response.ContentType = "application/json";
                response.Close (Encoding.UTF8.GetBytes (ret), false);
            } catch (Exception e) {
                Debug.LogException (e);
            }
        }
Ejemplo n.º 38
0
        private static string FileNameFromPattern( string pattern, GroupCollection parts )
        {
            try
            {
                string filename = pattern;

                // NOTE: On the 0th index is the whole file name.
                for( int i = 1; i < parts.Count; ++i )
                {
                    int ind = filename.IndexOf('*');
                    filename = filename.Remove(ind, 1);
                    filename = filename.Insert(ind, parts[i].Value);
                }
                return filename;
            }
            catch
            {
                return null;
            }
        }
Ejemplo n.º 39
0
        private static RouteParameters GetParameters(RouteDescription description, GroupCollection groups)
        {
            var segments =
                new ReadOnlyCollection<string>(
                    description.Path.Split(new[] { "/" },
                    StringSplitOptions.RemoveEmptyEntries).ToList());

            var parameters =
                from segment in segments
                where segment.IsParameterized()
                select segment.GetParameterName();

            dynamic data =
                new RouteParameters();

            foreach (var parameter in parameters)
            {
                data[parameter] = groups[parameter].Value;
            }

            return data;
        }
Ejemplo n.º 40
0
 protected override void ExtraVideoMatch(VideoInfo video, GroupCollection matchGroups)
 {
     bool isLive = video.VideoUrl.StartsWith(@"http://live");
     if (isLive)
     {
         string start = video.Airdate;
         string end = matchGroups["AirdateEnd"].Value;
         DateTime dtStart, dtEnd;
         if (DateTime.TryParseExact(start, "yyyy-M-d-H-mm-ss", CultureInfo.InvariantCulture,
             DateTimeStyles.None, out dtStart) &&
             DateTime.TryParseExact(end, "yyyy-M-d-H-mm-ss", CultureInfo.InvariantCulture,
             DateTimeStyles.None, out dtEnd))
         {
             video.Airdate = dtStart.ToString();
             video.Length = (dtEnd - dtStart).ToString();
         }
     }
     else
         if (matchGroups["Month"].Success && matchGroups["Date"].Success && String.IsNullOrEmpty(video.Airdate))
         {
             video.Airdate = matchGroups["Month"].Value + ' ' + matchGroups["Date"].Value;
         }
     video.Thumb = FixImageUrl(video.Thumb);
 }
Ejemplo n.º 41
0
        private static void parseCoords(this IGeographicPositionAndDateTime position, GroupCollection aprsBaseCoordsMatchGroup)
        {
            try
            {
                position.PositionTimeUTC = DateTime.ParseExact($"{DateTime.Now:yyyyMMdd} {aprsBaseCoordsMatchGroup[5].Value}", "yyyyMMdd HHmmss", CultureInfo.InvariantCulture);

                // lat (5111.32N)
                position.PositionLatDegrees = parseAprsCoordValue(aprsBaseCoordsMatchGroup[6].Value);
                if (aprsBaseCoordsMatchGroup[7].Value == "S")
                    position.PositionLatDegrees *= -1;

                // lon (00102.04W)
                position.PositionLonDegrees = parseAprsCoordValue(aprsBaseCoordsMatchGroup[8].Value);
                if (aprsBaseCoordsMatchGroup[9].Value == "W")
                    position.PositionLonDegrees *= -1;

                // Altitude
                position.PositionAltitudeMeters = (int)Math.Round(int.Parse(aprsBaseCoordsMatchGroup[14].Value, CultureInfo.InvariantCulture) / 3.28084f);
            }
            catch (Exception e)
            {
                throw new BeaconParserException("Error while parsing geographical position.", aprsBaseCoordsMatchGroup[0].Value, e);
            }
        }
Ejemplo n.º 42
0
        private static void AppendLastCharOfLastMatchGroup(GroupCollection groups, MutableString result) {
            int i = groups.Count - 1;
            // move to last successful match group
            while (i > 0 && !groups[i].Success) {
                i--;
            }

            if (i > 0 && groups[i].Value.Length > 0) {
                result.Append(groups[i].Value[groups[i].Length - 1]);
            }
        }
Ejemplo n.º 43
0
 private static void AppendReplacementExpression(MutableString input, GroupCollection/*!*/ groups, MutableString/*!*/ result, MutableString/*!*/ replacement) {
     int backslashCount = 0;
     for (int i = 0; i < replacement.Length; i++) {
         char c = replacement.GetChar(i);
         if (c == '\\')
             backslashCount++;
         else if (backslashCount == 0)
             result.Append(c);
         else {
             AppendBackslashes(backslashCount, result, 0);
             // Odd number of \'s + digit means insert replacement expression
             if ((backslashCount & 1) == 1) {
                 if (Char.IsDigit(c)) {
                     AppendGroupByIndex(groups, c - '0', backslashCount, result);
                 } else if (c == '&') {
                     AppendGroupByIndex(groups, groups.Count - 1, backslashCount, result);
                 } else if (c == '`') {
                     // Replace with everything in the input string BEFORE the match
                     result.Append(input, 0, groups[0].Index);
                 } else if (c == '\'') {
                     // Replace with everything in the input string AFTER the match
                     int start = groups[0].Index + groups[0].Length;
                     result.Append(input, start, input.Length - start);
                 } else if (c == '+') {
                     // Replace last character in last successful match group
                     AppendLastCharOfLastMatchGroup(groups, result);
                 } else {
                     // unknown escaped replacement char, go ahead and replace untouched
                     result.Append('\\');
                     result.Append(c);
                 }
             } else {
                 // Any other # of \'s or a non-digit character means insert literal \'s and character
                 AppendBackslashes(backslashCount, result, 1);
                 result.Append(c);
             }
             backslashCount = 0;
         }
     }
     AppendBackslashes(backslashCount, result, 1);
 }
Ejemplo n.º 44
0
        public SqlRuleMapResult PreparePropertiesFromString <T>(string containerRuleInSqlCmd, T entity, string sqlCmdMapRegexRule = "{(.*?)}")  where T : class
        {// 结果字典:key=字符串中的关键字,value=实体属性
            System.Text.RegularExpressions.Regex           reg    = new System.Text.RegularExpressions.Regex(sqlCmdMapRegexRule);
            System.Text.RegularExpressions.MatchCollection matchs = reg.Matches(containerRuleInSqlCmd);
            List <string> param = new List <string>();

            System.Reflection.PropertyInfo[] pis            = entity.GetType().GetProperties();
            Dictionary <string, string>      ruleAsProperty = new Dictionary <string, string>();
            List <string>       loseMapRule = new List <string>();       //语句规则中没法匹配的规则项
            List <SqlParameter> sqlParam    = new List <SqlParameter>(); //在规则全部符合的情形下进行执行命令的参数列表
            string waitExuet = containerRuleInSqlCmd;

            foreach (System.Text.RegularExpressions.Match item in matchs)
            {
                System.Text.RegularExpressions.GroupCollection gc = item.Groups;
                string ruleParamName   = gc[1].Value;
                string ruleParamFormat = gc[0].Value; //数组元素  表达式1 {(.*?)} =[{属性},属性] ,表达式2 ({.*?})=[{属性},{属性}]
                if (ruleAsProperty.ContainsKey(ruleParamFormat))
                {                                     //定义了多个相对规则参数名,会在第一次出现时进行处理
                    continue;
                }
                bool noMap = true;
                System.Reflection.PropertyInfo targetProperty = null;
                foreach (System.Reflection.PropertyInfo pi in pis)
                {
                    string pn = pi.Name;
                    if (pn.ToLower() == ruleParamName.ToLower())
                    {//这是目标属性
                        ruleAsProperty.Add(ruleParamFormat, pn);
                        noMap          = false;
                        targetProperty = pi;
                        break;
                    }
                }
                if (loseMapRule.Count > 0 || noMap)
                {//存在规则参数没有匹配的属性
                    loseMapRule.Add(ruleParamFormat);
                }
                else
                {
                    #region 将规则映射到参数
                    string pn = "@" + ruleAsProperty[ruleParamFormat];
                    waitExuet = waitExuet.Replace(ruleParamFormat, pn);
                    object obj = targetProperty.GetValue(entity, null);
                    if (obj != null)
                    {
                        sqlParam.Add(new SqlParameter()
                        {
                            ParameterName = pn, Value = obj
                        });
                    }
                    else
                    {
                        sqlParam.Add(new SqlParameter()
                        {
                            ParameterName = pn, Value = DBNull.Value
                        });
                    }
                    #endregion
                }
            }
            return(new SqlRuleMapResult()
            {
                OriginSql = containerRuleInSqlCmd,
                WaitExcuteSql = new List <string>()
                {
                    waitExuet
                },
                NoMapRule = loseMapRule,
                SqlParams = sqlParam,
                RuleMapProperty = ruleAsProperty
            });
        }
Ejemplo n.º 45
0
 // Nonpublic constructor
 internal GroupEnumerator(GroupCollection rgc)
 {
     _curindex = -1;
     _rgc      = rgc;
 }
Ejemplo n.º 46
0
 public GroupCollection(System.Text.RegularExpressions.GroupCollection groupCollection, string[] groupsname) :
     base(groupsname)
 {
     _groupCollection = groupCollection;
 }
Ejemplo n.º 47
0
 internal GroupEnumerator(GroupCollection rgc)
 {
     this._rgc = rgc;
 }
Ejemplo n.º 48
0
 private static void AppendGroupByIndex(GroupCollection/*!*/ groups, int index, int backslashCount, MutableString/*!*/ result) {
     if (groups[index].Success) {
         result.Append(groups[index].Value);
     }
 }
Ejemplo n.º 49
0
 public GroupCollection(RegExp.GroupCollection groups, RegExp.Regex regex)
 {
     _groups = groups;
     _regex  = regex;
 }
 public GroupCollection(RegExp.GroupCollection groups)
 {
     _groups = groups;
 }
Ejemplo n.º 51
0
		/// <summary>
		/// For Debugging and testing
		/// </summary>
		/// <param name="groups"></param>
		private void BuildGroupTree(GroupCollection groups) 
		{
			int i = 0;
			foreach (Group group in groups)
			{
				log.AddEntry("{1}:Group: {0}", group.Value, i);
				
				int j = 0;
				foreach (Capture capture in group.Captures)
				{
					log.AddEntry("{1}:Capture: {0}", capture.Value, j);
					j++;
				}
				i++;
			}
		}
Ejemplo n.º 52
0
 /// <summary>
 /// Returns the input typed as a generic IEnumerable of the groups
 /// </summary>
 /// <returns></returns>
 public static IEnumerable <System.Text.RegularExpressions.Group> AsEnumerable(
     this System.Text.RegularExpressions.GroupCollection gc)
 {
     return(gc.Cast <Group>());
 }