コード例 #1
0
        private static bool InterfaceCharMoveNext(ref RuneEnumerator e)
        {
            if (e.State is IEnumerator <char> enumerator)
            {
                if (!enumerator.MoveNext())
                {
                    return(false);
                }

                char highSurrogate = enumerator.Current;
                if (Rune.TryCreate(highSurrogate, out Rune rune))
                {
                    e.Current = rune;
                    return(true);
                }

                if (!enumerator.MoveNext())
                {
                    return(false);
                }

                char lowSurrogate = enumerator.Current;
                if (Rune.TryCreate(highSurrogate, lowSurrogate, out rune))
                {
                    e.Current = rune;
                    return(true);
                }
            }
            return(false);
        }
コード例 #2
0
 private static bool StringMoveNext(ref RuneEnumerator e)
 {
     if (e._stringEnumerator.MoveNext())
     {
         e.Current = e._stringEnumerator.Current;
         return(true);
     }
     return(false);
 }
コード例 #3
0
 private static bool InterfaceRuneMoveNext(ref RuneEnumerator e)
 {
     if (e.State is IEnumerator <Rune> enumerator && enumerator.MoveNext())
     {
         e.Current = enumerator.Current;
         return(true);
     }
     return(false);
 }
コード例 #4
0
 private static bool Utf8MoveNext(ref RuneEnumerator e)
 {
     if (e._utf8Enumerator.MoveNext())
     {
         e.Current = e._utf8Enumerator.Current;
         return(true);
     }
     return(false);
 }
コード例 #5
0
        public readonly override string ToString()
        {
            RuneEnumerator runes   = this;
            StringBuilder  builder = new();
            Span <char>    buffer  = stackalloc char[4];

            foreach (Rune rune in runes)
            {
                int encoded = rune.EncodeToUtf16(buffer);
                builder.Append(buffer.Slice(0, encoded));
            }
            return(builder.ToString());
        }
コード例 #6
0
        private static bool BuilderMoveNext(ref RuneEnumerator e)
        {
TryReturnFromChunk:
            if (e._spanEnumerator.MoveNext())
            {
                e.Current = e._spanEnumerator.Current;
                return(true);
            }

            if (e._builderEnumerator.MoveNext())
            {
                var chunkSpan = e._builderEnumerator.Current.Span;
                e._spanEnumerator = chunkSpan.EnumerateRunes();
                goto TryReturnFromChunk;
            }
            return(false);
        }
コード例 #7
0
 public Utf8Enumerator(RuneEnumerator runes) : this()
 {
     _runeEnumerator = runes;
 }
コード例 #8
0
 public static Utf8Enumerator GetUtf8Enumerator(this RuneEnumerator runes)
 {
     return(new Utf8Enumerator(runes));
 }