Represents a regular expression for a placeholder, given a supplied prefix
Beispiel #1
0
 public override IEnumerable <TemplMatchText> FindAll(DocX doc, TemplRegex rxp)
 {
     // Get both text and picture matches. Concat is possible due to the shared base type (MatchText)
     return(TemplMatchText.Find(rxp, Paragraphs)
            .Concat(TemplMatchPicture.Find(rxp, Paragraphs).Cast <TemplMatchText>())
            .Concat(TemplMatchHyperlink.Find(rxp, Paragraphs).Cast <TemplMatchText>()));
 }
Beispiel #2
0
 public static IEnumerable <TemplMatchTable> Find(TemplRegex rxp, IEnumerable <Table> tables,
                                                  uint maxPerTable = TemplConst.MaxMatchesPerScope,
                                                  uint maxPerRow   = TemplConst.MaxMatchesPerScope,
                                                  uint maxPerCell  = TemplConst.MaxMatchesPerScope)
 {
     return(tables.SelectMany(t => Find(rxp, t, maxPerTable, maxPerRow, maxPerCell)));
 }
Beispiel #3
0
 public override IEnumerable <TemplMatchTable> FindAll(DocX doc, TemplRegex rxp)
 {
     // Expecting only 1 match per row (yes really, per row)
     // Reverse(): If the handler inserts extra rows, we do not want to mess up the indexes of rows above this match.
     //            Processing  bottom-up avoids this issue.
     return(TemplMatchTable.Find(rxp, doc.Tables, maxPerRow: 1).Reverse());
 }
Beispiel #4
0
 public static IEnumerable <TemplMatchTable> Find(TemplRegex rxp, Table t,
                                                  uint maxPerTable = TemplConst.MaxMatchesPerScope,
                                                  uint maxPerRow   = TemplConst.MaxMatchesPerScope,
                                                  uint maxPerCell  = TemplConst.MaxMatchesPerScope)
 {
     return(Enumerable.Range(0, t.RowCount).SelectMany(rowIdx => Find(rxp, t, rowIdx, maxPerRow, maxPerCell)).Take((int)maxPerTable));
 }
Beispiel #5
0
 public static IEnumerable <TemplMatchSection> Find(TemplRegex rxp, Section sec)
 {
     return(Find <TemplMatchSection>(rxp, sec.SectionParagraphs).Select(m =>
     {
         m.Section = sec;
         return m;
     }));
 }
Beispiel #6
0
 public static IEnumerable<TemplMatchSection> Find(TemplRegex rxp, Section sec) 
 {
     return Find<TemplMatchSection>(rxp, sec.SectionParagraphs).Select(m =>
     {
         m.Section = sec;
         return m;
     });
 }
Beispiel #7
0
 /// <summary>
 /// Find matches in a string, based on a Regex placeholder pattern.
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <param name="rgx"></param>
 /// <param name="s"></param>
 public static IEnumerable <T> Find <T>(TemplRegex rgx, string s) where T : TemplMatch, new()
 {
     return(rgx.Pattern.Matches(s).Cast <Match>().Where(m => m.Success).Select(m => new T()
     {
         Regex = rgx,
         Body = m.Groups[1].Value,
     }));
 }
Beispiel #8
0
 private static IEnumerable <TemplMatchHyperlink> Find(TemplRegex rxp, Paragraph p, Hyperlink hl)
 {
     return(Find <TemplMatchHyperlink>(rxp, UrlString(hl)).Select(m => {
         m.Hyperlink = hl;
         m.Paragraph = p;
         return m;
     }));
 }
Beispiel #9
0
 private static IEnumerable <TemplMatchPicture> Find(TemplRegex rxp, Paragraph p, Picture pic)
 {
     return(Find <TemplMatchPicture>(rxp, pic.Description).Select(m => {
         m.Picture = pic;
         m.Width = pic.Width;
         m.Paragraph = p;
         return m;
     }));
 }
Beispiel #10
0
 public static IEnumerable <TemplMatchTable> Find(TemplRegex rxp, Table t, int rowIdx, int cellIdx,
                                                  uint maxPerCell = TemplConst.MaxMatchesPerScope)
 {
     return(Find <TemplMatchTable>(rxp, t.Rows[rowIdx].Cells[cellIdx].Paragraphs).Select(m =>
     {
         m.Table = t;
         m.RowIndex = rowIdx;
         m.CellIndex = cellIdx;
         return m;
     }).Take((int)maxPerCell));
 }
Beispiel #11
0
        /// <summary>
        /// Find matches in a paragraph, based on a Regex placeholder pattern.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="rgx"></param>
        /// <param name="p"></param>
        public static IEnumerable <T> Find <T>(TemplRegex rgx, Paragraph p) where T : TemplMatchPara, new()
        {
            var P = p;
            var t = P.Text;

            return(Find <T>(rgx, p.Text).Select(m =>
            {
                m.Paragraph = p;
                return m;
            }));
        }
Beispiel #12
0
 public static IEnumerable <TemplMatchHyperlink> Find(TemplRegex rxp, IEnumerable <Paragraph> paragraphs)
 {
     return(paragraphs.SelectMany(p => Find(rxp, p)));
 }
Beispiel #13
0
 public static IEnumerable<TemplMatchSection> Find(TemplRegex rxp, IEnumerable<Section> sections, 
     uint maxPerSection = TemplConst.MaxMatchesPerScope) 
 {
     return sections.SelectMany(sec => Find(rxp, sec).Take((int)maxPerSection));
 }
Beispiel #14
0
 public static IEnumerable<TemplMatchText> Find(TemplRegex rxp, Paragraph p) 
 {
     return Find<TemplMatchText>(rxp, p);
 }
Beispiel #15
0
 public static IEnumerable <TemplMatchSection> Find(TemplRegex rxp, IEnumerable <Section> sections,
                                                    uint maxPerSection = TemplConst.MaxMatchesPerScope)
 {
     return(sections.SelectMany(sec => Find(rxp, sec).Take((int)maxPerSection)));
 }
Beispiel #16
0
 public static new IEnumerable <TemplMatchPicture> Find(TemplRegex rxp, Paragraph p)
 {
     return(p.Pictures
            .Where(pic => pic.Description != null)
            .SelectMany(pic => Find(rxp, p, pic)));
 }
Beispiel #17
0
 public override IEnumerable <TemplMatchTable> FindAll(DocX doc, TemplRegex rxp)
 {
     // Expecting only 1 match per table
     return(TemplMatchTable.Find(rxp, doc.Tables, maxPerTable: 1));
 }
Beispiel #18
0
 public static IEnumerable <TemplMatchText> Find(TemplRegex rxp, IEnumerable <Paragraph> paragraphs,
                                                 uint maxPerParagraph = TemplConst.MaxMatchesPerScope)
 {
     return(paragraphs.SelectMany(p => Find(rxp, p).Take((int)maxPerParagraph)));
 }
Beispiel #19
0
 public override IEnumerable <TemplMatchText> FindAll(DocX doc, TemplRegex rxp)
 {
     return(TemplMatchText.Find(rxp, TemplDoc.Paragraphs(doc)));
 }
Beispiel #20
0
 public static new IEnumerable<TemplMatchPicture> Find(TemplRegex rxp, Paragraph p) 
 {
     return p.Pictures
         .Where(     pic => pic.Description != null)
         .SelectMany(pic => Find(rxp, p, pic));
 }
Beispiel #21
0
 public static IEnumerable<TemplMatchString> Find(TemplRegex rxp, string s)
 {
     return Find<TemplMatchString>(rxp, s);
 }
Beispiel #22
0
 public static IEnumerable<TemplMatchTable> Find(TemplRegex rxp, Table t, int rowIdx, int cellIdx,
     uint maxPerCell = TemplConst.MaxMatchesPerScope)
 {
     return Find<TemplMatchTable>(rxp, t.Rows[rowIdx].Cells[cellIdx].Paragraphs).Select(m =>
     {
         m.Table = t;
         m.RowIndex = rowIdx;
         m.CellIndex = cellIdx;
         return m;
     }).Take((int)maxPerCell);
 }
Beispiel #23
0
 public static IEnumerable<TemplMatchTable> Find(TemplRegex rxp, Table t, int rowIdx,
     uint maxPerRow = TemplConst.MaxMatchesPerScope,
     uint maxPerCell = TemplConst.MaxMatchesPerScope)
 {
     return Enumerable.Range(0,t.Rows[rowIdx].Cells.Count).SelectMany(cellIdx => Find(rxp, t, rowIdx, cellIdx, maxPerCell)).Take((int)maxPerRow);
 }
Beispiel #24
0
 public static IEnumerable<TemplMatchTable> Find(TemplRegex rxp, IEnumerable<Table> tables, 
     uint maxPerTable = TemplConst.MaxMatchesPerScope,
     uint maxPerRow = TemplConst.MaxMatchesPerScope,
     uint maxPerCell = TemplConst.MaxMatchesPerScope)
 {
     return tables.SelectMany(t => Find(rxp, t, maxPerTable, maxPerRow, maxPerCell));
 }
Beispiel #25
0
 public static new IEnumerable <TemplMatchHyperlink> Find(TemplRegex rxp, Paragraph p)
 {
     return(p.Hyperlinks
            .Where(hl => UrlString(hl).Length > 0)
            .SelectMany(hl => Find(rxp, p, hl)));
 }
Beispiel #26
0
 /// <summary>
 /// Find matches in paragraphs, based on a Regex placeholder pattern. Limit n per paragraph
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <param name="rgx"></param>
 /// <param name="paragraphs"></param>
 /// <param name="n"></param>
 public static IEnumerable <T> Find <T>(TemplRegex rgx, IEnumerable <Paragraph> paragraphs, int n) where T : TemplMatchPara, new()
 {
     return(paragraphs.SelectMany(p => Find <T>(rgx, p).Take(n)));
 }
Beispiel #27
0
 public static IEnumerable <TemplMatchString> Find(TemplRegex rxp, string s)
 {
     return(Find <TemplMatchString>(rxp, s));
 }
Beispiel #28
0
 public static IEnumerable<TemplMatchHyperlink> Find(TemplRegex rxp, IEnumerable<Paragraph> paragraphs) 
 {
     return paragraphs.SelectMany(p => Find(rxp, p));
 }
Beispiel #29
0
 public override IEnumerable <TemplMatchSection> FindAll(DocX doc, TemplRegex rxp)
 {
     // Expecting only 1 match per section
     return(TemplMatchSection.Find(rxp, doc.GetSections(), 1));
 }
Beispiel #30
0
 public static new IEnumerable<TemplMatchHyperlink> Find(TemplRegex rxp, Paragraph p) 
 {
     return p.Hyperlinks
         .Where(     hl => UrlString(hl).Length > 0)
         .SelectMany(hl => Find(rxp, p, hl));
 }
Beispiel #31
0
 public override IEnumerable <TemplMatchTable> FindAll(DocX doc, TemplRegex rxp)
 {
     return(TemplMatchTable.Find(rxp, doc.Tables));
 }
Beispiel #32
0
 private static IEnumerable<TemplMatchHyperlink> Find(TemplRegex rxp, Paragraph p, Hyperlink hl) 
 {
     return Find<TemplMatchHyperlink>(rxp, UrlString(hl)).Select(m => {
         m.Hyperlink= hl;
         m.Paragraph = p;
         return m;
     });
 }
Beispiel #33
0
 public override IEnumerable <TemplMatchText> FindAll(DocX doc, TemplRegex rxp)
 {
     // Expecting only 1 match per paragraph
     return(TemplMatchText.Find(rxp, TemplDoc.Paragraphs(doc), 1));
 }
Beispiel #34
0
 public static IEnumerable <TemplMatchText> Find(TemplRegex rxp, Paragraph p)
 {
     return(Find <TemplMatchText>(rxp, p));
 }
Beispiel #35
0
 private static IEnumerable<TemplMatchPicture> Find(TemplRegex rxp, Paragraph p, Picture pic) 
 {
     return Find<TemplMatchPicture>(rxp, pic.Description).Select(m => {
         m.Picture = pic;
         m.Width = pic.Width;
         m.Paragraph = p;
         return m;
     });
 }
Beispiel #36
0
 public static IEnumerable<TemplMatchText> Find(TemplRegex rxp, IEnumerable<Paragraph> paragraphs, 
     uint maxPerParagraph = TemplConst.MaxMatchesPerScope) 
 {
     return paragraphs.SelectMany(p => Find(rxp, p).Take((int)maxPerParagraph));
 }