Represents a regular expression for a placeholder, given a supplied prefix
Ejemplo n.º 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>()));
 }
Ejemplo n.º 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)));
 }
Ejemplo n.º 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());
 }
Ejemplo n.º 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));
 }
Ejemplo n.º 5
0
 public static IEnumerable <TemplMatchSection> Find(TemplRegex rxp, Section sec)
 {
     return(Find <TemplMatchSection>(rxp, sec.SectionParagraphs).Select(m =>
     {
         m.Section = sec;
         return m;
     }));
 }
Ejemplo n.º 6
0
 public static IEnumerable<TemplMatchSection> Find(TemplRegex rxp, Section sec) 
 {
     return Find<TemplMatchSection>(rxp, sec.SectionParagraphs).Select(m =>
     {
         m.Section = sec;
         return m;
     });
 }
Ejemplo n.º 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,
     }));
 }
Ejemplo n.º 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;
     }));
 }
Ejemplo n.º 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;
     }));
 }
Ejemplo n.º 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));
 }
Ejemplo n.º 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;
            }));
        }
Ejemplo n.º 12
0
 public static IEnumerable <TemplMatchHyperlink> Find(TemplRegex rxp, IEnumerable <Paragraph> paragraphs)
 {
     return(paragraphs.SelectMany(p => Find(rxp, p)));
 }
Ejemplo n.º 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));
 }
Ejemplo n.º 14
0
 public static IEnumerable<TemplMatchText> Find(TemplRegex rxp, Paragraph p) 
 {
     return Find<TemplMatchText>(rxp, p);
 }
Ejemplo n.º 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)));
 }
Ejemplo n.º 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)));
 }
Ejemplo n.º 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));
 }
Ejemplo n.º 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)));
 }
Ejemplo n.º 19
0
 public override IEnumerable <TemplMatchText> FindAll(DocX doc, TemplRegex rxp)
 {
     return(TemplMatchText.Find(rxp, TemplDoc.Paragraphs(doc)));
 }
Ejemplo n.º 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));
 }
Ejemplo n.º 21
0
 public static IEnumerable<TemplMatchString> Find(TemplRegex rxp, string s)
 {
     return Find<TemplMatchString>(rxp, s);
 }
Ejemplo n.º 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);
 }
Ejemplo n.º 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);
 }
Ejemplo n.º 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));
 }
Ejemplo n.º 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)));
 }
Ejemplo n.º 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)));
 }
Ejemplo n.º 27
0
 public static IEnumerable <TemplMatchString> Find(TemplRegex rxp, string s)
 {
     return(Find <TemplMatchString>(rxp, s));
 }
Ejemplo n.º 28
0
 public static IEnumerable<TemplMatchHyperlink> Find(TemplRegex rxp, IEnumerable<Paragraph> paragraphs) 
 {
     return paragraphs.SelectMany(p => Find(rxp, p));
 }
Ejemplo n.º 29
0
 public override IEnumerable <TemplMatchSection> FindAll(DocX doc, TemplRegex rxp)
 {
     // Expecting only 1 match per section
     return(TemplMatchSection.Find(rxp, doc.GetSections(), 1));
 }
Ejemplo n.º 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));
 }
Ejemplo n.º 31
0
 public override IEnumerable <TemplMatchTable> FindAll(DocX doc, TemplRegex rxp)
 {
     return(TemplMatchTable.Find(rxp, doc.Tables));
 }
Ejemplo n.º 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;
     });
 }
Ejemplo n.º 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));
 }
Ejemplo n.º 34
0
 public static IEnumerable <TemplMatchText> Find(TemplRegex rxp, Paragraph p)
 {
     return(Find <TemplMatchText>(rxp, p));
 }
Ejemplo n.º 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;
     });
 }
Ejemplo n.º 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));
 }