engine/src/PodcastUtils.cpp
author teknolog
Wed, 03 Mar 2010 22:24:42 +0000
changeset 31 8a5ead064c4f
parent 21 420a1b4930da
child 60 4d230e702aa3
permissions -rw-r--r--
Shows view now updates correctl after Mark all played
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
     1
/*
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
     2
* Copyright (c) 2007-2010 Sebastian Brannstrom, Lars Persson, EmbedDev AB
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
     3
*
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
     4
* All rights reserved.
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
     5
* This component and the accompanying materials are made available
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
     6
* under the terms of the License "Eclipse Public License v1.0"
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
     7
* which accompanies this distribution, and is available
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
     8
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
     9
*
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    10
* Initial Contributors:
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    11
* EmbedDev AB - initial contribution.
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    12
*
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    13
* Contributors:
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    14
*
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    15
* Description:
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    16
*
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    17
*/
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    18
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    19
#include <e32std.h>
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    20
#include <e32base.h>
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    21
#include <TXTETEXT.H> // for ELineBreak
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    22
#include "PodcastUtils.h"
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    23
#include "debug.h"
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    24
#include "FeedEngine.h" // for KMaxDescriptionLength
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    25
			
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    26
EXPORT_C void PodcastUtils::FixProtocolsL(TDes &aUrl)
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    27
	{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    28
	HBufC* urlCopy = aUrl.AllocLC();
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    29
	TPtr urlCopyPtr (urlCopy->Des());
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    30
	urlCopyPtr.LowerCase();
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    31
	
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    32
	// url is always present so access that								
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    33
	// Some pod links are written in format itpc://mylink.net/podcast.xml
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    34
	// Symbian HTTP stack does not like itpc:// 
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    35
	// Try to use a HTTP instead.
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    36
	TInt p = urlCopyPtr.Find(KItpcPrefix);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    37
	if (p >= 0)
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    38
		{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    39
		aUrl.Delete(p, KItpcPrefix().Length());
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    40
		}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    41
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    42
	// Some pod links are written in format pcast://mylink.net/podcast.xml
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    43
	// Symbian HTTP stack does not like itpc:// 
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    44
	// Try to use a HTTP instead.
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    45
	p = urlCopyPtr.Find(KPcastPrefix);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    46
	if (p >= 0)
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    47
		{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    48
		aUrl.Delete(p, KPcastPrefix().Length());
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    49
		}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    50
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    51
	// The URL must start with http://, otherwise the HTTP stack fails.
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    52
	TInt pos = urlCopyPtr.Find(KURLPrefix);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    53
	if (pos == KErrNotFound)
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    54
		{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    55
		HBufC* newUrl = HBufC::NewL(aUrl.Length() + KURLPrefix().Length());
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    56
		TPtr ptr = newUrl->Des();
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    57
		ptr.Append(KURLPrefix());
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    58
		ptr.Append(aUrl);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    59
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    60
		// replace the url buffer
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    61
		aUrl.Copy(*newUrl);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    62
		delete newUrl;					
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    63
		}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    64
	
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    65
	CleanupStack::PopAndDestroy(urlCopy);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    66
	}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    67
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    68
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    69
EXPORT_C void PodcastUtils::CleanHtmlL(TDes &str)
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    70
{
21
420a1b4930da SQLEncoding for showinfo added
teknolog
parents: 19
diff changeset
    71
420a1b4930da SQLEncoding for showinfo added
teknolog
parents: 19
diff changeset
    72
	if (str.Length() == 0)
420a1b4930da SQLEncoding for showinfo added
teknolog
parents: 19
diff changeset
    73
		{
420a1b4930da SQLEncoding for showinfo added
teknolog
parents: 19
diff changeset
    74
		return;
420a1b4930da SQLEncoding for showinfo added
teknolog
parents: 19
diff changeset
    75
		}
420a1b4930da SQLEncoding for showinfo added
teknolog
parents: 19
diff changeset
    76
	
18
cda6e6257514 Improved HTML cleaning
teknolog
parents: 15
diff changeset
    77
// miscellaneous cleanup
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    78
	const TChar KLineBreak(CEditableText::ELineBreak); 
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    79
	_LIT(KNewLine, "\n");
19
9219912415dc Even more improved HTML cleaning
teknolog
parents: 18
diff changeset
    80
	_LIT(KNewLineWindows, "\r\n");
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    81
	ReplaceString(str, KNewLine, KNullDesC);
19
9219912415dc Even more improved HTML cleaning
teknolog
parents: 18
diff changeset
    82
	ReplaceString(str, KNewLineWindows, KNullDesC);
18
cda6e6257514 Improved HTML cleaning
teknolog
parents: 15
diff changeset
    83
cda6e6257514 Improved HTML cleaning
teknolog
parents: 15
diff changeset
    84
// strip out HTML tags
cda6e6257514 Improved HTML cleaning
teknolog
parents: 15
diff changeset
    85
	
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    86
	TInt startPos = str.Locate('<');
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    87
	TInt endPos = str.Locate('>');
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    88
	HBufC* tmpBuf = HBufC::NewLC(KMaxDescriptionLength);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    89
	TPtr tmp(tmpBuf->Des());
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    90
	while (startPos != KErrNotFound && endPos != KErrNotFound && endPos > startPos) {
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    91
		//DP1("Cleaning out %S", &str.Mid(startPos, endPos-startPos+1));
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    92
		tmp.Copy(str.Left(startPos));
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    93
		TPtrC ptr=str.Mid(startPos, endPos-startPos+1);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    94
		_LIT(KHtmlBr, "<br>");
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    95
		_LIT(KHtmlBr2, "<br />");
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    96
		_LIT(KHtmlBr3, "<br/>");
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    97
		_LIT(KHtmlP, "<p>");
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    98
		if (ptr.CompareF(KHtmlBr)== 0 || ptr.CompareF(KHtmlBr2)== 0 || ptr.CompareF(KHtmlBr3)== 0)
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    99
			{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   100
			tmp.Append(KLineBreak);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   101
			}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   102
		else if (ptr.CompareF(KHtmlP) == 0)
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   103
			{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   104
			tmp.Append(KLineBreak);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   105
			tmp.Append(KLineBreak);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   106
			}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   107
		
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   108
		if (str.Length() > endPos+1) {
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   109
			tmp.Append(str.Mid(endPos+1));
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   110
		}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   111
		
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   112
		str.Copy(tmp);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   113
		startPos = str.Locate('<');
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   114
		endPos = str.Locate('>');
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   115
	}
18
cda6e6257514 Improved HTML cleaning
teknolog
parents: 15
diff changeset
   116
		
cda6e6257514 Improved HTML cleaning
teknolog
parents: 15
diff changeset
   117
// change HTML encoded chars to unicode
cda6e6257514 Improved HTML cleaning
teknolog
parents: 15
diff changeset
   118
	startPos = str.Locate('&');
cda6e6257514 Improved HTML cleaning
teknolog
parents: 15
diff changeset
   119
	endPos = str.Locate(';');
cda6e6257514 Improved HTML cleaning
teknolog
parents: 15
diff changeset
   120
	while (startPos != KErrNotFound && endPos != KErrNotFound && endPos > startPos)
cda6e6257514 Improved HTML cleaning
teknolog
parents: 15
diff changeset
   121
		{
cda6e6257514 Improved HTML cleaning
teknolog
parents: 15
diff changeset
   122
		TPtrC ptr(str.Mid(startPos+1, endPos-startPos));
cda6e6257514 Improved HTML cleaning
teknolog
parents: 15
diff changeset
   123
		// check for whitespace
cda6e6257514 Improved HTML cleaning
teknolog
parents: 15
diff changeset
   124
		if (ptr.Locate(' ') == KErrNotFound)
cda6e6257514 Improved HTML cleaning
teknolog
parents: 15
diff changeset
   125
			{
cda6e6257514 Improved HTML cleaning
teknolog
parents: 15
diff changeset
   126
			// numerical constant
cda6e6257514 Improved HTML cleaning
teknolog
parents: 15
diff changeset
   127
			if (ptr[0] == '#')
cda6e6257514 Improved HTML cleaning
teknolog
parents: 15
diff changeset
   128
				{ 
cda6e6257514 Improved HTML cleaning
teknolog
parents: 15
diff changeset
   129
				TUint length = endPos - startPos;
cda6e6257514 Improved HTML cleaning
teknolog
parents: 15
diff changeset
   130
				if (length > 2)
cda6e6257514 Improved HTML cleaning
teknolog
parents: 15
diff changeset
   131
					{
cda6e6257514 Improved HTML cleaning
teknolog
parents: 15
diff changeset
   132
					tmp.Copy(str.Left(startPos));
cda6e6257514 Improved HTML cleaning
teknolog
parents: 15
diff changeset
   133
					ptr.Set(str.Mid(startPos+2, length-2));
cda6e6257514 Improved HTML cleaning
teknolog
parents: 15
diff changeset
   134
					
cda6e6257514 Improved HTML cleaning
teknolog
parents: 15
diff changeset
   135
					TUint charCode = 0;
cda6e6257514 Improved HTML cleaning
teknolog
parents: 15
diff changeset
   136
				
cda6e6257514 Improved HTML cleaning
teknolog
parents: 15
diff changeset
   137
					if (ptr[0] == 'x')
cda6e6257514 Improved HTML cleaning
teknolog
parents: 15
diff changeset
   138
						{
cda6e6257514 Improved HTML cleaning
teknolog
parents: 15
diff changeset
   139
						// hexadecimal
cda6e6257514 Improved HTML cleaning
teknolog
parents: 15
diff changeset
   140
						ptr.Set(ptr.Mid(1));
cda6e6257514 Improved HTML cleaning
teknolog
parents: 15
diff changeset
   141
						TLex16 lex(ptr);
cda6e6257514 Improved HTML cleaning
teknolog
parents: 15
diff changeset
   142
						lex.Val(charCode, EHex);	
cda6e6257514 Improved HTML cleaning
teknolog
parents: 15
diff changeset
   143
						}
cda6e6257514 Improved HTML cleaning
teknolog
parents: 15
diff changeset
   144
					else
cda6e6257514 Improved HTML cleaning
teknolog
parents: 15
diff changeset
   145
						{
cda6e6257514 Improved HTML cleaning
teknolog
parents: 15
diff changeset
   146
						//decimal
cda6e6257514 Improved HTML cleaning
teknolog
parents: 15
diff changeset
   147
						TLex16 lex(ptr);
cda6e6257514 Improved HTML cleaning
teknolog
parents: 15
diff changeset
   148
						lex.Val(charCode, EDecimal);	
cda6e6257514 Improved HTML cleaning
teknolog
parents: 15
diff changeset
   149
						}
cda6e6257514 Improved HTML cleaning
teknolog
parents: 15
diff changeset
   150
					
cda6e6257514 Improved HTML cleaning
teknolog
parents: 15
diff changeset
   151
					TChar charChar(charCode);
cda6e6257514 Improved HTML cleaning
teknolog
parents: 15
diff changeset
   152
					tmp.Append(charChar);
cda6e6257514 Improved HTML cleaning
teknolog
parents: 15
diff changeset
   153
					tmp.Append(str.Mid(endPos+1));
cda6e6257514 Improved HTML cleaning
teknolog
parents: 15
diff changeset
   154
					str.Copy(tmp);
cda6e6257514 Improved HTML cleaning
teknolog
parents: 15
diff changeset
   155
					}
cda6e6257514 Improved HTML cleaning
teknolog
parents: 15
diff changeset
   156
				}
cda6e6257514 Improved HTML cleaning
teknolog
parents: 15
diff changeset
   157
			// literal constant
cda6e6257514 Improved HTML cleaning
teknolog
parents: 15
diff changeset
   158
			else
cda6e6257514 Improved HTML cleaning
teknolog
parents: 15
diff changeset
   159
				{
cda6e6257514 Improved HTML cleaning
teknolog
parents: 15
diff changeset
   160
				_LIT(KAmp, "amp;");
cda6e6257514 Improved HTML cleaning
teknolog
parents: 15
diff changeset
   161
				_LIT(KQuot, "quot;");
cda6e6257514 Improved HTML cleaning
teknolog
parents: 15
diff changeset
   162
				_LIT(KNbsp, "nbsp;");
cda6e6257514 Improved HTML cleaning
teknolog
parents: 15
diff changeset
   163
				_LIT(KCopy, "copy;");
cda6e6257514 Improved HTML cleaning
teknolog
parents: 15
diff changeset
   164
				
cda6e6257514 Improved HTML cleaning
teknolog
parents: 15
diff changeset
   165
				// copy start of string
cda6e6257514 Improved HTML cleaning
teknolog
parents: 15
diff changeset
   166
				tmp.Copy(str.Left(startPos));
cda6e6257514 Improved HTML cleaning
teknolog
parents: 15
diff changeset
   167
				
cda6e6257514 Improved HTML cleaning
teknolog
parents: 15
diff changeset
   168
				if (ptr.CompareF(KAmp) == 0)
cda6e6257514 Improved HTML cleaning
teknolog
parents: 15
diff changeset
   169
					{
cda6e6257514 Improved HTML cleaning
teknolog
parents: 15
diff changeset
   170
					tmp.Append('&');
cda6e6257514 Improved HTML cleaning
teknolog
parents: 15
diff changeset
   171
					}
cda6e6257514 Improved HTML cleaning
teknolog
parents: 15
diff changeset
   172
				else if (ptr.CompareF(KQuot) == 0)
cda6e6257514 Improved HTML cleaning
teknolog
parents: 15
diff changeset
   173
					{
cda6e6257514 Improved HTML cleaning
teknolog
parents: 15
diff changeset
   174
					tmp.Append('"');
cda6e6257514 Improved HTML cleaning
teknolog
parents: 15
diff changeset
   175
					}
cda6e6257514 Improved HTML cleaning
teknolog
parents: 15
diff changeset
   176
				else if (ptr.CompareF(KNbsp) == 0)
cda6e6257514 Improved HTML cleaning
teknolog
parents: 15
diff changeset
   177
					{
cda6e6257514 Improved HTML cleaning
teknolog
parents: 15
diff changeset
   178
					tmp.Append(' ');
cda6e6257514 Improved HTML cleaning
teknolog
parents: 15
diff changeset
   179
					}
cda6e6257514 Improved HTML cleaning
teknolog
parents: 15
diff changeset
   180
				else if (ptr.CompareF(KCopy) == 0)
cda6e6257514 Improved HTML cleaning
teknolog
parents: 15
diff changeset
   181
					{
cda6e6257514 Improved HTML cleaning
teknolog
parents: 15
diff changeset
   182
					tmp.Append('\xA9');
cda6e6257514 Improved HTML cleaning
teknolog
parents: 15
diff changeset
   183
					}
cda6e6257514 Improved HTML cleaning
teknolog
parents: 15
diff changeset
   184
				
cda6e6257514 Improved HTML cleaning
teknolog
parents: 15
diff changeset
   185
				// copy end of string
cda6e6257514 Improved HTML cleaning
teknolog
parents: 15
diff changeset
   186
				tmp.Append(str.Mid(endPos+1));
cda6e6257514 Improved HTML cleaning
teknolog
parents: 15
diff changeset
   187
				str.Copy(tmp);
cda6e6257514 Improved HTML cleaning
teknolog
parents: 15
diff changeset
   188
				}
cda6e6257514 Improved HTML cleaning
teknolog
parents: 15
diff changeset
   189
			}
cda6e6257514 Improved HTML cleaning
teknolog
parents: 15
diff changeset
   190
		
cda6e6257514 Improved HTML cleaning
teknolog
parents: 15
diff changeset
   191
		TInt newPos = str.Mid(startPos+1).Locate('&');
cda6e6257514 Improved HTML cleaning
teknolog
parents: 15
diff changeset
   192
		
cda6e6257514 Improved HTML cleaning
teknolog
parents: 15
diff changeset
   193
		if (newPos != KErrNotFound)
cda6e6257514 Improved HTML cleaning
teknolog
parents: 15
diff changeset
   194
			{
cda6e6257514 Improved HTML cleaning
teknolog
parents: 15
diff changeset
   195
			startPos = startPos+1 + newPos;
cda6e6257514 Improved HTML cleaning
teknolog
parents: 15
diff changeset
   196
			endPos = str.Locate(';');
cda6e6257514 Improved HTML cleaning
teknolog
parents: 15
diff changeset
   197
			}
cda6e6257514 Improved HTML cleaning
teknolog
parents: 15
diff changeset
   198
		else
cda6e6257514 Improved HTML cleaning
teknolog
parents: 15
diff changeset
   199
			{
cda6e6257514 Improved HTML cleaning
teknolog
parents: 15
diff changeset
   200
			startPos = KErrNotFound;
cda6e6257514 Improved HTML cleaning
teknolog
parents: 15
diff changeset
   201
			endPos = KErrNotFound;
cda6e6257514 Improved HTML cleaning
teknolog
parents: 15
diff changeset
   202
			}
cda6e6257514 Improved HTML cleaning
teknolog
parents: 15
diff changeset
   203
		}
cda6e6257514 Improved HTML cleaning
teknolog
parents: 15
diff changeset
   204
		
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   205
	CleanupStack::PopAndDestroy(tmpBuf);
19
9219912415dc Even more improved HTML cleaning
teknolog
parents: 18
diff changeset
   206
	
9219912415dc Even more improved HTML cleaning
teknolog
parents: 18
diff changeset
   207
	// chop away newlines at start
9219912415dc Even more improved HTML cleaning
teknolog
parents: 18
diff changeset
   208
	while (str[0] == KLineBreak) {
9219912415dc Even more improved HTML cleaning
teknolog
parents: 18
diff changeset
   209
		str = str.Mid(1);
9219912415dc Even more improved HTML cleaning
teknolog
parents: 18
diff changeset
   210
	}
9219912415dc Even more improved HTML cleaning
teknolog
parents: 18
diff changeset
   211
	
9219912415dc Even more improved HTML cleaning
teknolog
parents: 18
diff changeset
   212
	// chop away newlines at end
9219912415dc Even more improved HTML cleaning
teknolog
parents: 18
diff changeset
   213
9219912415dc Even more improved HTML cleaning
teknolog
parents: 18
diff changeset
   214
	while (str[str.Length()-1] == KLineBreak) {
9219912415dc Even more improved HTML cleaning
teknolog
parents: 18
diff changeset
   215
		str = str.Left(str.Length()-1);
9219912415dc Even more improved HTML cleaning
teknolog
parents: 18
diff changeset
   216
	}
9219912415dc Even more improved HTML cleaning
teknolog
parents: 18
diff changeset
   217
9219912415dc Even more improved HTML cleaning
teknolog
parents: 18
diff changeset
   218
	str.Trim();
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   219
}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   220
15
93d9f66bf50b Cleaning description better for second line in search results
teknolog
parents: 2
diff changeset
   221
EXPORT_C void PodcastUtils::RemoveAllFormatting(TDes & aString)
93d9f66bf50b Cleaning description better for second line in search results
teknolog
parents: 2
diff changeset
   222
	{
93d9f66bf50b Cleaning description better for second line in search results
teknolog
parents: 2
diff changeset
   223
	// check for combination first so we prevent adding two spaces 
93d9f66bf50b Cleaning description better for second line in search results
teknolog
parents: 2
diff changeset
   224
	ReplaceString(aString,_L("\r\n"), _L(" "));
93d9f66bf50b Cleaning description better for second line in search results
teknolog
parents: 2
diff changeset
   225
	
93d9f66bf50b Cleaning description better for second line in search results
teknolog
parents: 2
diff changeset
   226
	ReplaceString(aString,_L("\n"), _L(" "));
93d9f66bf50b Cleaning description better for second line in search results
teknolog
parents: 2
diff changeset
   227
	ReplaceString(aString,_L("\r"), _L(" "));
93d9f66bf50b Cleaning description better for second line in search results
teknolog
parents: 2
diff changeset
   228
	
93d9f66bf50b Cleaning description better for second line in search results
teknolog
parents: 2
diff changeset
   229
	}
93d9f66bf50b Cleaning description better for second line in search results
teknolog
parents: 2
diff changeset
   230
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   231
EXPORT_C void PodcastUtils::ReplaceString(TDes & aString, const TDesC& aStringToReplace, const TDesC& aReplacement)
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   232
	{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   233
	TInt pos=aString.Find(aStringToReplace);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   234
	TInt offset = 0;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   235
	while (pos != KErrNotFound)
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   236
		{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   237
		aString.Replace(offset+pos, aStringToReplace.Length(), aReplacement);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   238
		offset += pos + aStringToReplace.Length()+1;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   239
		if (offset > aString.Length())
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   240
			{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   241
			return;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   242
			}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   243
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   244
		pos=aString.Mid(offset).Find(aStringToReplace);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   245
		}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   246
	}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   247
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   248
EXPORT_C void PodcastUtils::ReplaceChar(TDes & aString, TUint aCharToReplace, TUint aReplacement)
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   249
	{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   250
	TInt strLen=aString.Length();
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   251
	for (TInt i=0; i < strLen; i++)
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   252
		{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   253
		if (aString[i] == aCharToReplace)
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   254
			{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   255
			aString[i] = aReplacement;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   256
			}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   257
		}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   258
	}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   259
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   260
EXPORT_C void PodcastUtils::EnsureProperPathName(TFileName &aPath)
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   261
	{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   262
	// from the SDK: The following characters cannot occur in the path: < >: " / |*
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   263
	
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   264
	ReplaceChar(aPath, '/', '_'); // better not to add \\ in case we have multiple /
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   265
	ReplaceChar(aPath, ':', '_');
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   266
	ReplaceChar(aPath, '?', '_');
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   267
	ReplaceChar(aPath, '|', '_');
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   268
	ReplaceChar(aPath, '*', '_');
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   269
	ReplaceChar(aPath, '<', '_');
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   270
	ReplaceChar(aPath, '>', '_');
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   271
	ReplaceChar(aPath, '"', '_');
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   272
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   273
	//buf.Append(_L("\\"));
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   274
	}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   275
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   276
EXPORT_C void PodcastUtils::FileNameFromUrl(const TDesC& aUrl, TFileName &aFileName)
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   277
	{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   278
	TInt pos = aUrl.LocateReverse('/');
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   279
	
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   280
	if (pos != KErrNotFound) 
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   281
		{	
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   282
		TPtrC str = aUrl.Mid(pos+1);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   283
		pos = str.Locate('?');
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   284
		if (pos != KErrNotFound) 
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   285
			{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   286
			aFileName.Copy(str.Left(pos));
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   287
			} 
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   288
		else 
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   289
			{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   290
			aFileName.Copy(str);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   291
			}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   292
		}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   293
	DP2("FileNameFromUrl in: %S, out: %S", &aUrl, &aFileName);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   294
	}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   295
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   296
EXPORT_C void PodcastUtils::SQLEncode(TDes &aString)
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   297
	{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   298
	ReplaceString(aString, _L("\""), _L("\"\""));
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   299
	//ReplaceString(aString, _L("'"), _L("''"));	
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   300
	}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   301
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   302
EXPORT_C void PodcastUtils::XMLEncode(TDes &aString)
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   303
	{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   304
	ReplaceString(aString, _L("\""), _L("&quot;"));	
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   305
	ReplaceString(aString, _L("<"), _L("&lt;"));
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   306
	ReplaceString(aString, _L(">"), _L("&gt;"));
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   307
	ReplaceString(aString, _L("&"), _L("&amp;"));
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   308
	}