本文整理汇总了C++中nsAutoString::SetLength方法的典型用法代码示例。如果您正苦于以下问题:C++ nsAutoString::SetLength方法的具体用法?C++ nsAutoString::SetLength怎么用?C++ nsAutoString::SetLength使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类nsAutoString
的用法示例。
在下文中一共展示了nsAutoString::SetLength方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: textSink
//
// ConvertFromHTMLToUnicode
//
// Takes HTML and converts it to plain text but in unicode.
//
NS_IMETHODIMP
nsHTMLFormatConverter::ConvertFromHTMLToUnicode(const nsAutoString & aFromStr, nsAutoString & aToStr)
{
// create the parser to do the conversion.
aToStr.SetLength(0);
nsresult rv;
nsCOMPtr<nsIParser> parser = do_CreateInstance(kCParserCID, &rv);
if ( !parser )
return rv;
// convert it!
nsCOMPtr<nsIContentSink> sink;
sink = do_CreateInstance(NS_PLAINTEXTSINK_CONTRACTID);
NS_ENSURE_TRUE(sink, NS_ERROR_FAILURE);
nsCOMPtr<nsIHTMLToTextSink> textSink(do_QueryInterface(sink));
NS_ENSURE_TRUE(textSink, NS_ERROR_FAILURE);
textSink->Initialize(&aToStr, nsIDocumentEncoder::OutputSelectionOnly
| nsIDocumentEncoder::OutputAbsoluteLinks, 0);
parser->SetContentSink(sink);
parser->Parse(aFromStr, 0, NS_LITERAL_CSTRING("text/html"), PR_TRUE, eDTDMode_fragment);
return NS_OK;
} // ConvertFromHTMLToUnicode
示例2: textSink
//
// ConvertFromHTMLToUnicode
//
// Takes HTML and converts it to plain text but in unicode.
//
NS_IMETHODIMP
nsHTMLFormatConverter::ConvertFromHTMLToUnicode(const nsAutoString & aFromStr, nsAutoString & aToStr)
{
// create the parser to do the conversion.
aToStr.SetLength(0);
nsresult rv;
nsCOMPtr<nsIParser> parser = do_CreateInstance(kCParserCID, &rv);
if ( !parser )
return rv;
// convert it!
nsCOMPtr<nsIContentSink> sink;
sink = do_CreateInstance(NS_PLAINTEXTSINK_CONTRACTID);
NS_ENSURE_TRUE(sink, NS_ERROR_FAILURE);
nsCOMPtr<nsIHTMLToTextSink> textSink(do_QueryInterface(sink));
NS_ENSURE_TRUE(textSink, NS_ERROR_FAILURE);
// We set OutputNoScriptContent and OutputNoFramesContent unconditionally
// here because |aFromStr| is already filtered based on user preferences.
PRUint32 flags =
nsIDocumentEncoder::OutputSelectionOnly |
nsIDocumentEncoder::OutputAbsoluteLinks |
nsIDocumentEncoder::OutputNoScriptContent |
nsIDocumentEncoder::OutputNoFramesContent;
textSink->Initialize(&aToStr, flags, 0);
parser->SetContentSink(sink);
parser->Parse(aFromStr, 0, NS_LITERAL_CSTRING("text/html"), PR_TRUE, eDTDMode_fragment);
return NS_OK;
} // ConvertFromHTMLToUnicode