]> git.saurik.com Git - wxWidgets.git/commitdiff
Add wxBase64Decode(void*,size_t,wxString) overload.
authorVadim Zeitlin <vadim@wxwidgets.org>
Wed, 11 Nov 2009 14:38:40 +0000 (14:38 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Wed, 11 Nov 2009 14:38:40 +0000 (14:38 +0000)
We had wxBase64Decode(void*,size_t,const char*,size_t) as well as
wxBase64Decode(const char*,size_t) and wxBase64Decode(wxString) already but
not a version taking the buffer and wxString, complete the set of overloads
now.

This allows the unit test to compile in STL build (where there is no implicit
conversion from wxString to const char *).

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@62614 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

include/wx/base64.h
interface/wx/base64.h

index 7d5c72637e56c0aa94a2e6d6f245b2263aeba74e..1632e60e7effe83a1be51b0e309cc802865a351b 100644 (file)
@@ -89,6 +89,17 @@ wxBase64Decode(void *dst, size_t dstLen,
                wxBase64DecodeMode mode = wxBase64DecodeMode_Strict,
                size_t *posErr = NULL);
 
+inline size_t
+wxBase64Decode(void *dst, size_t dstLen,
+               const wxString& src,
+               wxBase64DecodeMode mode = wxBase64DecodeMode_Strict,
+               size_t *posErr = NULL)
+{
+    // don't use str.length() here as the ASCII buffer is shorter than it for
+    // strings with embedded NULs
+    return wxBase64Decode(dst, dstLen, src.ToAscii(), wxNO_LEN, mode, posErr);
+}
+
 // decode the contents of the given string; the returned buffer is empty if an
 // error occurs during decoding
 WXDLLIMPEXP_BASE wxMemoryBuffer
index f72320ee9f936bb640e01ca4e3aace0694083ae1..a5b0adb15b6dbfa72b5ff3f163cd427d5bcbfc5c 100644 (file)
@@ -145,14 +145,30 @@ size_t wxBase64Decode(void* dst, size_t dstLen,
                       size_t *posErr = NULL);
 
 /**
+    Decode a Base64-encoded wxString.
+
     See the wxBase64Decode(void*,size_t,const char*,size_t,wxBase64DecodeMode,size_t*)
-    overload for more info about the parameters of this function.
+    overload for more information about the parameters of this function, the
+    only difference between it and this one is that a wxString is used instead
+    of a @c char* pointer and its length.
+
+    @since 2.9.1
+
+    @header{wx/base64.h}
+ */
+size_t wxBase64Decode(void* dst, size_t dstLen,
+                      const wxString& str,
+                      wxBase64DecodeMode mode = wxBase64DecodeMode_Strict,
+                      size_t *posErr = NULL);
 
-    This overload allocates memory internally and returns it as wxMemoryBuffer
-    and is recommended for normal use.
+/**
+    Decode a Base64-encoded string and return decoded contents in a buffer.
 
-    This overload returns a buffer with the base64 decoded binary equivalent
-    of the input string. In neither case is the buffer @NULL-terminated.
+    See the wxBase64Decode(void*,size_t,const char*,size_t,wxBase64DecodeMode,size_t*)
+    overload for more information about the parameters of this function. The
+    difference of this overload is that it allocates a buffer of necessary size
+    on its own and returns it, freeing you from the need to do it manually.
+    Because of this, it is simpler to use and is recommended for normal use.
 
     @header{wx/base64.h}
 */
@@ -162,11 +178,13 @@ wxMemoryBuffer wxBase64Decode(const char* src,
                               size_t *posErr = NULL);
 
 /**
+    Decode a Base64-encoded wxString and return decoded contents in a buffer.
+
     See the wxBase64Decode(void*,size_t,const char*,size_t,wxBase64DecodeMode,size_t*)
-    overload for more info about the parameters of this function.
+    overload for more information about the parameters of this function.
 
     This overload takes as input a wxString and returns the internally-allocated
-    memory as a wxMemoryBuffer, containing the base64 decoded data.
+    memory as a wxMemoryBuffer, containing the Base64-decoded data.
 
     @header{wx/base64.h}
 */