/// <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. If <paramref name="culture"/> is null, <see cref="System.Globalization.CultureInfo.CurrentCulture"/> will be used.</remarks>
+ /// <remarks>If <paramref name="culture"/> is null, <see cref="System.Globalization.CultureInfo.CurrentCulture"/> will be used.</remarks>
/// <returns>The number of characters written into the destination span. If the destination is too small, returns -1.</returns>
+ /// <exception cref="InvalidOperationException">The source and destination buffers overlap.</exception>
public static int ToLower(this ReadOnlySpan<char> source, Span<char> destination, CultureInfo? culture)
{
+ if (source.Overlaps(destination))
+ throw new InvalidOperationException(SR.InvalidOperation_SpanOverlappedOperation);
+
if (culture == null)
culture = CultureInfo.CurrentCulture;
/// </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>
/// <returns>The number of characters written into the destination span. If the destination is too small, returns -1.</returns>
+ /// <exception cref="InvalidOperationException">The source and destination buffers overlap.</exception>
public static int ToLowerInvariant(this ReadOnlySpan<char> source, Span<char> destination)
{
+ if (source.Overlaps(destination))
+ throw new InvalidOperationException(SR.InvalidOperation_SpanOverlappedOperation);
+
// Assuming that changing case does not affect length
if (destination.Length < source.Length)
return -1;
/// <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. If <paramref name="culture"/> is null, <see cref="System.Globalization.CultureInfo.CurrentCulture"/> will be used.</remarks>
+ /// <remarks>If <paramref name="culture"/> is null, <see cref="System.Globalization.CultureInfo.CurrentCulture"/> will be used.</remarks>
/// <returns>The number of characters written into the destination span. If the destination is too small, returns -1.</returns>
+ /// <exception cref="InvalidOperationException">The source and destination buffers overlap.</exception>
public static int ToUpper(this ReadOnlySpan<char> source, Span<char> destination, CultureInfo? culture)
{
+ if (source.Overlaps(destination))
+ throw new InvalidOperationException(SR.InvalidOperation_SpanOverlappedOperation);
+
if (culture == null)
culture = CultureInfo.CurrentCulture;
/// </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>
/// <returns>The number of characters written into the destination span. If the destination is too small, returns -1.</returns>
+ /// <exception cref="InvalidOperationException">The source and destination buffers overlap.</exception>
public static int ToUpperInvariant(this ReadOnlySpan<char> source, Span<char> destination)
{
+ if (source.Overlaps(destination))
+ throw new InvalidOperationException(SR.InvalidOperation_SpanOverlappedOperation);
+
// Assuming that changing case does not affect length
if (destination.Length < source.Length)
return -1;