|
1 /* |
|
2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * |
|
16 */ |
|
17 using System; |
|
18 using System.Text; |
|
19 using System.Text.RegularExpressions; |
|
20 using System.Collections.Generic; |
|
21 |
|
22 namespace DExcPlugin.Extractor |
|
23 { |
|
24 internal class DExcExtractorList : IEnumerable<string> |
|
25 { |
|
26 #region Constructors |
|
27 public DExcExtractorList( DExcExtractor.TState aState, DExcExtractorListType aType ) |
|
28 { |
|
29 iType = aType; |
|
30 iState = aState; |
|
31 } |
|
32 #endregion |
|
33 |
|
34 #region API |
|
35 public void AddExpression( DExcExtractorEntry aExpression ) |
|
36 { |
|
37 iEntries.Add( aExpression ); |
|
38 } |
|
39 |
|
40 public void AddExpressions( params DExcExtractorEntry[] aExpressions ) |
|
41 { |
|
42 foreach ( DExcExtractorEntry exp in aExpressions ) |
|
43 { |
|
44 AddExpression( exp ); |
|
45 } |
|
46 } |
|
47 |
|
48 public virtual void Add( string aLine ) |
|
49 { |
|
50 iLines.Add( aLine ); |
|
51 } |
|
52 |
|
53 public virtual bool Offer( string aLine, long aLineNumber, DExcExtractor aInterpreter ) |
|
54 { |
|
55 bool handled = false; |
|
56 // |
|
57 foreach ( DExcExtractorEntry interpreter in iEntries ) |
|
58 { |
|
59 handled = interpreter.Offer( aLine, aLineNumber, this, aInterpreter ); |
|
60 if ( handled ) |
|
61 { |
|
62 break; |
|
63 } |
|
64 } |
|
65 // |
|
66 return handled; |
|
67 } |
|
68 #endregion |
|
69 |
|
70 #region Properties |
|
71 public int Count |
|
72 { |
|
73 get { return iLines.Count; } |
|
74 } |
|
75 |
|
76 public string[] Lines |
|
77 { |
|
78 get { return iLines.ToArray(); } |
|
79 } |
|
80 |
|
81 public DExcExtractorListType Type |
|
82 { |
|
83 get { return iType; } |
|
84 } |
|
85 |
|
86 public DExcExtractor.TState State |
|
87 { |
|
88 get { return iState; } |
|
89 } |
|
90 #endregion |
|
91 |
|
92 #region Internal methods |
|
93 #endregion |
|
94 |
|
95 #region From System.Object |
|
96 public override string ToString() |
|
97 { |
|
98 StringBuilder ret = new StringBuilder(); |
|
99 // |
|
100 foreach ( string line in iLines ) |
|
101 { |
|
102 ret.AppendLine( line ); |
|
103 } |
|
104 // |
|
105 return ret.ToString(); |
|
106 } |
|
107 #endregion |
|
108 |
|
109 #region From IEnumerable<string> |
|
110 public IEnumerator<string> GetEnumerator() |
|
111 { |
|
112 foreach ( string line in iLines ) |
|
113 { |
|
114 yield return line; |
|
115 } |
|
116 } |
|
117 |
|
118 System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() |
|
119 { |
|
120 foreach ( string line in iLines ) |
|
121 { |
|
122 yield return line; |
|
123 } |
|
124 } |
|
125 #endregion |
|
126 |
|
127 #region Data members |
|
128 private readonly DExcExtractorListType iType; |
|
129 private readonly DExcExtractor.TState iState; |
|
130 private List<string> iLines = new List<string>(); |
|
131 private List<DExcExtractorEntry> iEntries = new List<DExcExtractorEntry>(); |
|
132 #endregion |
|
133 } |
|
134 } |