1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: interface of global functions
4 // Author: wxWidgets team
6 // Licence: wxWindows license
7 /////////////////////////////////////////////////////////////////////////////
10 // ============================================================================
11 // Global functions/macros
12 // ============================================================================
14 /** @addtogroup group_funcmacro_misc */
18 Elements of this enum specify the possible behaviours of wxBase64Decode
19 when an invalid character is encountered.
21 enum wxBase64DecodeMode
23 wxBase64DecodeMode_Strict
, ///< Normal behaviour: stop at any invalid characters.
24 wxBase64DecodeMode_SkipWS
, ///< Skip whitespace characters.
25 wxBase64DecodeMode_Relaxed
///< The most lenient behaviour: simply ignore all invalid characters.
29 This function encodes the given data using base64.
31 To allocate the buffer of the correct size, use wxBase64EncodedSize() or
32 call this function with @a dst set to @NULL -- it will then return the
33 necessary buffer size.
35 This raw encoding function overload writes the output string into the
36 provided buffer; the other overloads return it as a wxString.
39 The output buffer, may be @NULL to retrieve the needed buffer size.
41 The output buffer size, ignored if dst is @NULL.
43 The input buffer, must not be @NULL.
45 The length of the input data.
47 @return @c wxCONV_FAILED if the output buffer is too small.
51 size_t wxBase64Encode(char* dst
, size_t dstLen
,
56 This function encodes the given data using base64 and returns the output as
59 There is no error return.
61 To allocate the buffer of the correct size, use wxBase64EncodedSize() or
62 call this function with @a dst set to @NULL -- it will then return the
63 necessary buffer size.
66 The input buffer, must not be @NULL.
68 The length of the input data.
72 wxString
wxBase64Encode(const void* src
, size_t srcLen
);
75 This function encodes the given data using base64 and returns the output as
78 There is no error return.
82 wxString
wxBase64Encode(const wxMemoryBuffer
& buf
);
86 Returns the size of the buffer necessary to contain the data encoded in a
87 base64 string of length @e srcLen. This can be useful for allocating a
88 buffer to be passed to wxBase64Decode().
92 size_t wxBase64DecodedSize(size_t srcLen
);
95 Returns the length of the string with base64 representation of a buffer of
96 specified size @e len. This can be useful for allocating the buffer passed
101 size_t wxBase64EncodedSize(size_t len
);
104 This function decodes a Base64-encoded string.
106 This overload is a raw decoding function and decodes the data into the
107 provided buffer @a dst of the given size @e dstLen. An error is returned if
108 the buffer is not large enough -- that is not at least
109 wxBase64DecodedSize(srcLen) bytes.
111 This overload returns the number of bytes written to the buffer or the
112 necessary buffer size if @a dst was @NULL or @c wxCONV_FAILED on error,
113 e.g. if the output buffer is too small or invalid characters were
114 encountered in the input string.
117 Pointer to output buffer, may be @NULL to just compute the necessary
120 The size of the output buffer, ignored if dst is @NULL.
122 The input string, must not be @NULL. For the version using wxString,
123 the input string should contain only ASCII characters.
125 The length of the input string or special value wxNO_LEN if the string
126 is @NULL-terminated and the length should be computed by this function
129 This parameter specifies the function behaviour when invalid characters
130 are encountered in input. By default, any such character stops the
131 decoding with error. If the mode is wxBase64DecodeMode_SkipWS, then the
132 white space characters are silently skipped instead. And if it is
133 wxBase64DecodeMode_Relaxed, then all invalid characters are skipped.
135 If this pointer is non-@NULL and an error occurs during decoding, it is
136 filled with the index of the invalid character.
140 size_t wxBase64Decode(void* dst
, size_t dstLen
,
142 size_t srcLen
= wxNO_LEN
,
143 wxBase64DecodeMode mode
= wxBase64DecodeMode_Strict
,
144 size_t *posErr
= NULL
);
147 See the wxBase64Decode(void*,size_t,const char*,size_t,wxBase64DecodeMode,size_t*)
148 overload for more info about the parameters of this function.
150 This overload allocates memory internally and returns it as wxMemoryBuffer
151 and is recommended for normal use.
153 This overload returns a buffer with the base64 decoded binary equivalent
154 of the input string. In neither case is the buffer @NULL-terminated.
158 wxMemoryBuffer
wxBase64Decode(const char* src
,
159 size_t srcLen
= wxNO_LEN
,
160 wxBase64DecodeMode mode
= wxBase64DecodeMode_Strict
,
161 size_t *posErr
= NULL
);
164 See the wxBase64Decode(void*,size_t,const char*,size_t,wxBase64DecodeMode,size_t*)
165 overload for more info about the parameters of this function.
167 This overload takes as input a wxString and returns the internally-allocated
168 memory as a wxMemoryBuffer, containing the base64 decoded data.
172 wxMemoryBuffer
wxBase64Decode(const wxString
& src
,
173 wxBase64DecodeMode mode
= wxBase64DecodeMode_Strict
,
174 size_t *posErr
= NULL
);