From 7c0c08627cc18fc82a98ddb0bc8adbb482d35144 Mon Sep 17 00:00:00 2001 From: Czarek Nakamoto Date: Fri, 19 Apr 2024 16:25:05 +0200 Subject: [PATCH] make vectorToString behave as it should, without appending separators when it isn't required --- monero_libwallet2_api_c/src/main/cpp/helpers.cpp | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/monero_libwallet2_api_c/src/main/cpp/helpers.cpp b/monero_libwallet2_api_c/src/main/cpp/helpers.cpp index d77995b..d4ca540 100644 --- a/monero_libwallet2_api_c/src/main/cpp/helpers.cpp +++ b/monero_libwallet2_api_c/src/main/cpp/helpers.cpp @@ -11,12 +11,19 @@ #include const char* vectorToString(const std::vector& vec, const std::string separator) { + // Check if the vector is empty + if (vec.empty()) { + return ""; + } + // Concatenate all strings in the vector std::string result; - for (const auto& str : vec) { - result += str; + for (size_t i = 0; i < vec.size() - 1; ++i) { + result += vec[i]; result += separator; } + result += vec.back(); // Append the last string without the separator + const char* cstr = result.c_str(); return cstr; }