|
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.Collections; |
|
20 using System.Collections.Generic; |
|
21 |
|
22 namespace SymbianUtils.RawItems |
|
23 { |
|
24 public class RawItemCollection : IEnumerable<RawItem> |
|
25 { |
|
26 #region Constructors |
|
27 public RawItemCollection() |
|
28 { |
|
29 } |
|
30 #endregion |
|
31 |
|
32 #region API |
|
33 public void Clear() |
|
34 { |
|
35 iRawItems.Clear(); |
|
36 } |
|
37 |
|
38 public void Add( RawItem aItem ) |
|
39 { |
|
40 iRawItems.Add( aItem ); |
|
41 } |
|
42 |
|
43 public int CountPadding( byte aPaddingByte ) |
|
44 { |
|
45 int ret = 0; |
|
46 bool finished = false; |
|
47 // |
|
48 for ( int i = Count - 1; !finished && i >= 0; i-- ) |
|
49 { |
|
50 RawItem item = this[ i ]; |
|
51 long dataValue = item.OriginalData; |
|
52 // |
|
53 for ( int j = 0; j < 4; j++ ) |
|
54 { |
|
55 long mask = 0x000000FFL << ( j * 8 ); |
|
56 long value = ( mask & dataValue ); |
|
57 int shiftBy = ( j * 8 ); |
|
58 long valueClean = value >> shiftBy; |
|
59 if ( valueClean == aPaddingByte ) |
|
60 { |
|
61 ++ret; |
|
62 } |
|
63 else |
|
64 { |
|
65 finished = true; |
|
66 break; |
|
67 } |
|
68 } |
|
69 } |
|
70 // |
|
71 return ret; |
|
72 } |
|
73 |
|
74 public int PrintableCharacterCount( bool aUnicode, bool aIncludeFirstItem, out int aDotCount ) |
|
75 { |
|
76 aDotCount = 0; |
|
77 int i = ( aIncludeFirstItem ) ? 0 : 1; |
|
78 // |
|
79 int ret = 0; |
|
80 for ( ; i < iRawItems.Count; i++ ) |
|
81 { |
|
82 RawItem item = iRawItems[ i ]; |
|
83 ret += item.PrintableCharacterCount( aUnicode, ref aDotCount ); |
|
84 } |
|
85 // |
|
86 return ret; |
|
87 } |
|
88 |
|
89 public int PrintableCharacterCount( bool aUnicode, out int aDotCount ) |
|
90 { |
|
91 int ret = 0; |
|
92 aDotCount = 0; |
|
93 // |
|
94 foreach ( RawItem item in iRawItems ) |
|
95 { |
|
96 ret += item.PrintableCharacterCount( aUnicode, ref aDotCount ); |
|
97 } |
|
98 // |
|
99 return ret; |
|
100 } |
|
101 #endregion |
|
102 |
|
103 #region Properties |
|
104 public string FirstLine |
|
105 { |
|
106 get |
|
107 { |
|
108 StringBuilder ret = new StringBuilder(); |
|
109 // |
|
110 int count = Count; |
|
111 for ( int i = 0; i < 8; i += 8 ) |
|
112 { |
|
113 for ( int j = 0; j < 8 && i + j < count; j++ ) |
|
114 { |
|
115 RawItem item = this[ i + j ]; |
|
116 ret.Append( item.OriginalCharacterisedData ); |
|
117 } |
|
118 } |
|
119 // |
|
120 return ret.ToString(); |
|
121 } |
|
122 } |
|
123 |
|
124 public int Count |
|
125 { |
|
126 get { return iRawItems.Count; } |
|
127 } |
|
128 |
|
129 public RawItem this[ int aIndex ] |
|
130 { |
|
131 get |
|
132 { |
|
133 RawItem ret = iRawItems[ aIndex ]; |
|
134 return ret; |
|
135 } |
|
136 } |
|
137 #endregion |
|
138 |
|
139 #region IEnumerable Members |
|
140 IEnumerator IEnumerable.GetEnumerator() |
|
141 { |
|
142 return new RawItemCollectionEnumerator( this ); |
|
143 } |
|
144 |
|
145 IEnumerator<RawItem> IEnumerable<RawItem>.GetEnumerator() |
|
146 { |
|
147 return new RawItemCollectionEnumerator( this ); |
|
148 } |
|
149 #endregion |
|
150 |
|
151 #region From System.Object |
|
152 public override string ToString() |
|
153 { |
|
154 StringBuilder ret = new StringBuilder(); |
|
155 // |
|
156 int count = Count; |
|
157 for ( int i = 0; i < count; i += 8 ) |
|
158 { |
|
159 for ( int j = 0; j < 8 && i + j < count; j++ ) |
|
160 { |
|
161 RawItem item = this[ i + j ]; |
|
162 ret.Append( item.OriginalCharacterisedData ); |
|
163 } |
|
164 ret.Append( System.Environment.NewLine ); |
|
165 } |
|
166 // |
|
167 return ret.ToString(); |
|
168 } |
|
169 #endregion |
|
170 |
|
171 #region Data members |
|
172 private List<RawItem> iRawItems = new List<RawItem>(); |
|
173 #endregion |
|
174 } |
|
175 } |