add char** overloads for join_string
[libi2ncommon] / src / stringfunc.cpp
index 3813a1c..72de728 100644 (file)
@@ -479,6 +479,30 @@ std::string join_string(
    return result;
 } // eo join_string(const std::vector< std::string >&,const std::string&)
 
+std::string join_string (
+   const char *const parts[], /* assumed NULL-terminated */
+   const std::string& delimiter
+)
+{
+   std::string result;
+
+   if (parts != NULL)
+   {
+       const char *const *cur = parts;
+
+       if (*cur != NULL) {
+           result = std::string (*cur);
+
+           while (*++cur != NULL) {
+               result += delimiter;
+               result += std::string (*cur);
+           }
+       }
+   }
+
+   return result;
+}
+
 
 
 /*
@@ -712,9 +736,10 @@ static std::string _convert_BIO_to_string(BIO *input)
     * Data size limit is 2GB on 32 bit (LONG_MAX)
     *
     * @param input String to encode
+    * @param one_line Encode all data as one line, no wrapping with line feeds
     * @return base64 encoded string
     */
-std::string base64_encode(const std::string &input)
+std::string base64_encode(const std::string &input, bool one_line)
 {
     // check for empty buffer
     if (input.empty())
@@ -727,7 +752,8 @@ std::string base64_encode(const std::string &input)
     // setup encoder. Note: BIO_free_all frees both BIOs.
     BIO_Ptr base64_encoder(BIO_new(BIO_f_base64()), BIO_free_all);
     BIO *encoder_bio = base64_encoder.get();
-    BIO_set_flags(encoder_bio, BIO_FLAGS_BASE64_NO_NL);
+    if (one_line)
+        BIO_set_flags(encoder_bio, BIO_FLAGS_BASE64_NO_NL);
 
     // chain output buffer and encoder together
     BIO *encoded_result = BIO_new(BIO_s_mem());
@@ -752,9 +778,10 @@ std::string base64_encode(const std::string &input)
     * @brief base64 decode a string using OpenSSL base64 functions
     *
     * @param input String to decode
+    * @param one_line Expect all base64 data in one line. Input with line feeds will fail.
     * @return base64 decoded string
     */
-std::string base64_decode(const std::string &input)
+std::string base64_decode(const std::string &input, bool one_line)
 {
     // check for empty buffer
     if (input.empty())
@@ -767,7 +794,8 @@ std::string base64_decode(const std::string &input)
     // setup encoder. Note: BIO_free_all frees both BIOs.
     BIO_Ptr base64_decoder(BIO_new(BIO_f_base64()), BIO_free_all);
     BIO *bio_base64 = base64_decoder.get();
-    BIO_set_flags(bio_base64, BIO_FLAGS_BASE64_NO_NL);
+    if (one_line)
+        BIO_set_flags(bio_base64, BIO_FLAGS_BASE64_NO_NL);
 
     // chain input buffer and decoder together
     BIO *bio_input = BIO_new_mem_buf((void*)input.c_str(), input.size());