示例#1
0
 private void SetMatchValues(MatchValues matchValues)
 {
     _matchValues = matchValues;
     // test matchValues is null to keep _text, _matchIndex, _matchLength from last match
     if (matchValues != null)
     {
         _text        = matchValues.Match.Value;
         _matchIndex  = matchValues.Match.Index;
         _matchLength = matchValues.Match.Length;
     }
 }
示例#2
0
        public NamedValues <ZValue> ExtractTextValues(ref string text)
        {
            NamedValues <ZValue> values = new NamedValues <ZValue>();

            foreach (RegexValues rv in this.Values)
            {
                MatchValues matchValues = rv.Match(text);
                if (matchValues.Success)
                {
                    values.SetValues(matchValues.GetValues());
                    text = matchValues.Replace("");
                }
            }
            return(values);
        }
示例#3
0
 public FindNumber Find(string text)
 {
     foreach (RegexValues rv in _numberRegexList.Values)
     {
         MatchValues matchValues = rv.Match(text);
         if (matchValues.Success)
         {
             NamedValues <ZValue> values = matchValues.GetValues();
             if (values.ContainsKey("number"))
             {
                 int    number;
                 ZValue value = values["number"];
                 if (value is ZString)
                 {
                     if (!int.TryParse((string)value, out number))
                     {
                         throw new PBException("error finding number text is'nt a number : \"{0}\"", (string)value);
                     }
                 }
                 else if (value is ZInt)
                 {
                     number = (int)value;
                 }
                 else
                 {
                     throw new PBException("error finding number value is'nt a number : {0}", value);
                 }
                 //return new FindNumber { found = true, number = number, remainText = rv.MatchReplace("_"), regexValues = rv };
                 return(new FindNumber {
                     found = true, number = number, matchValues = matchValues
                 });
             }
         }
     }
     return(new FindNumber {
         found = false
     });
 }
示例#4
0
 public static RegexCaptureValues CreateRegexCaptureValues(MatchValues matchValues, bool allValues = false)
 {
     if (matchValues != null && matchValues.Success)
     {
         if (allValues)
         {
             return new RegexCaptureValues {
                        capture = matchValues.Match.Value, values = matchValues.GetAllValues()
             }
         }
         ;
         else
         {
             return new RegexCaptureValues {
                        capture = matchValues.Match.Value, values = matchValues.GetValues()
             }
         };
     }
     else
     {
         return(null);
     }
 }
示例#5
0
 public MatchValues FindNext(string text, int startat, bool contiguous = false)
 {
     if (_trace)
     {
         Trace.WriteLine($"RegexValuesList.FindNext() : text \"{text}\" start at {startat} contiguous {contiguous}");
     }
     foreach (RegexValues rv in this.Values)
     {
         if (_trace)
         {
             Trace.WriteLine($"RegexValuesList.FindNext() : pattern \"{rv.Pattern}\"");
         }
         MatchValues matchValues = rv.Match(text, startat);
         if (matchValues.Success)
         {
             if (!contiguous || matchValues.Match.Index == startat)
             {
                 return(matchValues);
             }
         }
     }
     return(null);
 }
示例#6
0
 public FindDate Find(string text)
 {
     foreach (RegexValues rv in _dateRegexList.Values)
     {
         MatchValues matchValues = rv.Match(text);
         if (matchValues.Success)
         {
             Date     date;
             DateType dateType;
             if (zdate.TryCreateDate(matchValues.GetValues(), out date, out dateType))
             {
                 //return new FindDate { found = true, date = date, dateType = dateType, remainText = rv.MatchReplace("_"), regexValues = rv };
                 //return new FindDate { found = true, date = date, dateType = dateType, matchValues = matchValues, matchValuesList = new MatchValues[] { matchValues } };
                 return(new FindDate {
                     Found = true, Date = date, DateType = dateType, matchValues = matchValues
                 });
                 //return new FindDate { Found = true, Date = date, DateType = dateType, matchValues = matchValues, matchValuesList = null };
             }
         }
     }
     return(new FindDate {
         Found = false
     });
 }
示例#7
0
        //public FindText_v2()
        //{
        //}

        public FindText_v2(MatchValues matchValues, RegexValuesList regexValuesList)
        {
            _regexValuesList = regexValuesList;
            SetMatchValues(matchValues);
        }
示例#8
0
        public FindDate Find(string text, Date?expectedDate = null)
        {
            //List<MatchValues> matchValuesList = new List<MatchValues>();
            List <MatchDate> matchDates = new List <MatchDate>();

            foreach (RegexValues rv in _dateRegexList.Values)
            {
                MatchValues matchValues = rv.Match(text);
                while (matchValues.Success)
                {
                    Date     date;
                    DateType dateType;
                    if (zdate.TryCreateDate(matchValues.GetValues(), out date, out dateType))
                    {
                        if (!_multipleSearch)
                        {
                            //return new FindDate { found = true, date = date, dateType = dateType, matchValues = matchValues, matchValuesList = matchValuesList.Count > 0 ? matchValuesList.ToArray() : null };
                            return new FindDate {
                                       Found = true, Date = date, DateType = dateType, matchValues = matchValues
                            }
                        }
                        ;
                        //return new FindDate { Found = true, Date = date, DateType = dateType, MatchValues = matchValues.GetValuesInfos() };
                        else
                        {
                            //matchDates.Add(new MatchDate { Index = matchValuesList.Count, Date = date, DateType = dateType, MatchValues = matchValues });
                            matchDates.Add(new MatchDate {
                                Date = date, DateType = dateType, MatchValues = matchValues
                            });
                        }
                        //matchDates.Add(new MatchDate { Date = date, DateType = dateType, MatchValues = matchValues.GetValuesInfos() });
                    }
                    //matchValuesList.Add(matchValues);
                    //matchValues = matchValues.Next();
                    matchValues.Next();
                }
            }

            MatchDate selectedMatchDate = null;

            foreach (MatchDate matchDate in matchDates)
            {
                if (selectedMatchDate == null || zdate.GetDateTypeOrderNumber(matchDate.DateType) <= zdate.GetDateTypeOrderNumber(selectedMatchDate.DateType))
                {
                    selectedMatchDate = matchDate;
                }
            }

            // try to find a digit date corresponding to expectedDate : 20150820 20082015
            if (selectedMatchDate == null && expectedDate != null && _digitDateRegexList != null)
            {
                //string date1 = ((Date)expectedDate).ToString("yyyyMMdd");
                //string date2 = ((Date)expectedDate).ToString("ddMMyyyy");
                //MatchValues matchValues = __sixDigitDate.Match(text);
                //while (matchValues.Success)
                //{
                //    if (matchValues.Match.Value == date1 || matchValues.Match.Value == date2)
                //    {
                //        selectedMatchDate = new MatchDate { Date = (Date)expectedDate, DateType = DateType.Day, Index = -1, MatchValues = matchValues };
                //        break;
                //    }
                //    matchValues = matchValues.Next();
                //}
                foreach (RegexValues rv in _digitDateRegexList.Values)
                {
                    MatchValues matchValues = rv.Match(text);
                    while (matchValues.Success)
                    {
                        Date     date;
                        DateType dateType;
                        //if (zdate.TryCreateDate(matchValues.GetValues(), out date, out dateType) && date == (Date)expectedDate)
                        if (zdate.TryCreateDate(matchValues.GetValues(), out date, out dateType) && IsDateCorrect(date, (Date)expectedDate))
                        {
                            //return new FindDate { Found = true, Date = date, DateType = dateType, matchValues = matchValues, matchValuesList = matchValuesList.Count > 0 ? matchValuesList.ToArray() : null };
                            return(new FindDate {
                                Found = true, Date = date, DateType = dateType, matchValues = matchValues
                            });
                            //return new FindDate { Found = true, Date = date, DateType = dateType, MatchValues = matchValues.GetValuesInfos() };
                        }
                        //matchValues = matchValues.Next();
                        matchValues.Next();
                    }
                }
            }

            if (selectedMatchDate != null)
            {
                //if (selectedMatchDate.Index != -1)
                //    matchValuesList.RemoveAt(selectedMatchDate.Index);
                //return new FindDate { Found = true, Date = selectedMatchDate.Date, DateType = selectedMatchDate.DateType, matchValues = selectedMatchDate.MatchValues, matchValuesList = matchValuesList.Count > 0 ? matchValuesList.ToArray() : null };
                return(new FindDate {
                    Found = true, Date = selectedMatchDate.Date, DateType = selectedMatchDate.DateType, matchValues = selectedMatchDate.MatchValues
                });
                //return new FindDate { Found = true, Date = selectedMatchDate.Date, DateType = selectedMatchDate.DateType, MatchValues = selectedMatchDate.MatchValues };
            }
            else
            {
                //return new FindDate { Found = false, matchValuesList = matchValuesList.Count > 0 ? matchValuesList.ToArray() : null };
                return new FindDate {
                           Found = false
                }
            };
        }