changeset 243:73e5381d7baf

Base64: return output #291
author David Demelier <markand@malikania.fr>
date Sat, 13 Sep 2014 10:27:41 +0200
parents a9883eeb9757
children 777bc3cb665a
files C++/Base64.h
diffstat 1 files changed, 10 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/C++/Base64.h	Thu Sep 11 21:09:58 2014 +0200
+++ b/C++/Base64.h	Sat Sep 13 10:27:41 2014 +0200
@@ -54,10 +54,11 @@
 	 *
 	 * @param input the beginning
 	 * @param end the end of the data
-	 * @output the output destination
+	 * @param output the output destination
+	 * @return output
 	 */
 	template <typename InputIt, typename OutputIt>
-	static void encode(InputIt input, InputIt end, OutputIt output)
+	static OutputIt encode(InputIt input, InputIt end, OutputIt output)
 	{
 		while (input != end) {
 			char inputbuf[3] = { 0, 0, 0 };
@@ -71,6 +72,8 @@
 			*output++ = (count < 2) ? '=' : lookup((inputbuf[1] << 2 & 0x3c) | (inputbuf[2] >> 6 & 0x03));
 			*output++ = (count < 3) ? '=' : lookup(inputbuf[2] & 0x3f);
 		}
+
+		return output;
 	}
 
 	/**
@@ -80,11 +83,12 @@
 	 *
 	 * @param input the beginning
 	 * @param end the end of the data
-	 * @output the output destination
+	 * @param output the output destination
+	 * @return output
 	 * @throw std::invalid_argument on bad base64 string
 	 */
 	template <typename InputIt, typename OutputIt>
-	static void decode(InputIt input, InputIt end, OutputIt output)
+	static OutputIt decode(InputIt input, InputIt end, OutputIt output)
 	{
 		while (input != end) {
 			char inputbuf[4] = { 0, 0, 0, 0 };
@@ -105,6 +109,8 @@
 			if (inputbuf[3] != '=')
 				*output++ = (inputbuf[2] << 6 & 0xc0) | (inputbuf[3] & 0x3f);
 		}
+
+		return output;
 	}
 
 	/**