/// <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 <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); } culture ??= CultureInfo.CurrentCulture; // Assuming that changing case does not affect length if (destination.Length < source.Length) { return(-1); } if (GlobalizationMode.Invariant) { TextInfo.ToUpperAsciiInvariant(source, destination); } else { culture.TextInfo.ChangeCaseToUpper(source, 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 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 ToUpper(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.ToUpperAsciiInvariant(source, destination); } else { culture !.TextInfo.ChangeCaseToUpper(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 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> /// <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); } if (GlobalizationMode.Invariant) { InvariantModeCasing.ToUpper(source, destination); } else { TextInfo.Invariant.ChangeCaseToUpper(source, destination); } return(source.Length); }