|
1 // Copyright (c) 2001-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
2 // All rights reserved. |
|
3 // This component and the accompanying materials are made available |
|
4 // under the terms of "Eclipse Public License v1.0" |
|
5 // which accompanies this distribution, and is available |
|
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // |
|
15 |
|
16 |
|
17 #include "CHtmlToCrtConvHashTable.h" |
|
18 #include "CHtmlToCrtConvHash.h" |
|
19 #include "CHtmlToCrtConvLookupTable.h" |
|
20 #include "CHtmlToCrtConvAssertDefines.h" |
|
21 |
|
22 const TInt KTagHashTableNumberOfEntries = sizeof(KTagHashTable)/sizeof(TTagHashTableEntry); |
|
23 const TInt KAttributeHashTableNumberOfEntries = sizeof(KAttributeHashTable)/sizeof(TAttributeHashTableEntry); |
|
24 |
|
25 CHtmlToCrtConvHashTable::CHtmlToCrtConvHashTable() |
|
26 { |
|
27 } |
|
28 |
|
29 CHtmlToCrtConvHashTable* CHtmlToCrtConvHashTable::NewL() |
|
30 { |
|
31 CHtmlToCrtConvHashTable* self=new(ELeave) CHtmlToCrtConvHashTable(); |
|
32 CleanupStack::PushL(self); |
|
33 self->ConstructL(); |
|
34 CleanupStack::Pop(self); |
|
35 return self; |
|
36 } |
|
37 |
|
38 void CHtmlToCrtConvHashTable::ConstructL() |
|
39 { |
|
40 CreateTagHashTableL(); |
|
41 CreateAttributeHashTableL(); |
|
42 } |
|
43 |
|
44 CHtmlToCrtConvHashTable::~CHtmlToCrtConvHashTable() |
|
45 { |
|
46 iTagHashValues.Close(); |
|
47 iAttributeHashValues.Close(); |
|
48 } |
|
49 |
|
50 void CHtmlToCrtConvHashTable::CreateTagHashTableL() |
|
51 { |
|
52 const TTagHashTableEntry* item=&KTagHashTable[0]; |
|
53 TPtrC16 text; |
|
54 |
|
55 for(TInt ii=0; ii<KTagHashTableNumberOfEntries; ii++) |
|
56 { |
|
57 text.Set(item->iText); |
|
58 iTagHashValues.Append(Hash(text)); |
|
59 item++; |
|
60 } |
|
61 iTagHashValues.Compress(); |
|
62 } |
|
63 |
|
64 void CHtmlToCrtConvHashTable::CreateAttributeHashTableL() |
|
65 { |
|
66 const TAttributeHashTableEntry* item=&KAttributeHashTable[0]; |
|
67 TPtrC16 text; |
|
68 |
|
69 for(TInt ii=0; ii<KAttributeHashTableNumberOfEntries; ii++) |
|
70 { |
|
71 text.Set(item->iText); |
|
72 iAttributeHashValues.Append(Hash(text)); |
|
73 item++; |
|
74 } |
|
75 iAttributeHashValues.Compress(); |
|
76 } |
|
77 |
|
78 THtmlToCrtConvTagType CHtmlToCrtConvHashTable::LookupTag(const TDesC16& aTag) const |
|
79 { |
|
80 TInt hashValue=Hash(aTag); |
|
81 TInt length=aTag.Length(); |
|
82 const TInt count=iTagHashValues.Count(); |
|
83 |
|
84 for(TInt ii=0; ii<count; ii++) |
|
85 { |
|
86 const TTagHashTableEntry* item=&KTagHashTable[ii]; |
|
87 |
|
88 if ((iTagHashValues)[ii]==hashValue) |
|
89 { |
|
90 TPtrC16 text=TPtrC16(item->iText); |
|
91 if (text.Length()==length) |
|
92 { |
|
93 if (aTag.CompareF(text)==0) |
|
94 { |
|
95 return item->iTagType; |
|
96 } |
|
97 } |
|
98 } |
|
99 } |
|
100 return EHtmlTagUnknown; |
|
101 } |
|
102 |
|
103 const TDesC16& CHtmlToCrtConvHashTable::LookupEntity(const TDesC16& aEntityName) const |
|
104 { |
|
105 TChar firstChar(aEntityName.Ptr()[0]); |
|
106 firstChar=firstChar.GetUpperCase(); |
|
107 switch (firstChar) |
|
108 { |
|
109 case 'L': |
|
110 if (!aEntityName.CompareF(KHtmlLt)) |
|
111 return KHtmlEntityLt; |
|
112 break; |
|
113 case 'G': |
|
114 if (!aEntityName.CompareF(KHtmlGt)) |
|
115 return KHtmlEntityGt; |
|
116 break; |
|
117 case 'N': |
|
118 if (!aEntityName.CompareF(KHtmlNbsp)) |
|
119 return KHtmlEntitySpace; |
|
120 break; |
|
121 } |
|
122 |
|
123 return KHtmlEntityUnknown; |
|
124 } |
|
125 |
|
126 THtmlToCrtConvAttributeType CHtmlToCrtConvHashTable::LookupAttribute(const TDesC16& aAttribute) const |
|
127 { |
|
128 TInt hashValue=Hash(aAttribute); |
|
129 TInt length=aAttribute.Length(); |
|
130 const TInt count=iAttributeHashValues.Count(); |
|
131 |
|
132 for(TInt ii=0; ii<count; ii++) |
|
133 { |
|
134 const TAttributeHashTableEntry* item=&KAttributeHashTable[ii]; |
|
135 |
|
136 if ((iAttributeHashValues)[ii]==hashValue) |
|
137 { |
|
138 TPtrC16 text=TPtrC16(item->iText); |
|
139 if (text.Length()==length) |
|
140 { |
|
141 if (aAttribute.CompareF(text)==0) |
|
142 { |
|
143 return item->iAttributeType; |
|
144 } |
|
145 } |
|
146 } |
|
147 } |
|
148 return EHtmlAttributeUnknown; |
|
149 } |
|
150 |
|
151 TInt CHtmlToCrtConvHashTable::Hash(const TDesC16& aText) const |
|
152 { |
|
153 TInt hashValue=0; |
|
154 const TInt length=aText.Length(); |
|
155 |
|
156 for(TInt ii=0; ii<length; ii++) |
|
157 { |
|
158 TCharUC temp(aText[ii]); |
|
159 hashValue += temp; |
|
160 } |
|
161 return hashValue; |
|
162 } |