diff options
| author | Czarek Nakamoto <cyjan@mrcyjanek.net> | 2024-04-19 16:25:05 +0200 |
|---|---|---|
| committer | Czarek Nakamoto <cyjan@mrcyjanek.net> | 2024-04-19 16:25:05 +0200 |
| commit | 7c0c08627cc18fc82a98ddb0bc8adbb482d35144 (patch) | |
| tree | c5fae818ac6b4882565a844f3c7a8c1d6287268c | |
| parent | a1d03a28a7e7c10c6a51d3e1de3d6a1fcd24ce30 (diff) | |
make vectorToString behave as it should, without appending separators when it isn't required
| -rw-r--r-- | monero_libwallet2_api_c/src/main/cpp/helpers.cpp | 11 |
1 files 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 <cstring> const char* vectorToString(const std::vector<std::string>& 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; } |
