Ark Server API (ASA) - Wiki
Loading...
Searching...
No Matches
Join.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2
3#pragma once
4
5#include "CoreTypes.h"
6#include "Containers/StringView.h"
7#include "Misc/StringBuilder.h"
8#include "Templates/IdentityFunctor.h"
9#include "Templates/Invoke.h"
10
11namespace UE::String::Private
12{
13
14template <typename RangeType, typename ProjectionType, typename DelimiterType, typename QuoteType>
16{
17 RangeType&& Range;
18 ProjectionType Projection;
19 DelimiterType&& Delimiter;
20 QuoteType&& Quote;
21};
22
23template <typename RangeType, typename ProjectionType, typename DelimiterType>
24struct TJoinBy
25{
26 RangeType&& Range;
27 ProjectionType Projection;
28 DelimiterType&& Delimiter;
29};
30
31} // UE::String::Private
32
33namespace UE::String
34{
35
36/**
37 * Create an object that can be appended to a string builder to append every element of the range
38 * to the builder, separating the elements by the delimiter and surrounding every element on both
39 * sides with a quote.
40 *
41 * @param Range The range of elements to join and append.
42 * @param Projection The projection to apply to the elements before appending them.
43 * @param Delimiter The delimiter to append as a separator for the elements.
44 * @param Quote The quote to append on both sides of each element.
45 *
46 * @return An anonymous object to append to a string builder.
47 */
48template <typename RangeType, typename ProjectionType, typename DelimiterType, typename QuoteType>
49inline auto JoinQuotedBy(RangeType&& Range, ProjectionType Projection, DelimiterType&& Delimiter, QuoteType&& Quote)
50 -> Private::TJoinQuotedBy<RangeType, ProjectionType, DelimiterType, QuoteType>
51{
53}
54
55/**
56 * Append every element of the range to the builder, separating the elements by the delimiter, and
57 * surrounding every element on each side with the given quote.
58 *
59 * @param Range The range of elements to join and append.
60 * @param Projection The projection to apply to the elements before appending them.
61 * @param Delimiter The delimiter to append as a separator for the elements.
62 * @param Quote The quote to append on both sides of each element.
63 * @param Builder The builder to append to.
64 *
65 * @return The builder, to allow additional operations to be composed with this one.
66 */
67template <typename RangeType, typename ProjectionType, typename DelimiterType, typename QuoteType, typename CharType>
68inline TStringBuilderBase<CharType>& JoinQuotedByTo(
69 RangeType&& Range,
70 ProjectionType Projection,
71 DelimiterType&& Delimiter,
72 QuoteType&& Quote,
73 TStringBuilderBase<CharType>& Builder)
74{
75 bool bFirst = true;
76 for (auto&& Elem : Forward<RangeType>(Range))
77 {
78 if (bFirst)
79 {
80 bFirst = false;
81 }
82 else
83 {
85 }
87 }
88 return Builder;
89}
90
91/**
92 * Create an object that can be appended to a string builder to append every element of the range
93 * to the builder, separating the elements by the delimiter and surrounding every element on both
94 * sides with a quote.
95 *
96 * @param Range The range of elements to join and append.
97 * @param Delimiter The delimiter to append as a separator for the elements.
98 * @param Quote The quote to append on both sides of each element.
99 *
100 * @return An anonymous object to append to a string builder.
101 */
102template <typename RangeType, typename DelimiterType, typename QuoteType>
103inline auto JoinQuoted(RangeType&& Range, DelimiterType&& Delimiter, QuoteType&& Quote)
104 -> Private::TJoinQuotedBy<RangeType, FIdentityFunctor, DelimiterType, QuoteType>
105{
107}
108
109/**
110 * Append every element of the range to the builder, separating the elements by the delimiter, and
111 * surrounding every element on each side with the given quote.
112 *
113 * @param Range The range of elements to join and append.
114 * @param Delimiter The delimiter to append as a separator for the elements.
115 * @param Quote The quote to append on both sides of each element.
116 * @param Builder The builder to append to.
117 *
118 * @return The builder, to allow additional operations to be composed with this one.
119 */
120template <typename RangeType, typename DelimiterType, typename QuoteType, typename CharType>
121inline TStringBuilderBase<CharType>& JoinQuotedTo(
122 RangeType&& Range,
123 DelimiterType&& Delimiter,
124 QuoteType&& Quote,
125 TStringBuilderBase<CharType>& Builder)
126{
128}
129
130/**
131 * Create an object that can be appended to a string builder to append every element of the range
132 * to the builder, separating the elements by the delimiter.
133 *
134 * @param Range The range of elements to join and append.
135 * @param Projection The projection to apply to the elements before appending them.
136 * @param Delimiter The delimiter to append as a separator for the elements.
137 *
138 * @return An anonymous object to append to a string builder.
139 */
140template <typename RangeType, typename ProjectionType, typename DelimiterType>
141inline auto JoinBy(RangeType&& Range, ProjectionType Projection, DelimiterType&& Delimiter)
142 -> Private::TJoinBy<RangeType, ProjectionType, DelimiterType>
143{
145}
146
147/**
148 * Append every element of the range to the builder, separating the elements by the delimiter.
149 *
150 * @param Range The range of elements to join and append.
151 * @param Projection The projection to apply to the elements before appending them.
152 * @param Delimiter The delimiter to append as a separator for the elements.
153 * @param Builder The builder to append to.
154 *
155 * @return The builder, to allow additional operations to be composed with this one.
156 */
157template <typename RangeType, typename ProjectionType, typename DelimiterType, typename CharType>
158inline TStringBuilderBase<CharType>& JoinByTo(
159 RangeType&& Range,
160 ProjectionType Projection,
161 DelimiterType&& Delimiter,
162 TStringBuilderBase<CharType>& Builder)
163{
164 bool bFirst = true;
165 for (auto&& Elem : Forward<RangeType>(Range))
166 {
167 if (bFirst)
168 {
169 bFirst = false;
170 }
171 else
172 {
174 }
176 }
177 return Builder;
178}
179
180/**
181 * Create an object that can be appended to a string builder to append every element of the range
182 * to the builder, separating the elements by the delimiter.
183 *
184 * @param Range The range of elements to join and append.
185 * @param Delimiter The delimiter to append as a separator for the elements.
186 *
187 * @return An anonymous object to append to a string builder.
188 */
189template <typename RangeType, typename DelimiterType>
190inline auto Join(RangeType&& Range, DelimiterType&& Delimiter)
191 -> Private::TJoinBy<RangeType, FIdentityFunctor, DelimiterType>
192{
194}
195
196/**
197 * Append every element of the range to the builder, separating the elements by the delimiter.
198 *
199 * @param Range The range of elements to join and append.
200 * @param Delimiter The delimiter to append as a separator for the elements.
201 * @param Builder The builder to append to.
202 *
203 * @return The builder, to allow additional operations to be composed with this one.
204 */
205template <typename RangeType, typename DelimiterType, typename CharType>
206inline TStringBuilderBase<CharType>& JoinTo(RangeType&& Range, DelimiterType&& Delimiter, TStringBuilderBase<CharType>& Builder)
207{
209}
210
211} // UE::String
212
213namespace UE::String::Private
214{
215
216template <typename RangeType, typename ProjectionType, typename DelimiterType, typename QuoteType, typename CharType>
217inline TStringBuilderBase<CharType>& operator<<(
218 TStringBuilderBase<CharType>& Builder,
219 Private::TJoinQuotedBy<RangeType, ProjectionType, DelimiterType, QuoteType>&& Adapter)
220{
221 return JoinQuotedByTo(
226 Builder);
227}
228
229template <typename RangeType, typename ProjectionType, typename DelimiterType, typename CharType>
230inline TStringBuilderBase<CharType>& operator<<(
231 TStringBuilderBase<CharType>& Builder,
232 Private::TJoinBy<RangeType, ProjectionType, DelimiterType>&& Adapter)
233{
235}
236
237} // UE::String::Private
auto JoinQuotedBy(RangeType &&Range, ProjectionType Projection, DelimiterType &&Delimiter, QuoteType &&Quote) -> Private::TJoinQuotedBy< RangeType, ProjectionType, DelimiterType, QuoteType >
Definition Join.h:49
TStringBuilderBase< CharType > & JoinQuotedTo(RangeType &&Range, DelimiterType &&Delimiter, QuoteType &&Quote, TStringBuilderBase< CharType > &Builder)
Definition Join.h:121
auto JoinBy(RangeType &&Range, ProjectionType Projection, DelimiterType &&Delimiter) -> Private::TJoinBy< RangeType, ProjectionType, DelimiterType >
Definition Join.h:141
TStringBuilderBase< CharType > & JoinByTo(RangeType &&Range, ProjectionType Projection, DelimiterType &&Delimiter, TStringBuilderBase< CharType > &Builder)
Definition Join.h:158
TStringBuilderBase< CharType > & JoinQuotedByTo(RangeType &&Range, ProjectionType Projection, DelimiterType &&Delimiter, QuoteType &&Quote, TStringBuilderBase< CharType > &Builder)
Definition Join.h:68
auto Join(RangeType &&Range, DelimiterType &&Delimiter) -> Private::TJoinBy< RangeType, FIdentityFunctor, DelimiterType >
Definition Join.h:190
auto JoinQuoted(RangeType &&Range, DelimiterType &&Delimiter, QuoteType &&Quote) -> Private::TJoinQuotedBy< RangeType, FIdentityFunctor, DelimiterType, QuoteType >
Definition Join.h:103
TStringBuilderBase< CharType > & JoinTo(RangeType &&Range, DelimiterType &&Delimiter, TStringBuilderBase< CharType > &Builder)
Definition Join.h:206
Definition Vector.h:40
DelimiterType && Delimiter
Definition Join.h:28
ProjectionType Projection
Definition Join.h:27
DelimiterType && Delimiter
Definition Join.h:19