66 } |
66 } |
67 |
67 |
68 |
68 |
69 EXPORT_C void PodcastUtils::CleanHtmlL(TDes &str) |
69 EXPORT_C void PodcastUtils::CleanHtmlL(TDes &str) |
70 { |
70 { |
71 #ifdef UIQ |
71 // miscellaneous cleanup |
72 _LIT(KLineBreak, "\r\n"); |
|
73 #else |
|
74 const TChar KLineBreak(CEditableText::ELineBreak); |
72 const TChar KLineBreak(CEditableText::ELineBreak); |
75 #endif |
|
76 _LIT(KNewLine, "\n"); |
73 _LIT(KNewLine, "\n"); |
|
74 // ReplaceChar(str, '"', '\''); |
77 ReplaceString(str, KNewLine, KNullDesC); |
75 ReplaceString(str, KNewLine, KNullDesC); |
78 |
76 str.Trim(); |
79 // DP2("CleanHtml %d, %S", str.Length(), &str); |
77 |
|
78 |
|
79 // strip out HTML tags |
|
80 |
80 TInt startPos = str.Locate('<'); |
81 TInt startPos = str.Locate('<'); |
81 TInt endPos = str.Locate('>'); |
82 TInt endPos = str.Locate('>'); |
82 //DP3("length: %d, startPos: %d, endPos: %d", str.Length(), startPos, endPos); |
|
83 HBufC* tmpBuf = HBufC::NewLC(KMaxDescriptionLength); |
83 HBufC* tmpBuf = HBufC::NewLC(KMaxDescriptionLength); |
84 TPtr tmp(tmpBuf->Des()); |
84 TPtr tmp(tmpBuf->Des()); |
85 while (startPos != KErrNotFound && endPos != KErrNotFound && endPos > startPos) { |
85 while (startPos != KErrNotFound && endPos != KErrNotFound && endPos > startPos) { |
86 //DP1("Cleaning out %S", &str.Mid(startPos, endPos-startPos+1)); |
86 //DP1("Cleaning out %S", &str.Mid(startPos, endPos-startPos+1)); |
87 tmp.Copy(str.Left(startPos)); |
87 tmp.Copy(str.Left(startPos)); |
106 |
106 |
107 str.Copy(tmp); |
107 str.Copy(tmp); |
108 startPos = str.Locate('<'); |
108 startPos = str.Locate('<'); |
109 endPos = str.Locate('>'); |
109 endPos = str.Locate('>'); |
110 } |
110 } |
111 |
111 |
112 str.Trim(); |
112 // change HTML encoded chars to unicode |
113 _LIT(KAmp, "&"); |
113 startPos = str.Locate('&'); |
114 _LIT(KQuot, """); |
114 endPos = str.Locate(';'); |
115 _LIT(KNbsp, " "); |
115 while (startPos != KErrNotFound && endPos != KErrNotFound && endPos > startPos) |
116 _LIT(KCopy, "©"); |
116 { |
117 _LIT(KCopyReplacement, "(c)"); |
117 TPtrC ptr(str.Mid(startPos+1, endPos-startPos)); |
118 if(str.Locate('&') != KErrNotFound) { |
118 // check for whitespace |
119 ReplaceString(str, KAmp, KNullDesC); |
119 if (ptr.Locate(' ') == KErrNotFound) |
120 ReplaceString(str, KQuot, KNullDesC); |
120 { |
121 ReplaceString(str, KNbsp, KNullDesC); |
121 // numerical constant |
122 ReplaceString(str, KCopy, KCopyReplacement); |
122 if (ptr[0] == '#') |
123 } |
123 { |
124 ReplaceChar(str, '"', '\''); |
124 TUint length = endPos - startPos; |
125 |
125 if (length > 2) |
|
126 { |
|
127 tmp.Copy(str.Left(startPos)); |
|
128 ptr.Set(str.Mid(startPos+2, length-2)); |
|
129 |
|
130 TUint charCode = 0; |
|
131 |
|
132 if (ptr[0] == 'x') |
|
133 { |
|
134 // hexadecimal |
|
135 ptr.Set(ptr.Mid(1)); |
|
136 TLex16 lex(ptr); |
|
137 lex.Val(charCode, EHex); |
|
138 } |
|
139 else |
|
140 { |
|
141 //decimal |
|
142 TLex16 lex(ptr); |
|
143 lex.Val(charCode, EDecimal); |
|
144 } |
|
145 |
|
146 TChar charChar(charCode); |
|
147 tmp.Append(charChar); |
|
148 tmp.Append(str.Mid(endPos+1)); |
|
149 str.Copy(tmp); |
|
150 } |
|
151 } |
|
152 // literal constant |
|
153 else |
|
154 { |
|
155 _LIT(KAmp, "amp;"); |
|
156 _LIT(KQuot, "quot;"); |
|
157 _LIT(KNbsp, "nbsp;"); |
|
158 _LIT(KCopy, "copy;"); |
|
159 |
|
160 // copy start of string |
|
161 tmp.Copy(str.Left(startPos)); |
|
162 |
|
163 if (ptr.CompareF(KAmp) == 0) |
|
164 { |
|
165 tmp.Append('&'); |
|
166 } |
|
167 else if (ptr.CompareF(KQuot) == 0) |
|
168 { |
|
169 tmp.Append('"'); |
|
170 } |
|
171 else if (ptr.CompareF(KNbsp) == 0) |
|
172 { |
|
173 tmp.Append(' '); |
|
174 } |
|
175 else if (ptr.CompareF(KCopy) == 0) |
|
176 { |
|
177 tmp.Append('\xA9'); |
|
178 } |
|
179 |
|
180 // copy end of string |
|
181 tmp.Append(str.Mid(endPos+1)); |
|
182 str.Copy(tmp); |
|
183 } |
|
184 } |
|
185 |
|
186 TInt newPos = str.Mid(startPos+1).Locate('&'); |
|
187 |
|
188 if (newPos != KErrNotFound) |
|
189 { |
|
190 startPos = startPos+1 + newPos; |
|
191 endPos = str.Locate(';'); |
|
192 } |
|
193 else |
|
194 { |
|
195 startPos = KErrNotFound; |
|
196 endPos = KErrNotFound; |
|
197 } |
|
198 } |
|
199 |
126 CleanupStack::PopAndDestroy(tmpBuf); |
200 CleanupStack::PopAndDestroy(tmpBuf); |
127 } |
201 } |
128 |
202 |
129 EXPORT_C void PodcastUtils::RemoveAllFormatting(TDes & aString) |
203 EXPORT_C void PodcastUtils::RemoveAllFormatting(TDes & aString) |
130 { |
204 { |