mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-12-04 13:30:31 +00:00
AK: Add optional format string parameter to String{,Builder}::join()
Allow specifying a custom format string that's being used for each item instead of hardcoding "{}".
This commit is contained in:
parent
f8ff8c8dd6
commit
b253bca807
Notes:
sideshowbarker
2024-07-17 18:21:16 +09:00
Author: https://github.com/linusg Commit: https://github.com/SerenityOS/serenity/commit/b253bca807 Pull-request: https://github.com/SerenityOS/serenity/pull/12736 Reviewed-by: https://github.com/davidot ✅
2 changed files with 4 additions and 4 deletions
|
@ -102,10 +102,10 @@ public:
|
|||
[[nodiscard]] static String roman_number_from(size_t value);
|
||||
|
||||
template<class SeparatorType, class CollectionType>
|
||||
[[nodiscard]] static String join(const SeparatorType& separator, const CollectionType& collection)
|
||||
[[nodiscard]] static String join(const SeparatorType& separator, const CollectionType& collection, StringView fmtstr = "{}"sv)
|
||||
{
|
||||
StringBuilder builder;
|
||||
builder.join(separator, collection);
|
||||
builder.join(separator, collection, fmtstr);
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
|
|
|
@ -70,7 +70,7 @@ public:
|
|||
void trim(size_t count) { m_buffer.resize(m_buffer.size() - count); }
|
||||
|
||||
template<class SeparatorType, class CollectionType>
|
||||
void join(SeparatorType const& separator, CollectionType const& collection)
|
||||
void join(SeparatorType const& separator, CollectionType const& collection, StringView fmtstr = "{}"sv)
|
||||
{
|
||||
bool first = true;
|
||||
for (auto& item : collection) {
|
||||
|
@ -78,7 +78,7 @@ public:
|
|||
first = false;
|
||||
else
|
||||
append(separator);
|
||||
appendff("{}", item);
|
||||
appendff(fmtstr, item);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue