mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-11-05 02:28:55 +01:00
fixup! Add GBase64Encoder and Decoder
Review feedback.
This commit is contained in:
@@ -21,8 +21,8 @@
|
|||||||
/**
|
/**
|
||||||
* GBase64Decoder:
|
* GBase64Decoder:
|
||||||
*
|
*
|
||||||
* `GBase64Decoder` is an implementation of `GConverter` that
|
* `GBase64Decoder` is an implementation of [iface@Gio.Converter]
|
||||||
* converts data from base64 encoding.
|
* that converts data from base64 encoding.
|
||||||
*
|
*
|
||||||
* Since: 2.82
|
* Since: 2.82
|
||||||
*/
|
*/
|
||||||
@@ -104,7 +104,7 @@ g_base64_decoder_class_init (GBase64DecoderClass *klass)
|
|||||||
*
|
*
|
||||||
* Creates a new `GBase64Decoder`.
|
* Creates a new `GBase64Decoder`.
|
||||||
*
|
*
|
||||||
* Returns: a new `GBase64Decoder`
|
* Returns: (transfer full): a new `GBase64Decoder`
|
||||||
*
|
*
|
||||||
* Since: 2.82
|
* Since: 2.82
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -20,14 +20,15 @@
|
|||||||
#include "glibintl.h"
|
#include "glibintl.h"
|
||||||
|
|
||||||
|
|
||||||
|
/* See g_base64_encode_step docs in ../glib/gbase64.c */
|
||||||
#define BASE64_ENCODING_OUTPUT_SIZE(len, break_lines) \
|
#define BASE64_ENCODING_OUTPUT_SIZE(len, break_lines) \
|
||||||
(((len) / 3 + 1) * 4 + 4 + ((break_lines) ? ((((len) / 3 + 1) * 4 + 4) / 72 + 1) : 0))
|
(((len) / 3 + 1) * 4 + 4 + ((break_lines) ? ((((len) / 3 + 1) * 4 + 4) / 72 + 1) : 0))
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* GBase64Encoder:
|
* GBase64Encoder:
|
||||||
*
|
*
|
||||||
* GBase64Encoder is an implementation of `GConverter` that
|
* `GBase64Encoder` is an implementation of [iface@Gio.Converter]
|
||||||
* converts data to base64 encoding.
|
* that converts data to base64 encoding.
|
||||||
*
|
*
|
||||||
* Since: 2.82
|
* Since: 2.82
|
||||||
*/
|
*/
|
||||||
@@ -40,11 +41,10 @@ struct _GBase64Encoder
|
|||||||
int state[2];
|
int state[2];
|
||||||
};
|
};
|
||||||
|
|
||||||
enum
|
typedef enum
|
||||||
{
|
{
|
||||||
PROP_0,
|
PROP_BREAK_LINES = 1,
|
||||||
PROP_BREAK_LINES
|
} GBase64EncoderProperty;
|
||||||
};
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
g_base64_encoder_reset (GConverter *converter)
|
g_base64_encoder_reset (GConverter *converter)
|
||||||
@@ -134,7 +134,7 @@ g_base64_encoder_set_property (GObject *object,
|
|||||||
{
|
{
|
||||||
GBase64Encoder *encoder = G_BASE64_ENCODER (object);
|
GBase64Encoder *encoder = G_BASE64_ENCODER (object);
|
||||||
|
|
||||||
switch (prop_id)
|
switch ((GBase64EncoderProperty) prop_id)
|
||||||
{
|
{
|
||||||
case PROP_BREAK_LINES:
|
case PROP_BREAK_LINES:
|
||||||
encoder->break_lines = g_value_get_boolean (value);
|
encoder->break_lines = g_value_get_boolean (value);
|
||||||
@@ -154,7 +154,7 @@ g_base64_encoder_get_property (GObject *object,
|
|||||||
{
|
{
|
||||||
GBase64Encoder *encoder = G_BASE64_ENCODER (object);
|
GBase64Encoder *encoder = G_BASE64_ENCODER (object);
|
||||||
|
|
||||||
switch (prop_id)
|
switch ((GBase64EncoderProperty) prop_id)
|
||||||
{
|
{
|
||||||
case PROP_BREAK_LINES:
|
case PROP_BREAK_LINES:
|
||||||
g_value_set_boolean (value, encoder->break_lines);
|
g_value_set_boolean (value, encoder->break_lines);
|
||||||
@@ -182,6 +182,8 @@ g_base64_encoder_class_init (GBase64EncoderClass *klass)
|
|||||||
* This is typically used when putting base64-encoded data in emails.
|
* This is typically used when putting base64-encoded data in emails.
|
||||||
* It breaks the lines at 72 columns instead of putting all of the text on
|
* It breaks the lines at 72 columns instead of putting all of the text on
|
||||||
* the same line. This avoids problems with long lines in the email system.
|
* the same line. This avoids problems with long lines in the email system.
|
||||||
|
*
|
||||||
|
* Since: 2.82
|
||||||
*/
|
*/
|
||||||
g_object_class_install_property (gobject_class,
|
g_object_class_install_property (gobject_class,
|
||||||
PROP_BREAK_LINES,
|
PROP_BREAK_LINES,
|
||||||
@@ -203,7 +205,7 @@ g_base64_encoder_class_init (GBase64EncoderClass *klass)
|
|||||||
* instead of putting all of the text on the same line. This avoids
|
* instead of putting all of the text on the same line. This avoids
|
||||||
* problems with long lines in the email system.
|
* problems with long lines in the email system.
|
||||||
*
|
*
|
||||||
* Returns: a new `GBase64Encoder`
|
* Returns: (transfer full): a new `GBase64Encoder`
|
||||||
*
|
*
|
||||||
* Since: 2.82
|
* Since: 2.82
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -640,6 +640,8 @@ gio_headers = files(
|
|||||||
'gappinfo.h',
|
'gappinfo.h',
|
||||||
'gasyncinitable.h',
|
'gasyncinitable.h',
|
||||||
'gasyncresult.h',
|
'gasyncresult.h',
|
||||||
|
'gbase64decoder.h',
|
||||||
|
'gbase64encoder.h',
|
||||||
'gbufferedinputstream.h',
|
'gbufferedinputstream.h',
|
||||||
'gbufferedoutputstream.h',
|
'gbufferedoutputstream.h',
|
||||||
'gbytesicon.h',
|
'gbytesicon.h',
|
||||||
|
|||||||
@@ -1217,8 +1217,8 @@ test_converter_base64 (void)
|
|||||||
|
|
||||||
flags = G_OUTPUT_STREAM_SPLICE_CLOSE_SOURCE | G_OUTPUT_STREAM_SPLICE_CLOSE_TARGET;
|
flags = G_OUTPUT_STREAM_SPLICE_CLOSE_SOURCE | G_OUTPUT_STREAM_SPLICE_CLOSE_TARGET;
|
||||||
size = g_output_stream_splice (converter, input, flags, NULL, &error);
|
size = g_output_stream_splice (converter, input, flags, NULL, &error);
|
||||||
g_assert_true (size != -1);
|
|
||||||
g_assert_no_error (error);
|
g_assert_no_error (error);
|
||||||
|
g_assert_cmpint (size, !=, -1);
|
||||||
|
|
||||||
result = g_memory_output_stream_steal_data (G_MEMORY_OUTPUT_STREAM (output));
|
result = g_memory_output_stream_steal_data (G_MEMORY_OUTPUT_STREAM (output));
|
||||||
g_assert_cmpstr (encoded, ==, result);
|
g_assert_cmpstr (encoded, ==, result);
|
||||||
@@ -1237,8 +1237,8 @@ test_converter_base64 (void)
|
|||||||
|
|
||||||
flags = G_OUTPUT_STREAM_SPLICE_CLOSE_SOURCE | G_OUTPUT_STREAM_SPLICE_CLOSE_TARGET;
|
flags = G_OUTPUT_STREAM_SPLICE_CLOSE_SOURCE | G_OUTPUT_STREAM_SPLICE_CLOSE_TARGET;
|
||||||
size = g_output_stream_splice (output, converter2, flags, NULL, &error);
|
size = g_output_stream_splice (output, converter2, flags, NULL, &error);
|
||||||
g_assert_true (size != -1);
|
|
||||||
g_assert_no_error (error);
|
g_assert_no_error (error);
|
||||||
|
g_assert_cmpint (size, !=, -1);
|
||||||
|
|
||||||
result = g_memory_output_stream_steal_data (G_MEMORY_OUTPUT_STREAM (output));
|
result = g_memory_output_stream_steal_data (G_MEMORY_OUTPUT_STREAM (output));
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user