mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 07:17:35 +00:00
AK: Add String::join
This commit is contained in:
parent
79aaa2fe0f
commit
cccaa94767
3 changed files with 33 additions and 1 deletions
|
@ -14,6 +14,7 @@
|
|||
#include <AK/Optional.h>
|
||||
#include <AK/RefCounted.h>
|
||||
#include <AK/Span.h>
|
||||
#include <AK/StringBuilder.h>
|
||||
#include <AK/StringUtils.h>
|
||||
#include <AK/StringView.h>
|
||||
#include <AK/Traits.h>
|
||||
|
@ -185,6 +186,14 @@ public:
|
|||
return vformatted(fmtstr.view(), variadic_format_parameters);
|
||||
}
|
||||
|
||||
template<class SeparatorType, class CollectionType>
|
||||
static ErrorOr<String> join(SeparatorType const& separator, CollectionType const& collection, StringView fmtstr = "{}"sv)
|
||||
{
|
||||
StringBuilder builder;
|
||||
TRY(builder.try_join(separator, collection, fmtstr));
|
||||
return builder.to_string();
|
||||
}
|
||||
|
||||
// NOTE: This is primarily interesting to unit tests.
|
||||
[[nodiscard]] bool is_short_string() const;
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue