Skip to content

Commit

Permalink
Rename 'MinimalUtility.String' to 'MinimalUtility.BackPort'
Browse files Browse the repository at this point in the history
  • Loading branch information
kochounoyume committed Sep 23, 2024
1 parent 6e4e107 commit ed7d9b8
Show file tree
Hide file tree
Showing 28 changed files with 100 additions and 75 deletions.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace System.Runtime.CompilerServices
{
/// <summary>Indicates which arguments to a method involving an interpolated string handler should be passed to that handler.</summary>
[AttributeUsage(AttributeTargets.Parameter, AllowMultiple = false, Inherited = false)]
internal sealed class InterpolatedStringHandlerArgumentAttribute : Attribute
public sealed class InterpolatedStringHandlerArgumentAttribute : Attribute
{
/// <summary>Initializes a new instance of the <see cref="InterpolatedStringHandlerArgumentAttribute"/> class.</summary>
/// <param name="argument">The name of the argument that should be passed to the handler.</param>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace System.Runtime.CompilerServices
{
/// <summary>Indicates the attributed type is to be used as an interpolated string handler.</summary>
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct, AllowMultiple = false, Inherited = false)]
internal sealed class InterpolatedStringHandlerAttribute : Attribute
public sealed class InterpolatedStringHandlerAttribute : Attribute
{
/// <summary>Initializes the <see cref="InterpolatedStringHandlerAttribute"/>.</summary>
public InterpolatedStringHandlerAttribute() { }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "MinimalUtility.String",
"rootNamespace": "MinimalUtility.String",
"name": "MinimalUtility.BackPort",
"rootNamespace": "",
"references": [],
"includePlatforms": [],
"excludePlatforms": [],
Expand Down
68 changes: 0 additions & 68 deletions Packages/MinimalUtility/Runtime/String/StringUtils.Join.cs

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,11 @@
using System;
using System.Runtime.CompilerServices;

namespace MinimalUtility.String
namespace MinimalUtility
{
/// <summary>
/// 文字列を扱うための静的メソッド群を提供します.
/// </summary>
public static partial class StringUtils
{
/// <summary>Creates a new string by using the specified provider to control the formatting of the specified interpolated string.</summary>
Expand Down
90 changes: 90 additions & 0 deletions Packages/MinimalUtility/Runtime/StringUtils.Join.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
#nullable enable

using System;
using System.Buffers;
using System.Collections.Generic;
using System.Runtime.CompilerServices;

namespace MinimalUtility
{
/// <summary>
/// 文字列を扱うための静的メソッド群を提供します.
/// </summary>
public static partial class StringUtils
{
/// <summary>
/// 内部で<see cref="DefaultInterpolatedStringHandler"/>を使用した<see cref="string.Join(string,IEnumerable{string})"/>.
/// </summary>
/// <param name="separator">区切り文字列.</param>
/// <param name="values">連結する文字列のコレクション.</param>
/// <returns>連結された文字列.</returns>
/// <exception cref="ArgumentNullException"><paramref name="values"/>がnullの場合にスローされます.</exception>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static string Join(in string? separator, IEnumerable<string?> values) => Join(separator.AsSpan(), values);

/// <summary>
/// 内部で<see cref="DefaultInterpolatedStringHandler"/>を使用した<see cref="string.Join{T}(char,IEnumerable{T})"/>.
/// </summary>
/// <param name="separator">区切り文字.</param>
/// <param name="values">連結する文字列のコレクション.</param>
/// <returns>連結された文字列.</returns>
/// <exception cref="ArgumentNullException"><paramref name="values"/>がnullの場合にスローされます.</exception>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static string Join(in char separator, IEnumerable<string?> values)
{
char[] separatorArray = ArrayPool<char>.Shared.Rent(1);
separatorArray[0] = separator;
string result = Join(new ReadOnlySpan<char>(separatorArray), values);
ArrayPool<char>.Shared.Return(separatorArray);
return result;
}

/// <summary>
/// 内部で<see cref="DefaultInterpolatedStringHandler"/>を使用したstring.Join.
/// </summary>
/// <param name="separator">区切り文字列.</param>
/// <param name="values">連結する文字列のコレクション.</param>
/// <returns>連結された文字列.</returns>
/// <exception cref="ArgumentNullException"><paramref name="values"/>がnullの場合にスローされます.</exception>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static string Join(in ReadOnlySpan<char> separator, IEnumerable<string?> values)
{
if (values == null)
{
throw new ArgumentNullException(nameof(values));
}

using IEnumerator<string?> en = values.GetEnumerator();
if (!en.MoveNext())
{
return "";
}

string? firstValue = en.Current;

if (!en.MoveNext())
{
return firstValue ?? "";
}

DefaultInterpolatedStringHandler result = new ();

if (firstValue != null)
{
result.AppendLiteral(firstValue);
}

do
{
result.AppendFormatted(separator);
if (en.Current != null)
{
result.AppendLiteral(en.Current);
}
}
while (en.MoveNext());

return result.ToString();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "MinimalUtility.WebRequest",
"rootNamespace": "MinimalUtility.WebRequest",
"references": [
"GUID:eb014bd0dae606c44a234c52ffeb53e2",
"GUID:2294a65d721f9974ca66d13b434e6b7b",
"GUID:f51ebe6a0ceec4240a699833d6309b23"
],
"includePlatforms": [],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ protected override async System.Threading.Tasks.Task<HttpResponseMessage> SendAs

foreach (var (key, values) in requestMessage.Headers)
{
webRequest.SetRequestHeader(key, String.StringUtils.Join(',', values));
webRequest.SetRequestHeader(key, StringUtils.Join(',', values));
}

await webRequest.SendWebRequest().WithCancellation(cancellationToken);
Expand Down

0 comments on commit ed7d9b8

Please sign in to comment.