|
1 /* |
|
2 * Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * |
|
5 * Redistribution and use in source and binary forms, with or without |
|
6 * modification, are permitted provided that the following conditions are met: |
|
7 * |
|
8 * - Redistributions of source code must retain the above copyright notice, |
|
9 * this list of conditions and the following disclaimer. |
|
10 * - Redistributions in binary form must reproduce the above copyright notice, |
|
11 * this list of conditions and the following disclaimer in the documentation |
|
12 * and/or other materials provided with the distribution. |
|
13 * - Neither the name of Nokia Corporation nor the names of its contributors |
|
14 * may be used to endorse or promote products derived from this software |
|
15 * without specific prior written permission. |
|
16 * |
|
17 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
|
18 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
|
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
|
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE |
|
21 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
|
22 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
|
23 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
|
24 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
|
25 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
|
26 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
|
27 * POSSIBILITY OF SUCH DAMAGE. |
|
28 * |
|
29 * Initial Contributors: |
|
30 * Nokia Corporation - initial contribution. |
|
31 * |
|
32 * Contributors: |
|
33 * |
|
34 * Description: |
|
35 * |
|
36 */ |
|
37 |
|
38 using System; |
|
39 using System.Collections.Generic; |
|
40 using System.Text; |
|
41 using System.Text.RegularExpressions; |
|
42 using SymbianUtils; |
|
43 |
|
44 namespace HeapComparisonLib.CSV.Thread.Parsers |
|
45 { |
|
46 internal class CSVThreadParserFormatOld |
|
47 { |
|
48 #region Constructors & destructor |
|
49 public CSVThreadParserFormatOld( CSVThreadParser aParser ) |
|
50 { |
|
51 } |
|
52 #endregion |
|
53 |
|
54 #region API |
|
55 public CSVThread ParseLine( string aLine ) |
|
56 { |
|
57 CSVThread ret = null; |
|
58 // |
|
59 Match m = KParserRegEx.Match( aLine ); |
|
60 if ( m.Success ) |
|
61 { |
|
62 ret = CSVThread.New(); |
|
63 // |
|
64 string[] items = m.Value.Split( ',' ); |
|
65 if ( items.Length >= KExpectedItemCount ) |
|
66 { |
|
67 // Ensure each item is trimmed before processing |
|
68 for ( int i = 0; i < items.Length; i++ ) |
|
69 { |
|
70 items[ i ] = items[ i ].Trim(); |
|
71 } |
|
72 |
|
73 try |
|
74 { |
|
75 // THREAD |
|
76 ret.ThreadName = items[ 0 ]; |
|
77 |
|
78 // CHUNK |
|
79 ret.ChunkName = items[ 1 ]; |
|
80 ret.ChunkBaseAddress = ParseHexValue( items[ 2 ] ); |
|
81 |
|
82 // HEAP |
|
83 ret.SizeCurrent = ParseDecimalValue( items[ 3 ] ); |
|
84 ret.SizeMin = ParseDecimalValue( items[ 4 ] ); |
|
85 ret.SizeMax = ParseDecimalValue( items[ 5 ] ); |
|
86 |
|
87 // FIRST FREE CELL |
|
88 ret.FirstFreeCellAddress = ParseHexValue( items[ 6 ] ); |
|
89 ret.FirstFreeCellLength = ParseDecimalValue( items[ 7 ] ); |
|
90 |
|
91 // OTHER FREE CELL INFO |
|
92 ret.FreeCellCount = ParseDecimalValue( items[ 8 ] ); |
|
93 ret.FreeSpaceTotal = ParseDecimalValue( items[ 9 ] ); |
|
94 ret.FreeSpaceSlack = ParseDecimalValue( items[ 10 ] ); |
|
95 ret.FreeCellLargest = ParseDecimalValue( items[ 11 ] ); |
|
96 |
|
97 // ALLOC CELL INFO |
|
98 ret.AllocCellLargest = ParseDecimalValue( items[ 12 ] ); |
|
99 ret.AllocCellCount = ParseDecimalValue( items[ 13 ] ); |
|
100 ret.AllocSpaceTotal = ParseDecimalValue( items[ 15 ] ); |
|
101 |
|
102 // MISC |
|
103 ret.MinCellSize = ParseDecimalValue( items[ 14 ] ); |
|
104 } |
|
105 catch ( Exception ) |
|
106 { |
|
107 ret = null; |
|
108 } |
|
109 } |
|
110 } |
|
111 |
|
112 return ret; |
|
113 } |
|
114 #endregion |
|
115 |
|
116 #region Internal constants |
|
117 private const int KExpectedItemCount = 16; |
|
118 #endregion |
|
119 |
|
120 #region Internal methods |
|
121 private static long ParseHexValue( string aItem ) |
|
122 { |
|
123 long ret = 0; |
|
124 // |
|
125 if ( aItem.Length > 0 ) |
|
126 { |
|
127 const string KHexPrefix = "0x"; |
|
128 if ( aItem.IndexOf( KHexPrefix ) == 0 ) |
|
129 { |
|
130 aItem = aItem.Substring( KHexPrefix.Length ); |
|
131 } |
|
132 |
|
133 ret = System.Convert.ToInt32( aItem, 16 ); |
|
134 } |
|
135 // |
|
136 return ret; |
|
137 } |
|
138 |
|
139 private static long ParseDecimalValue( string aItem ) |
|
140 { |
|
141 long ret = 0; |
|
142 // |
|
143 if ( aItem.Length > 0 ) |
|
144 { |
|
145 ret = System.Convert.ToInt32( aItem ); |
|
146 } |
|
147 // |
|
148 return ret; |
|
149 } |
|
150 #endregion |
|
151 |
|
152 #region Internal regular expression |
|
153 // <summary> |
|
154 // Regular expression built for C# on: Tue, Sep 9, 2008, 02:09:20 PM |
|
155 // Using Expresso Version: 3.0.2766, http://www.ultrapico.com |
|
156 // |
|
157 // A description of the regular expression: |
|
158 // |
|
159 // [Thread]: A named capture group. [(?:[A-Za-z0-9!_$ ]+)\:\:(?:[A-Za-z0-9!_$: ]+)] |
|
160 // (?:[A-Za-z0-9!_$ ]+)\:\:(?:[A-Za-z0-9!_$: ]+) |
|
161 // Match expression but don't capture it. [[A-Za-z0-9!_$ ]+] |
|
162 // Any character in this class: [A-Za-z0-9!_$ ], one or more repetitions |
|
163 // Literal : |
|
164 // Literal : |
|
165 // Match expression but don't capture it. [[A-Za-z0-9!_$: ]+] |
|
166 // Any character in this class: [A-Za-z0-9!_$: ], one or more repetitions |
|
167 // Literal , |
|
168 // [Chunk]: A named capture group. [[A-Za-z0-9!_$ \[\]:.]+] |
|
169 // Any character in this class: [A-Za-z0-9!_$ \[\]:.], one or more repetitions |
|
170 // Match expression but don't capture it. [ \, (?<Items> [A-Za-z0-9!_$ \[\]:.] +)], exactly 14 repetitions |
|
171 // \, (?<Items> [A-Za-z0-9!_$ \[\]:.] +) |
|
172 // Literal , |
|
173 // [Items]: A named capture group. [ [A-Za-z0-9!_$ \[\]:.] +] |
|
174 // Any character in this class: [A-Za-z0-9!_$ \[\]:.], one or more repetitions |
|
175 // |
|
176 // |
|
177 // </summary> |
|
178 private static readonly Regex KParserRegEx = new Regex( |
|
179 "(?<Thread>(?:[A-Za-z0-9!_$ ]+)\\:\\:(?:[A-Za-z0-9!_$: ]+))\r\n"+ |
|
180 "\\,\r\n(?<Chunk>[A-Za-z0-9!_$ \\[\\]:.]+)\r\n(?:\r\n \\,\r\n (?<"+ |
|
181 "Items>\r\n [A-Za-z0-9!_$ \\[\\]:.]\r\n +)\r\n){14}", |
|
182 RegexOptions.Singleline |
|
183 | RegexOptions.CultureInvariant |
|
184 | RegexOptions.IgnorePatternWhitespace |
|
185 | RegexOptions.Compiled |
|
186 ); |
|
187 #endregion |
|
188 |
|
189 #region Data members |
|
190 #endregion |
|
191 } |
|
192 } |