|
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.IO; |
|
19 using System.Text; |
|
20 |
|
21 namespace SymbianUtils |
|
22 { |
|
23 public class TracePrefixAnalyser |
|
24 { |
|
25 #region Constructors |
|
26 public TracePrefixAnalyser() |
|
27 { |
|
28 } |
|
29 #endregion |
|
30 |
|
31 #region API |
|
32 public bool CleanLine( ref string aLine ) |
|
33 { |
|
34 bool matched = false; |
|
35 string prefix = IdentifyTracePrefixFromLine( aLine ); |
|
36 // |
|
37 if ( prefix.Length > 0 ) |
|
38 { |
|
39 int prefixPos = aLine.IndexOf( prefix ); |
|
40 aLine = aLine.Substring( prefixPos + prefix.Length ); |
|
41 matched = true; |
|
42 } |
|
43 // |
|
44 return matched; |
|
45 } |
|
46 |
|
47 public StringBuilder CleanFile( string aFileName ) |
|
48 { |
|
49 StringBuilder lines = new StringBuilder(); |
|
50 // |
|
51 using( StreamReader reader = new StreamReader( aFileName ) ) |
|
52 { |
|
53 string line = reader.ReadLine(); |
|
54 while( line != null ) |
|
55 { |
|
56 CleanLine( ref line ); |
|
57 lines.Append( line + System.Environment.NewLine ); |
|
58 // |
|
59 line = reader.ReadLine(); |
|
60 } |
|
61 } |
|
62 // |
|
63 return lines; |
|
64 } |
|
65 |
|
66 public string IdentifyTracePrefixFromLine( string aLine ) |
|
67 { |
|
68 string prefix = string.Empty; |
|
69 // |
|
70 if ( aLine.IndexOf( KFinalPrefix ) >= 0 ) |
|
71 { |
|
72 prefix = KFinalPrefix; |
|
73 } |
|
74 // |
|
75 return prefix; |
|
76 } |
|
77 |
|
78 public string IdentifyTracePrefix( string aFileName ) |
|
79 { |
|
80 string prefix = string.Empty; |
|
81 // |
|
82 try |
|
83 { |
|
84 using( StreamReader reader = new StreamReader( aFileName ) ) |
|
85 { |
|
86 int lineCounter = 0; |
|
87 string line = string.Empty; |
|
88 // |
|
89 while( lineCounter < KNumberOfLinesToCheck && line != null ) |
|
90 { |
|
91 try |
|
92 { |
|
93 line = reader.ReadLine(); |
|
94 // |
|
95 if ( line != null ) |
|
96 { |
|
97 string tmp = IdentifyTracePrefixFromLine( line ); |
|
98 if ( tmp.Length > 0 ) |
|
99 { |
|
100 prefix = tmp; |
|
101 break; |
|
102 } |
|
103 } |
|
104 } |
|
105 catch(Exception) |
|
106 { |
|
107 line = null; |
|
108 } |
|
109 // |
|
110 ++lineCounter; |
|
111 } |
|
112 } |
|
113 } |
|
114 catch( Exception ) |
|
115 { |
|
116 } |
|
117 // |
|
118 return prefix; |
|
119 } |
|
120 #endregion |
|
121 |
|
122 #region Internal constants |
|
123 private const int KNumberOfLinesToCheck = 500; |
|
124 #endregion |
|
125 |
|
126 #region Data members |
|
127 private const int KLineLookAheadCount = 200; |
|
128 private const string KFinalPrefix = "msg:"; |
|
129 #endregion |
|
130 } |
|
131 } |