11using System . Runtime . CompilerServices ;
2+ using System . Text ;
23
34namespace LinkDotNet . StringBuilder ;
45
@@ -8,7 +9,7 @@ public ref partial struct ValueStringBuilder
89 /// Concatenates and appends all values with the given separator between each entry at the end of the string.
910 /// </summary>
1011 /// <param name="separator">String used as separator between the entries.</param>
11- /// <param name="values">Array of strings, which will be concatenated.</param>
12+ /// <param name="values">Enumerable of strings to be concatenated.</param>
1213 [ MethodImpl ( MethodImplOptions . AggressiveInlining ) ]
1314 public void AppendJoin ( ReadOnlySpan < char > separator , IEnumerable < string ? > values )
1415 => AppendJoinInternalString ( separator , values ) ;
@@ -17,17 +18,26 @@ public void AppendJoin(ReadOnlySpan<char> separator, IEnumerable<string?> values
1718 /// Concatenates and appends all values with the given separator between each entry at the end of the string.
1819 /// </summary>
1920 /// <param name="separator">Character used as separator between the entries.</param>
20- /// <param name="values">Array of strings, which will be concatenated.</param>
21+ /// <param name="values">Enumerable of strings to be concatenated.</param>
2122 [ MethodImpl ( MethodImplOptions . AggressiveInlining ) ]
2223 public void AppendJoin ( char separator , IEnumerable < string ? > values )
2324 => AppendJoinInternalChar ( separator , values ) ;
2425
26+ /// <summary>
27+ /// Concatenates and appends all values with the given separator between each entry at the end of the string.
28+ /// </summary>
29+ /// <param name="separator">Rune used as separator between the entries.</param>
30+ /// <param name="values">Enumerable of strings to be concatenated.</param>
31+ [ MethodImpl ( MethodImplOptions . AggressiveInlining ) ]
32+ public void AppendJoin ( Rune separator , IEnumerable < string ? > values )
33+ => AppendJoinInternalRune ( separator , values ) ;
34+
2535 /// <summary>
2636 /// Concatenates and appends all values with the given separator between each entry at the end of the string.
2737 /// </summary>
2838 /// <param name="separator">String used as separator between the entries.</param>
29- /// <param name="values">Array of strings, which will be concatenated.</param>
30- /// <typeparam name="T">Type of the given array .</typeparam>
39+ /// <param name="values">Enumerable to be concatenated.</param>
40+ /// <typeparam name="T">Type of the given enumerable .</typeparam>
3141 [ MethodImpl ( MethodImplOptions . AggressiveInlining ) ]
3242 public void AppendJoin < T > ( ReadOnlySpan < char > separator , IEnumerable < T > values )
3343 => AppendJoinInternalString ( separator , values ) ;
@@ -36,12 +46,22 @@ public void AppendJoin<T>(ReadOnlySpan<char> separator, IEnumerable<T> values)
3646 /// Concatenates and appends all values with the given separator between each entry at the end of the string.
3747 /// </summary>
3848 /// <param name="separator">Character used as separator between the entries.</param>
39- /// <param name="values">Array of strings, which will be concatenated.</param>
40- /// <typeparam name="T">Type of the given array .</typeparam>
49+ /// <param name="values">Enumerable to be concatenated.</param>
50+ /// <typeparam name="T">Type of the given enumerable .</typeparam>
4151 [ MethodImpl ( MethodImplOptions . AggressiveInlining ) ]
4252 public void AppendJoin < T > ( char separator , IEnumerable < T > values )
4353 => AppendJoinInternalChar ( separator , values ) ;
4454
55+ /// <summary>
56+ /// Concatenates and appends all values with the given separator between each entry at the end of the string.
57+ /// </summary>
58+ /// <param name="separator">Rune used as separator between the entries.</param>
59+ /// <param name="values">Enumerable to be concatenated.</param>
60+ /// <typeparam name="T">Type of the given enumerable.</typeparam>
61+ [ MethodImpl ( MethodImplOptions . AggressiveInlining ) ]
62+ public void AppendJoin < T > ( Rune separator , IEnumerable < T > values )
63+ => AppendJoinInternalRune ( separator , values ) ;
64+
4565 [ MethodImpl ( MethodImplOptions . AggressiveInlining ) ]
4666 private void AppendJoinInternalString < T > ( ReadOnlySpan < char > separator , IEnumerable < T > values )
4767 {
@@ -55,10 +75,7 @@ private void AppendJoinInternalString<T>(ReadOnlySpan<char> separator, IEnumerab
5575 }
5676
5777 var current = enumerator . Current ;
58- if ( current is not null )
59- {
60- AppendInternal ( current ) ;
61- }
78+ AppendInternal ( current ) ;
6279
6380 while ( enumerator . MoveNext ( ) )
6481 {
@@ -91,6 +108,29 @@ private void AppendJoinInternalChar<T>(char separator, IEnumerable<T> values)
91108 }
92109 }
93110
111+ [ MethodImpl ( MethodImplOptions . AggressiveInlining ) ]
112+ private void AppendJoinInternalRune < T > ( Rune separator , IEnumerable < T > values )
113+ {
114+ ArgumentNullException . ThrowIfNull ( values ) ;
115+
116+ using var enumerator = values . GetEnumerator ( ) ;
117+
118+ if ( ! enumerator . MoveNext ( ) )
119+ {
120+ return ;
121+ }
122+
123+ var current = enumerator . Current ;
124+ AppendInternal ( current ) ;
125+
126+ while ( enumerator . MoveNext ( ) )
127+ {
128+ Append ( separator ) ;
129+ current = enumerator . Current ;
130+ AppendInternal ( current ) ;
131+ }
132+ }
133+
94134 [ MethodImpl ( MethodImplOptions . AggressiveInlining ) ]
95135 private void AppendInternal < T > ( T value )
96136 {
0 commit comments