| Top |
String APIs accept and produce UTF-8. Stream APIs use the selected input and output charsets, defaulting to UTF-8. Invalid or unrepresentable text is an error, not silently replaced. BOM detection and emission are opt-in.
Plain text copying preserves newlines. Flowed conversion recognizes CRLF, LF and bare CR as input line endings and writes LF, independently of the host platform. Wrapping counts Unicode scalar values rather than UTF-16 code units; it never splits a UTF-8 character.
Converters may be reused after success or failure, but must not be used concurrently or reentrantly. Conversion reads from the current input position and leaves both streams open. On failure, stream output may be partial. The string convenience API returns no partial result.
GMimeTextFormat
g_mime_text_converter_get_input_format
(GMimeTextConverter *converter);
GMimeTextFormat
g_mime_text_converter_get_output_format
(GMimeTextConverter *converter);
const char *
g_mime_text_converter_get_input_charset
(GMimeTextConverter *converter);
gboolean g_mime_text_converter_set_input_charset (GMimeTextConverter *converter,const char *charset,GError **error);
Selects strict stream decoding. Generic UTF-16/32 names select little-endian input. Strings are already UTF-8 and are not affected by this setting.
const char *
g_mime_text_converter_get_output_charset
(GMimeTextConverter *converter);
gboolean g_mime_text_converter_set_output_charset (GMimeTextConverter *converter,const char *charset,GError **error);
Selects strict stream encoding. Unrepresentable characters are errors. Generic UTF-16/32 names select little-endian bytes. String results are always UTF-8. Output has no BOM unless explicitly enabled.
gboolean
g_mime_text_converter_get_detect_encoding_from_byte_order_mark
(GMimeTextConverter *converter);
void g_mime_text_converter_set_detect_encoding_from_byte_order_mark (GMimeTextConverter *converter,gboolean detect);
When enabled, consumes an initial UTF-8, UTF-16LE/BE or UTF-32LE/BE BOM and overrides the input charset. Without a BOM the configured charset is used. When disabled, BOMs are ordinary text. Does not affect string input.
gboolean
g_mime_text_converter_get_write_bom (GMimeTextConverter *converter);
void g_mime_text_converter_set_write_bom (GMimeTextConverter *converter,gboolean write_bom);
Writes a BOM at the current output position for UTF-8, UTF-16 or UTF-32,
including for empty output. Other charsets have no BOM. String output is
unaffected. Defaults to FALSE rather than .NET's encoding-specific preamble.
gsize
g_mime_text_converter_get_input_stream_buffer_size
(GMimeTextConverter *converter);
void g_mime_text_converter_set_input_stream_buffer_size (GMimeTextConverter *converter,gsize size);
Sets the decoder read size. Additional space retains incomplete characters.
gsize
g_mime_text_converter_get_output_stream_buffer_size
(GMimeTextConverter *converter);
void g_mime_text_converter_set_output_stream_buffer_size (GMimeTextConverter *converter,gsize size);
Sets the encoder buffer size. At least 32 bytes are reserved for characters and shift sequences.
const char *
g_mime_text_converter_get_header (GMimeTextConverter *converter);
void g_mime_text_converter_set_header (GMimeTextConverter *converter,const char *header);
Copies header
. Set before conversion; no newline is added automatically.
const char *
g_mime_text_converter_get_footer (GMimeTextConverter *converter);
void g_mime_text_converter_set_footer (GMimeTextConverter *converter,const char *footer);
Copies footer
. Set before conversion; no newline is added automatically.
gboolean g_mime_text_converter_convert (GMimeTextConverter *converter,GMimeStream *input,GMimeStream *output,GError **error);
Converts from the current input position, prepending/appending the configured
header/footer. Flushes output on success, without closing or rewinding either
stream. Output can be partial on failure. Shared backing storage must not
overlap. Invalid or unrepresentable characters are reported in G_CONVERT_ERROR;
I/O errors use GMIME_ERROR with errno, or GMIME_ERROR_GENERAL when unavailable.
Encoding defaults to UTF-8 with no BOM detection or emission, except
that RTF converters default to Latin-1 input to preserve wire bytes.
char * g_mime_text_converter_convert_to_string (GMimeTextConverter *converter,const char *text,gssize length,GError **error);
Converts a bounded string. Input need not be NUL-terminated when length
is
nonnegative. Malformed UTF-8 is rejected. Input and output are always UTF-8,
independent of stream charset and BOM settings. Plain-text converters reject
embedded NUL; HTML converters apply their tokenizer's NUL handling. If the
converted output contains a NUL, returns NULL with G_CONVERT_ERROR_EMBEDDED_NUL.
GMimeTextConverter *
g_mime_text_to_flowed_new (void);
Converts plain text to flowed text. Label the output MIME part text/plain; format=flowed; delsp=yes. Does not change MIME headers.
gboolean
g_mime_flowed_to_text_get_delete_space
(GMimeFlowedToText *converter);
void g_mime_flowed_to_text_set_delete_space (GMimeFlowedToText *converter,gboolean delete_space);
Set before conversion. Defaults to FALSE, corresponding to delsp=no.
typedef struct _GMimeTextConverter GMimeTextConverter;
An abstract, synchronous text converter with UTF-8 string APIs and selectable stream charsets.
struct GMimeTextConverterClass {
GObjectClass parent_class;
GMimeTextFormat input_format;
GMimeTextFormat output_format;
gboolean (*convert) (GMimeTextConverter *converter, GMimeStream *input, GMimeStream *output, GError **error);
};
Base class for text converters. Implementations must not retain stream arguments after returning, and must leave the converter reusable on failure.
GMimeTextFormat |
the input text format |
|
GMimeTextFormat |
the output text format |
|
converts UTF-8 streams, including the configured
header/footer, reporting invalid input and I/O failures through |
typedef struct _GMimeTextToText GMimeTextToText;
Copies UTF-8 text without changing its newlines.
typedef struct _GMimeTextToFlowed GMimeTextToFlowed;
Converts plain text to format=flowed; delsp=yes.