Ejemplo n.º 1
0
        public static Rune ToUpperInvariant(Rune value)
        {
            // Handle the most common case (ASCII data) first. Within the common case, we expect
            // that there'll be a mix of lowercase & uppercase chars, so make the conversion branchless.

            if (value.IsAscii || GlobalizationMode.Invariant)
            {
                // It's ok for us to use the UTF-16 conversion utility for this since the high
                // 16 bits of the value will never be set so will be left unchanged.
                return(UnsafeCreate(Utf16Utility.ConvertAllAsciiCharsInUInt32ToUppercase(value._value)));
            }

            // Non-ASCII data requires going through the case folding tables.

            return(ToUpper(value, CultureInfo.InvariantCulture));
        }
Ejemplo n.º 2
0
        [MethodImpl(MethodImplOptions.AggressiveInlining)] // called directly by GetCharCountCommon
        private protected sealed override unsafe int GetByteCountFast(char *pChars, int charsLength, EncoderFallback?fallback, out int charsConsumed)
        {
            // The number of UTF-8 code units may exceed the number of UTF-16 code units,
            // so we'll need to check for overflow before casting to Int32.

            char *ptrToFirstInvalidChar = Utf16Utility.GetPointerToFirstInvalidChar(pChars, charsLength, out long utf8CodeUnitCountAdjustment, out _);

            int tempCharsConsumed = (int)(ptrToFirstInvalidChar - pChars);

            charsConsumed = tempCharsConsumed;

            long totalUtf8Bytes = tempCharsConsumed + utf8CodeUnitCountAdjustment;

            if ((ulong)totalUtf8Bytes > int.MaxValue)
            {
                ThrowConversionOverflow();
            }

            return((int)totalUtf8Bytes);
        }
Ejemplo n.º 3
0
        public static Rune ToUpperInvariant(Rune value)
        {
            // Handle the most common case (ASCII data) first. Within the common case, we expect
            // that there'll be a mix of lowercase & uppercase chars, so make the conversion branchless.

            if (value.IsAscii)
            {
                // It's ok for us to use the UTF-16 conversion utility for this since the high
                // 16 bits of the value will never be set so will be left unchanged.
                return(UnsafeCreate(Utf16Utility.ConvertAllAsciiCharsInUInt32ToUppercase(value._value)));
            }

            if (GlobalizationMode.Invariant)
            {
                // If the value isn't ASCII and if the globalization tables aren't available,
                // case changing has no effect.
                return(value);
            }

            // Non-ASCII data requires going through the case folding tables.

            return(ChangeCaseCultureAware(value, TextInfo.Invariant, toUpper: true));
        }