/// <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 <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) { ThrowHelper.ThrowArgumentNullException(ExceptionArgument.culture); } // Assuming that changing case does not affect length if (destination.Length < source.Length) { return(-1); } if (GlobalizationMode.Invariant) { TextInfo.ToLowerAsciiInvariant(source, destination); } else { culture !.TextInfo.ChangeCaseToLower(source, destination); // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected } 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 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 <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); } culture ??= CultureInfo.CurrentCulture; // Assuming that changing case does not affect length if (destination.Length < source.Length) { return(-1); } if (GlobalizationMode.Invariant) { TextInfo.ToLowerAsciiInvariant(source, destination); } else { culture.TextInfo.ChangeCaseToLower(source, 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> /// <returns>The number of characters written into the destination span. If the destination is too small, returns -1.</returns> public static int ToLowerInvariant(this ReadOnlySpan <char> source, Span <char> destination) { // Assuming that changing case does not affect length if (destination.Length < source.Length) { return(-1); } if (GlobalizationMode.Invariant) { TextInfo.ToLowerAsciiInvariant(source, destination); } else { CultureInfo.InvariantCulture.TextInfo.ChangeCaseToLower(source, 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 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> /// <returns>The number of characters written into the destination span. If the destination is too small, returns -1.</returns> /// <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); } if (GlobalizationMode.Invariant) { TextInfo.ToLowerAsciiInvariant(source, destination); } else { culture.TextInfo.ChangeCaseToLower(source, 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 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> /// <returns>The number of characters written into the destination span. If the destination is too small, returns -1.</returns> /// <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); } if (GlobalizationMode.Invariant) { TextInfo.ToLowerAsciiInvariant(source, destination); } else { culture !.TextInfo.ChangeCaseToLower(source, destination); // TODO-NULLABLE: https://github.com/dotnet/csharplang/issues/538 } return(source.Length); }