Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/System.Memory/ref/System.Memory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@ public static void Reverse<T>(this System.Span<T> span) { }
public static bool StartsWith(this System.ReadOnlySpan<char> span, System.ReadOnlySpan<char> value, System.StringComparison comparisonType) { throw null; }
public static bool StartsWith<T>(this System.ReadOnlySpan<T> span, System.ReadOnlySpan<T> value) where T : System.IEquatable<T> { throw null; }
public static bool StartsWith<T>(this System.Span<T> span, System.ReadOnlySpan<T> value) where T : System.IEquatable<T> { throw null; }
public static int ToLower(this System.ReadOnlySpan<char> source, System.Span<char> destination, System.Globalization.CultureInfo culture) { throw null; }
public static int ToLowerInvariant(this System.ReadOnlySpan<char> source, System.Span<char> destination) { throw null; }
public static int ToUpper(this System.ReadOnlySpan<char> source, System.Span<char> destination, System.Globalization.CultureInfo culture) { throw null; }
public static int ToUpperInvariant(this System.ReadOnlySpan<char> source, System.Span<char> destination) { throw null; }
public static System.ReadOnlySpan<char> Trim(this System.ReadOnlySpan<char> span) { throw null; }
public static System.ReadOnlySpan<char> Trim(this System.ReadOnlySpan<char> span, char trimChar) { throw null; }
public static System.ReadOnlySpan<char> Trim(this System.ReadOnlySpan<char> span, System.ReadOnlySpan<char> trimChars) { throw null; }
Expand Down
1 change: 1 addition & 0 deletions src/System.Memory/ref/System.Memory.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
<ProjectReference Include="..\..\System.Runtime.InteropServices\ref\System.Runtime.InteropServices.csproj" />
</ItemGroup>
<ItemGroup Condition="'$(TargetGroup)' == 'netstandard1.1'">
<Reference Include="System.Globalization" />
<Reference Include="System.Runtime" />
<Reference Include="System.Runtime.InteropServices" />
</ItemGroup>
Expand Down
87 changes: 87 additions & 0 deletions src/System.Memory/src/System/MemoryExtensions.Portable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// See the LICENSE file in the project root for more information.

using System.Diagnostics;
using System.Globalization;
using System.Runtime.CompilerServices;

namespace System
Expand All @@ -12,6 +13,92 @@ namespace System
/// </summary>
public static partial class MemoryExtensions
{
/// <summary>
/// Copies the characters from the source span into the destination, converting each character to lowercase,
/// using the casing rules of the specified culture.
/// </summary>
/// <param name="source">The source span.</param>
/// <param name="destination">The destination span which contains the transformed characters.</param>
/// <param name="culture">An object that supplies culture-specific casing rules.</param>
/// <remarks>If the source and destinations overlap, this method behaves as if the original values are in
/// a temporary location before the destination is overwritten.</remarks>
/// <exception cref="System.ArgumentNullException">
/// Thrown when <paramref name="culture"/> is null.
/// </exception>
public static int ToLower(this ReadOnlySpan<char> source, Span<char> destination, CultureInfo culture)
{
if (culture == null)
ThrowHelper.ThrowArgumentNullException(ExceptionArgument.culture);

// Assuming that changing case does not affect length
if (destination.Length < source.Length)
return -1;

string sourceString = source.ToString();
#if !netstandard11
string resultString = sourceString.ToLower(culture);
#else
string resultString = culture.TextInfo.ToLower(sourceString);
#endif
Debug.Assert(sourceString.Length == resultString.Length);
resultString.AsSpan().CopyTo(destination);
return source.Length;
}

/// <summary>
/// Copies the characters from the source span into the destination, converting each character to lowercase,
/// using the casing rules of the invariant culture.
/// </summary>
/// <param name="source">The source span.</param>
/// <param name="destination">The destination span which contains the transformed characters.</param>
/// <remarks>If the source and destinations overlap, this method behaves as if the original values are in
/// a temporary location before the destination is overwritten.</remarks>
public static int ToLowerInvariant(this ReadOnlySpan<char> source, Span<char> destination)
=> ToLower(source, destination, CultureInfo.InvariantCulture);

/// <summary>
/// Copies the characters from the source span into the destination, converting each character to uppercase,
/// using the casing rules of the specified culture.
/// </summary>
/// <param name="source">The source span.</param>
/// <param name="destination">The destination span which contains the transformed characters.</param>
/// <param name="culture">An object that supplies culture-specific casing rules.</param>
/// <remarks>If the source and destinations overlap, this method behaves as if the original values are in
/// a temporary location before the destination is overwritten.</remarks>
/// <exception cref="System.ArgumentNullException">
/// Thrown when <paramref name="culture"/> is null.
/// </exception>
public static int ToUpper(this ReadOnlySpan<char> source, Span<char> destination, CultureInfo culture)
{
if (culture == null)
ThrowHelper.ThrowArgumentNullException(ExceptionArgument.culture);

// Assuming that changing case does not affect length
if (destination.Length < source.Length)
return -1;

string sourceString = source.ToString();
#if !netstandard11
string resultString = sourceString.ToUpper(culture);
#else
string resultString = culture.TextInfo.ToUpper(sourceString);
#endif
Debug.Assert(sourceString.Length == resultString.Length);
resultString.AsSpan().CopyTo(destination);
return source.Length;
}

/// <summary>
/// Copies the characters from the source span into the destination, converting each character to uppercase
/// using the casing rules of the invariant culture.
/// </summary>
/// <param name="source">The source span.</param>
/// <param name="destination">The destination span which contains the transformed characters.</param>
/// <remarks>If the source and destinations overlap, this method behaves as if the original values are in
/// a temporary location before the destination is overwritten.</remarks>
public static int ToUpperInvariant(this ReadOnlySpan<char> source, Span<char> destination)
=> ToUpper(source, destination, CultureInfo.InvariantCulture);

/// <summary>
/// Determines whether the end of the <paramref name="span"/> matches the specified <paramref name="value"/> when compared using the specified <paramref name="comparisonType"/> option.
/// </summary>
Expand Down
3 changes: 2 additions & 1 deletion src/System.Memory/src/System/ThrowHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@ internal enum ExceptionArgument
startIndex,
endIndex,
array,
ownedMemory
ownedMemory,
culture
}
}
Loading