engine/src/PodcastUtils.cpp
branchRCL_3
changeset 333 c80c7fb835c2
parent 257 f5377b5817a0
child 369 c683165bec63
equal deleted inserted replaced
332:88a24b8b97d8 333:c80c7fb835c2
    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 
    71 	DP("PodcastUtils::CleanHtmlL BEGIN");
    72 	if (str.Length() == 0)
    72 	if (str.Length() == 0)
    73 		{
    73 		{
    74 		return;
    74 		return;
    75 		}
    75 		}
    76 	
       
    77 // miscellaneous cleanup
    76 // miscellaneous cleanup
       
    77 	DP("    miscellaneous cleanup");
    78 	const TChar KLineBreak(CEditableText::ELineBreak); 
    78 	const TChar KLineBreak(CEditableText::ELineBreak); 
    79 	_LIT(KNewLine, "\n");
    79 	_LIT(KNewLine, "\n");
    80 	_LIT(KNewLineWindows, "\r\n");
    80 	_LIT(KNewLineWindows, "\r\n");
    81 	ReplaceString(str, KNewLine, KNullDesC);
    81 	ReplaceString(str, KNewLine, KNullDesC);
    82 	ReplaceString(str, KNewLineWindows, KNullDesC);
    82 	ReplaceString(str, KNewLineWindows, KNullDesC);
    83 
    83 
    84 // strip out HTML tags
    84 // strip out HTML tags
    85 	
    85 	DP("    strip out HTML tags");
    86 	TInt startPos = str.Locate('<');
    86 	TInt startPos = str.Locate('<');
    87 	TInt endPos = str.Locate('>');
    87 	TInt endPos = str.Locate('>');
    88 	HBufC* tmpBuf = HBufC::NewLC(KMaxDescriptionLength);
    88 	HBufC* tmpBuf = HBufC::NewLC(KMaxDescriptionLength);
    89 	TPtr tmp(tmpBuf->Des());
    89 	TPtr tmp(tmpBuf->Des());
    90 	while (startPos != KErrNotFound && endPos != KErrNotFound && endPos > startPos) {
    90 	while (startPos != KErrNotFound && endPos != KErrNotFound && endPos > startPos) {
   113 		startPos = str.Locate('<');
   113 		startPos = str.Locate('<');
   114 		endPos = str.Locate('>');
   114 		endPos = str.Locate('>');
   115 	}
   115 	}
   116 		
   116 		
   117 // change HTML encoded chars to unicode
   117 // change HTML encoded chars to unicode
       
   118 	DP("    change HTML encoded chars to unicode");
   118 	startPos = str.Locate('&');
   119 	startPos = str.Locate('&');
   119 	endPos = str.Locate(';');
   120 	endPos = str.Locate(';');
   120 	while (startPos != KErrNotFound && endPos != KErrNotFound && endPos > startPos)
   121 	while (startPos != KErrNotFound && endPos != KErrNotFound && endPos > startPos)
   121 		{
   122 		{
   122 		TPtrC ptr(str.Mid(startPos+1, endPos-startPos));
   123 		TPtrC ptr(str.Mid(startPos+1, endPos-startPos));
   205 	CleanupStack::PopAndDestroy(tmpBuf);
   206 	CleanupStack::PopAndDestroy(tmpBuf);
   206 	
   207 	
   207 	if(str.Length()>1)
   208 	if(str.Length()>1)
   208 		{
   209 		{
   209 		// chop away newlines at start
   210 		// chop away newlines at start
   210 		while ((str[0] == KLineBreak) )  {
   211 		DP("    chop away newlines at start");
       
   212 		while (str.Length() > 0 && (str[0] == KLineBreak))  {
   211 			str = str.Mid(1);
   213 			str = str.Mid(1);
   212 		}
   214 		}
   213 		
   215 		
   214 		// chop away newlines at end
   216 		// chop away newlines at end
   215 	
   217 		DP("    chop away newlines at end");
   216 		while ((str[str.Length()-1] == KLineBreak)) {
   218 		while (str.Length() > 0 && (str[str.Length()-1] == KLineBreak)) {
   217 			str = str.Left(str.Length()-1);
   219 			str = str.Left(str.Length()-1);
   218 		}
   220 		}
   219 
   221 
   220 		str.Trim();
   222 		str.Trim();
   221 		}
   223 		}
       
   224 	DP("PodcastUtils::CleanHtmlL END");
   222 }
   225 }
   223 
   226 
   224 EXPORT_C void PodcastUtils::RemoveAllFormatting(TDes & aString)
   227 EXPORT_C void PodcastUtils::RemoveAllFormatting(TDes & aString)
   225 	{
   228 	{
   226 	// check for combination first so we prevent adding two spaces 
   229 	// check for combination first so we prevent adding two spaces