engine/src/PodcastUtils.cpp
branchsymbian1
changeset 240 03e8cc4066ba
parent 161 ce4f70a6d1d2
child 246 140a404c6b53
equal deleted inserted replaced
213:53d9fa8ea3b3 240:03e8cc4066ba
    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 	
    76 	
       
    77 	DP("    miscellaneous");
    77 // miscellaneous cleanup
    78 // miscellaneous cleanup
    78 	const TChar KLineBreak(CEditableText::ELineBreak); 
    79 	const TChar KLineBreak(CEditableText::ELineBreak); 
    79 	_LIT(KNewLine, "\n");
    80 	_LIT(KNewLine, "\n");
    80 	_LIT(KNewLineWindows, "\r\n");
    81 	_LIT(KNewLineWindows, "\r\n");
    81 	ReplaceString(str, KNewLine, KNullDesC);
    82 	ReplaceString(str, KNewLine, KNullDesC);
    82 	ReplaceString(str, KNewLineWindows, KNullDesC);
    83 	ReplaceString(str, KNewLineWindows, KNullDesC);
    83 
    84 
       
    85 	DP("    strip HTML");
    84 // strip out HTML tags
    86 // strip out HTML tags
    85 	
    87 	
    86 	TInt startPos = str.Locate('<');
    88 	TInt startPos = str.Locate('<');
    87 	TInt endPos = str.Locate('>');
    89 	TInt endPos = str.Locate('>');
    88 	HBufC* tmpBuf = HBufC::NewLC(KMaxDescriptionLength);
    90 	HBufC* tmpBuf = HBufC::NewLC(KMaxDescriptionLength);
   112 		str.Copy(tmp);
   114 		str.Copy(tmp);
   113 		startPos = str.Locate('<');
   115 		startPos = str.Locate('<');
   114 		endPos = str.Locate('>');
   116 		endPos = str.Locate('>');
   115 	}
   117 	}
   116 		
   118 		
       
   119 	DP("    change HTML encoded chars to unicode");
   117 // change HTML encoded chars to unicode
   120 // change HTML encoded chars to unicode
   118 	startPos = str.Locate('&');
   121 	startPos = str.Locate('&');
   119 	endPos = str.Locate(';');
   122 	endPos = str.Locate(';');
   120 	while (startPos != KErrNotFound && endPos != KErrNotFound && endPos > startPos)
   123 	while (startPos != KErrNotFound && endPos != KErrNotFound && endPos > startPos)
   121 		{
   124 		{
   202 			}
   205 			}
   203 		}
   206 		}
   204 		
   207 		
   205 	CleanupStack::PopAndDestroy(tmpBuf);
   208 	CleanupStack::PopAndDestroy(tmpBuf);
   206 	
   209 	
       
   210 	DP("    trim");
   207 	if(str.Length()>1)
   211 	if(str.Length()>1)
   208 		{
   212 		{
       
   213 		DP1("str.Length() ==%d", str.Length());
   209 		// chop away newlines at start
   214 		// chop away newlines at start
   210 		while ((str[0] == KLineBreak) )  {
   215 		while (str.Length() && (str[0] == KLineBreak))  {
       
   216 			DP("mid");
   211 			str = str.Mid(1);
   217 			str = str.Mid(1);
   212 		}
   218 		}
   213 		
   219 		
   214 		// chop away newlines at end
   220 		// chop away newlines at end
   215 	
   221 	
   216 		while ((str[str.Length()-1] == KLineBreak)) {
   222 		while (str.Length() && (str[str.Length()-1] == KLineBreak)) {
       
   223 			DP("left");
   217 			str = str.Left(str.Length()-1);
   224 			str = str.Left(str.Length()-1);
   218 		}
   225 		}
   219 
   226 
   220 		str.Trim();
   227 		str.Trim();
   221 		}
   228 		}
       
   229 	DP("PodcastUtils::CleanHtmlL END");
   222 }
   230 }
   223 
   231 
   224 EXPORT_C void PodcastUtils::RemoveAllFormatting(TDes & aString)
   232 EXPORT_C void PodcastUtils::RemoveAllFormatting(TDes & aString)
   225 	{
   233 	{
   226 	// check for combination first so we prevent adding two spaces 
   234 	// check for combination first so we prevent adding two spaces