/// <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 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 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 ToUpperInvariant(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.ToUpperAsciiInvariant(source, destination); } else { CultureInfo.InvariantCulture.TextInfo.ChangeCaseToUpper(source, destination); } return(source.Length); }
private static bool EqualsOrdinalIgnoreCase(this ReadOnlySpan <char> left, ReadOnlySpan <char> right) { if (left.Length != right.Length) { return(false); } for (int i = 0; i < left.Length; i++) { char x = left[i], y = right[i]; if (x != y && TextInfo.ToUpperAsciiInvariant(x) != TextInfo.ToUpperAsciiInvariant(y)) { return(false); } } return(true); }
/// <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> /// <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 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); } 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 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 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); } if (GlobalizationMode.Invariant) { TextInfo.ToUpperAsciiInvariant(source, destination); } else { culture !.TextInfo.ChangeCaseToUpper(source, destination); // TODO-NULLABLE: https://github.com/dotnet/csharplang/issues/538 } return(source.Length); }