本文整理汇总了C++中Codec::fromUnicode方法的典型用法代码示例。如果您正苦于以下问题:C++ Codec::fromUnicode方法的具体用法?C++ Codec::fromUnicode怎么用?C++ Codec::fromUnicode使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Codec
的用法示例。
在下文中一共展示了Codec::fromUnicode方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: appendTextPart
void Multipart::appendTextPart( EString & r, const Bodypart * bp,
ContentType * ct ) const
{
Codec * c = 0;
EString::Encoding e = EString::Binary;
ContentTransferEncoding * cte
= bp->header()->contentTransferEncoding();
if ( cte )
e = cte->encoding();
if ( ct && !ct->parameter( "charset" ).isEmpty() )
c = Codec::byName( ct->parameter( "charset" ) );
if ( !c )
c = Codec::byString( bp->text() );
EString body = c->fromUnicode( bp->text() );
r.append( body.encoded( e, 72 ) );
}
示例2: asText
EString Bodypart::asText( bool avoidUtf8 ) const
{
EString r;
Codec *c = 0;
ContentType *ct = header()->contentType();
if ( ct && !ct->parameter( "charset" ).isEmpty() )
c = Codec::byName( ct->parameter( "charset" ) );
if ( !c )
c = new AsciiCodec;
if ( !children()->isEmpty() )
appendMultipart( r, avoidUtf8 );
else if ( !header()->contentType() ||
header()->contentType()->type() == "text" )
r = c->fromUnicode( text() );
else
r = d->data.e64( 72 );
return r;
}
示例3: if
//.........这里部分代码省略.........
bp->d->hasText = true;
bp->d->text = c->toUnicode( body.crlf() );
if ( c->name() == "GB2312" || c->name() == "ISO-2022-JP" ||
c->name() == "KS_C_5601-1987" ) {
// undefined code point usage in GB2312 spam is much too
// common. (GB2312 spam is much too common, but that's
// another matter.) Gb2312Codec turns all undefined code
// points into U+FFFD, so here, we can take the unicode
// form and say it's the canonical form. when a client
// later reads the message, it gets the text in unicode,
// including U+FFFD.
bool bad = !c->valid();
// the header may contain some unencoded gb2312. we bang
// it by hand, ignoring errors.
List<HeaderField>::Iterator hf( h->fields() );
while ( hf ) {
if ( !hf->valid() &&
hf->type() == HeaderField::Subject ) {
// is it right to bang only Subject?
c->reset();
hf->setValue( c->toUnicode( hf->unparsedValue() ) );
}
++hf;
}
// if the body was bad, we prefer the (unicode) in
// bp->d->text and pretend it arrived as UTF-8:
if ( bad ) {
c = new Utf8Codec;
body = c->fromUnicode( bp->d->text );
}
}
if ( ( !specified && ( !c->wellformed() ||
ct->subtype() == "html" ) ) ||
( specified && ( !c->valid() ) ) ) {
Codec * g = 0;
if ( ct->subtype() == "html" )
g = guessHtmlCodec( body );
else
g = guessTextCodec( body );
UString guessed;
if ( g )
guessed = g->toUnicode( body.crlf() );
if ( !g ) {
// if we couldn't guess anything, keep what we had if
// it's valid or explicitly specified, else use
// unknown-8bit.
if ( !specified && !c->valid() ) {
c = new Unknown8BitCodec;
bp->d->text = c->toUnicode( body.crlf() );
}
}
else {
// if we could guess something, is our guess better
// than what we had?
if ( g->wellformed() && !c->wellformed() ) {
c = g;
bp->d->text = guessed;
}
}
}