|
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 DExcExtractorEntry |
|
25 { |
|
26 #region Constructors |
|
27 public static DExcExtractorEntry NewMatchAndSave( Regex aExpression ) |
|
28 { |
|
29 DExcExtractorEntry ret = new DExcExtractorEntry( aExpression ); |
|
30 return ret; |
|
31 } |
|
32 |
|
33 public static DExcExtractorEntry NewMatchAndTransition( Regex aExpression, DExcExtractor.TState aNewState ) |
|
34 { |
|
35 DExcExtractorEntry ret = new DExcExtractorEntry( aExpression, TType.ETypeMatchAndTransition, aNewState ); |
|
36 return ret; |
|
37 } |
|
38 |
|
39 public static DExcExtractorEntry NewMatchSaveAndTransition( Regex aExpression, DExcExtractor.TState aNewState ) |
|
40 { |
|
41 DExcExtractorEntry ret = new DExcExtractorEntry( aExpression, TType.ETypeMatchSaveAndTransition, aNewState ); |
|
42 return ret; |
|
43 } |
|
44 #endregion |
|
45 |
|
46 #region Internal constructors |
|
47 private DExcExtractorEntry( Regex aExpression ) |
|
48 : this( aExpression, TType.ETypeMatchAndSave, DExcExtractor.TState.EStateIdle ) |
|
49 { |
|
50 } |
|
51 |
|
52 private DExcExtractorEntry( Regex aExpression, TType aType, DExcExtractor.TState aNewState ) |
|
53 { |
|
54 iType = aType; |
|
55 iNewState = aNewState; |
|
56 iExpression = aExpression; |
|
57 } |
|
58 #endregion |
|
59 |
|
60 #region API |
|
61 public bool Offer( string aLine, long aLineNumber, DExcExtractorList aList, DExcExtractor aInterpreter ) |
|
62 { |
|
63 Match m = iExpression.Match( aLine ); |
|
64 // |
|
65 if ( m.Success ) |
|
66 { |
|
67 if ( Type == TType.ETypeMatchAndTransition || Type == TType.ETypeMatchSaveAndTransition ) |
|
68 { |
|
69 aInterpreter.State = iNewState; |
|
70 } |
|
71 if ( Type == TType.ETypeMatchAndSave ) |
|
72 { |
|
73 aList.Add( m.Value ); |
|
74 } |
|
75 else if ( Type == TType.ETypeMatchSaveAndTransition ) |
|
76 { |
|
77 // We have just transitioned state and we must add the line |
|
78 // to the new state's list |
|
79 if ( aInterpreter.CurrentList != null ) |
|
80 { |
|
81 aInterpreter.CurrentList.Add( m.Value ); |
|
82 } |
|
83 } |
|
84 } |
|
85 // |
|
86 return m.Success; |
|
87 } |
|
88 #endregion |
|
89 |
|
90 #region Properties |
|
91 private TType Type |
|
92 { |
|
93 get { return iType; } |
|
94 } |
|
95 #endregion |
|
96 |
|
97 #region Internal enumerations |
|
98 private enum TType |
|
99 { |
|
100 ETypeMatchAndSave, |
|
101 ETypeMatchAndTransition, |
|
102 ETypeMatchSaveAndTransition |
|
103 } |
|
104 #endregion |
|
105 |
|
106 #region From System.Object |
|
107 public override string ToString() |
|
108 { |
|
109 return iExpression.ToString(); |
|
110 } |
|
111 #endregion |
|
112 |
|
113 #region Data members |
|
114 private readonly TType iType; |
|
115 private readonly Regex iExpression; |
|
116 private readonly DExcExtractor.TState iNewState; |
|
117 #endregion |
|
118 } |
|
119 } |