VMime
charset Class Reference

#include <charset.hpp>

Inheritance diagram for charset:
Collaboration diagram for charset:

Public Member Functions

 charset ()
 charset (const string &name)
 charset (const char *name)
const stringgetName () const
charsetoperator= (const charset &other)
bool operator== (const charset &value) const
bool operator!= (const charset &value) const
const std::vector< shared_ptr< component > > getChildComponents ()
bool getRecommendedEncoding (encoding &enc) const
bool isValidText (const string &text, string::size_type *firstInvalidByte) const
shared_ptr< componentclone () const
void copyFrom (const component &other)
Public Member Functions inherited from component
 component ()
virtual ~component ()
void parse (const string &buffer)
void parse (const parsingContext &ctx, const string &buffer)
void parse (shared_ptr< utility::inputStream > inputStream, const size_t length)
void parse (const string &buffer, const size_t position, const size_t end, size_t *newPosition=NULL)
void parse (const parsingContext &ctx, const string &buffer, const size_t position, const size_t end, size_t *newPosition=NULL)
void parse (shared_ptr< utility::inputStream > inputStream, const size_t position, const size_t end, size_t *newPosition=NULL)
void parse (const parsingContext &ctx, shared_ptr< utility::inputStream > inputStream, const size_t position, const size_t end, size_t *newPosition=NULL)
virtual const string generate (const size_t maxLineLength=lineLengthLimits::infinite, const size_t curLinePos=0) const
virtual void generate (utility::outputStream &outputStream, const size_t curLinePos=0, size_t *newLinePos=NULL) const
virtual void generate (const generationContext &ctx, utility::outputStream &outputStream, const size_t curLinePos=0, size_t *newLinePos=NULL) const
size_t getParsedOffset () const
size_t getParsedLength () const
virtual size_t getGeneratedSize (const generationContext &ctx)

Static Public Member Functions

static const charset getLocalCharset ()
static void convert (const string &in, string &out, const charset &source, const charset &dest, const charsetConverterOptions &opts=charsetConverterOptions())
static void convert (utility::inputStream &in, utility::outputStream &out, const charset &source, const charset &dest, const charsetConverterOptions &opts=charsetConverterOptions())

Protected Member Functions

void parseImpl (const parsingContext &ctx, const string &buffer, const size_t position, const size_t end, size_t *newPosition=NULL)
void generateImpl (const generationContext &ctx, utility::outputStream &os, const size_t curLinePos=0, size_t *newLinePos=NULL) const
Protected Member Functions inherited from component
void setParsedBounds (const size_t start, const size_t end)
virtual void parseImpl (const parsingContext &ctx, shared_ptr< utility::parserInputStreamAdapter > parser, const size_t position, const size_t end, size_t *newPosition=NULL)
Protected Member Functions inherited from object
 object ()
 object (const object &)
objectoperator= (const object &)
virtual ~object ()

Detailed Description

Charset description (basic type).

Constructor & Destructor Documentation

◆ charset() [1/3]

◆ charset() [2/3]

charset ( const string & name)

◆ charset() [3/3]

charset ( const char * name)

Member Function Documentation

◆ clone()

shared_ptr< component > clone ( ) const
virtual

Clone this component.

Returns
a copy of this component

Implements component.

Referenced by htmlTextPart::setPlainText().

◆ convert() [1/2]

void convert ( const string & in,
string & out,
const charset & source,
const charset & dest,
const charsetConverterOptions & opts = charsetConverterOptions() )
static

Convert a string buffer from one charset to another charset (in-memory conversion).

Deprecated
Use the new convert() method, which takes an outputStream parameter.
Parameters
ininput buffer
outoutput buffer
sourceinput charset
destoutput charset
optsconversion options
Exceptions
exceptions::illegal_byte_sequence_for_charsetif an illegal byte sequence was found in the input bytes, and the 'silentlyReplaceInvalidSequences' flag is set to false in the charsetConverterOptions
exceptions::charset_conv_errorif an unexpected error occurred during the conversion

References charset(), and charsetConverter::create().

Referenced by charsetConverter_idna::convert(), courierMaildirFormat::fromModifiedUTF7(), word::getConvertedText(), and wordEncoder::wordEncoder().

◆ convert() [2/2]

void convert ( utility::inputStream & in,
utility::outputStream & out,
const charset & source,
const charset & dest,
const charsetConverterOptions & opts = charsetConverterOptions() )
static

Convert the contents of an input stream in a specified charset to another charset and write the result to an output stream.

Parameters
ininput stream to read data from
outoutput stream to write the converted data
sourceinput charset
destoutput charset
optsconversion options
Exceptions
exceptions::illegal_byte_sequence_for_charsetif an illegal byte sequence was found in the input bytes, and the 'silentlyReplaceInvalidSequences' flag is set to false in the charsetConverterOptions
exceptions::charset_conv_errorif an unexpected error occurred during the conversion

References charset(), and charsetConverter::create().

◆ copyFrom()

void copyFrom ( const component & other)
virtual

Replace data in this component by data in other component.

Both components must be of the same type.

Exceptions
std::bad_cast_exceptionif the components are not of the same (dynamic) type
Parameters
otherother component to copy data from

Implements component.

References charset(), and component::component().

Referenced by operator=().

◆ generateImpl()

void generateImpl ( const generationContext & ctx,
utility::outputStream & os,
const size_t curLinePos = 0,
size_t * newLinePos = NULL ) const
protectedvirtual

Implements component.

◆ getChildComponents()

const std::vector< shared_ptr< component > > getChildComponents ( )
virtual

Return the list of children of this component.

Returns
list of child components

Implements component.

◆ getLocalCharset()

const charset getLocalCharset ( )
static

Returns the default charset used on the system.

This function simply calls platformHandler::getLocalCharset() and is provided for convenience.

Returns
system default charset

References charset(), platform::getHandler(), and getLocalCharset().

Referenced by getLocalCharset(), word::operator=(), and text::text().

◆ getName()

const string & getName ( ) const

Return the ISO name of the charset.

Returns
charset name

Referenced by getRecommendedEncoding(), and IMAPCommand::SEARCH().

◆ getRecommendedEncoding()

bool getRecommendedEncoding ( encoding & enc) const

Gets the recommended encoding for this charset.

Note: there may be no recommended encoding.

Parameters
encoutput parameter that will hold recommended encoding
Returns
true if an encoding is recommended (the encoding is stored in the enc parameter), false otherwise (in this case, the enc parameter is not modified)

References vmime::g_charsetEncodingMap, getName(), and stringUtils::toLower().

Referenced by text::createFromString(), encoding::decide(), wordEncoder::guessBestEncoding(), and wordEncoder::isEncodingNeeded().

◆ isValidText()

bool isValidText ( const string & text,
string::size_type * firstInvalidByte ) const

Checks whether the specified text is valid in this charset.

Parameters
textinput text
firstInvalidByteif the function returns false, will contain the index of the first invalid byte in the string. Can be NULL if not used.
Returns
true if the text is perfectly valid in this charset, or false otherwise (eg. it contains illegal sequences)

References charsetConverter::create(), charsetConverter::status::inputBytesRead, and charsetConverterOptions::silentlyReplaceInvalidSequences.

◆ operator!=()

bool operator!= ( const charset & value) const

References charset().

◆ operator=()

charset & operator= ( const charset & other)

References charset(), and copyFrom().

◆ operator==()

bool operator== ( const charset & value) const

◆ parseImpl()

void parseImpl ( const parsingContext & ctx,
const string & buffer,
const size_t position,
const size_t end,
size_t * newPosition = NULL )
protectedvirtual

The documentation for this class was generated from the following files: