-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathToStringHelper.cs
More file actions
52 lines (39 loc) · 1.15 KB
/
Copy pathToStringHelper.cs
File metadata and controls
52 lines (39 loc) · 1.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
// Copyright Subatomix Research Inc.
// SPDX-License-Identifier: MIT
using System.Text;
namespace DependencyQueue;
internal static class ToStringHelper
{
public const string
Separator = ", ",
EmptyPlaceholder = "none";
internal static int GetJoinedLength(
this IEnumerable<string> strings)
{
using var enumerator = strings.GetEnumerator();
if (!enumerator.MoveNext())
return EmptyPlaceholder.Length;
for (var length = 0;;)
{
length += enumerator.Current.Length;
if (!enumerator.MoveNext())
return length;
length += Separator.Length;
}
}
internal static StringBuilder AppendJoined(
this StringBuilder builder,
IEnumerable<string> strings)
{
using var enumerator = strings.GetEnumerator();
if (!enumerator.MoveNext())
return builder.Append(EmptyPlaceholder);
for (;;)
{
builder.Append(enumerator.Current);
if (!enumerator.MoveNext())
return builder;
builder.Append(Separator);
}
}
}