Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions src/util/string_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ Author: Daniel Poetzl
#ifndef CPROVER_UTIL_STRING_UTILS_H
#define CPROVER_UTIL_STRING_UTILS_H

#include <ostream>
#include <string>
#include <vector>

Expand All @@ -33,4 +34,31 @@ std::string trim_from_last_delimiter(
const std::string &s,
const char delim);

/// Prints items to an stream, separated by a constant delimiter
/// \tparam It An iterator type
/// \tparam Delimiter A delimiter type which supports printing to ostreams
/// \param os An ostream to write to
/// \param b Iterator pointing to first item to print
/// \param e Iterator pointing past last item to print
/// \param delimiter Object to print between each item in the iterator range
/// \return A reference to the ostream that was passed in
template<typename Stream, typename It, typename Delimiter>
Stream &join_strings(
Stream &os,
const It b,
const It e,
const Delimiter &delimiter)
{
if(b==e)
{
return os;
}
os << *b;
for(auto it=std::next(b); it!=e; ++it)
{
os << delimiter << *it;
}
return os;
}

#endif