Exemplo n.º 1
0
        private Rune GetNextRune()
        {
            char firstChar = GetNextChar();

            if (Rune.TryCreate(firstChar, out Rune value) || Rune.TryCreate(firstChar, GetNextChar(), out value))
            {
                return(value);
            }

            throw new ArgumentException(SR.Argument_InvalidCharSequenceNoIndex);
        }
Exemplo n.º 2
0
        public SplitResult Split(char separator, Utf8StringSplitOptions options = Utf8StringSplitOptions.None)
        {
            if (!Rune.TryCreate(separator, out Rune rune))
            {
                throw new ArgumentOutOfRangeException(
                          paramName: nameof(separator),
                          message: SR.ArgumentOutOfRange_Utf16SurrogatesDisallowed);
            }

            Utf8String.CheckSplitOptions(options);

            return(new SplitResult(this, rune, options));
        }
Exemplo n.º 3
0
        /// <summary>
        /// Attempts to locate the target <paramref name="value"/> within this <see cref="Utf8Span"/> instance.
        /// If <paramref name="value"/> is found, returns <see langword="true"/> and sets <paramref name="range"/> to
        /// the location where <paramref name="value"/> occurs within this <see cref="Utf8Span"/> instance.
        /// If <paramref name="value"/> is not found, returns <see langword="false"/> and sets <paramref name="range"/>
        /// to <see langword="default"/>.
        /// </summary>
        /// <remarks>
        /// An ordinal search is performed.
        /// </remarks>
        public bool TryFind(char value, out Range range)
        {
            if (Rune.TryCreate(value, out Rune rune))
            {
                return(TryFind(rune, out range));
            }
            else
            {
                // Surrogate chars can't exist in well-formed UTF-8 data - bail immediately.

                range = default;
                return(false);
            }
        }
Exemplo n.º 4
0
        private Rune GetNextRune()
        {
            // Call GetNextChar() and try treating it as a non-surrogate character.
            // If that fails, call GetNextChar() again and attempt to treat the two chars
            // as a surrogate pair. If that still fails, throw an exception since the fallback
            // mechanism is giving us a bad replacement character.

            char ch = GetNextChar();

            if (!Rune.TryCreate(ch, out Rune rune) && !Rune.TryCreate(ch, GetNextChar(), out rune))
            {
                throw new ArgumentException(SR.Argument_InvalidCharSequenceNoIndex);
            }

            return(rune);
        }
Exemplo n.º 5
0
        /// <summary>
        /// Attempts to locate the target <paramref name="value"/> within this <see cref="Utf8Span"/> instance.
        /// If <paramref name="value"/> is found, returns <see langword="true"/> and sets <paramref name="range"/> to
        /// the location where <paramref name="value"/> occurs within this <see cref="Utf8Span"/> instance.
        /// If <paramref name="value"/> is not found, returns <see langword="false"/> and sets <paramref name="range"/>
        /// to <see langword="default"/>.
        /// </summary>
        /// <remarks>
        /// The search is performed using the specified <paramref name="comparisonType"/>.
        /// </remarks>
        public bool TryFind(char value, StringComparison comparisonType, out Range range)
        {
            if (Rune.TryCreate(value, out Rune rune))
            {
                return(TryFind(rune, comparisonType, out range));
            }
            else
            {
                string.CheckStringComparison(comparisonType);

                // Surrogate chars can't exist in well-formed UTF-8 data - bail immediately.

                range = default;
                return(false);
            }
        }
Exemplo n.º 6
0
 /// <summary>
 /// Returns a value stating whether the current <see cref="Utf8Span"/> instance contains
 /// <paramref name="value"/>. The specified comparison is used.
 /// </summary>
 public bool Contains(char value, StringComparison comparison)
 {
     return(Rune.TryCreate(value, out Rune rune) && Contains(rune, comparison));
 }
Exemplo n.º 7
0
 /// <summary>
 /// Returns a value stating whether the current <see cref="Utf8Span"/> instance contains
 /// <paramref name="value"/>. An ordinal comparison is used.
 /// </summary>
 public bool Contains(char value)
 {
     return(Rune.TryCreate(value, out Rune rune) && Contains(rune));
 }
Exemplo n.º 8
0
 /// <summary>
 /// Returns a value stating whether the current <see cref="Utf8Span"/> instance begins with
 /// <paramref name="value"/>. The specified comparison is used.
 /// </summary>
 public bool StartsWith(char value, StringComparison comparison)
 {
     return(Rune.TryCreate(value, out Rune rune) && StartsWith(rune, comparison));
 }
Exemplo n.º 9
0
 /// <summary>
 /// Returns a value stating whether the current <see cref="Utf8Span"/> instance begins with
 /// <paramref name="value"/>. An ordinal comparison is used.
 /// </summary>
 public bool StartsWith(char value)
 {
     return(Rune.TryCreate(value, out Rune rune) && StartsWith(rune));
 }