Example #1
0
        public static void AppendString(this IWriter writer, string value)
        {
            var enumerator = new Utf16LittleEndianCodePointEnumerator(value); // no need to dispose this

            while (enumerator.MoveNext())
            {
                int encodedBytes;
                var success = Utf8Encoder.TryEncodeCodePoint(
                    enumerator.Current,
                    writer.GetFreeBuffer(MaxUtf8CodePointBytes).ToSpan(),
                    out encodedBytes);
                Debug.Assert(success);
                writer.CommitBytes(encodedBytes);
            }
        }
Example #2
0
        public bool Equals(string other)
        {
            CodePointEnumerator thisEnumerator = GetCodePointEnumerator();
            Utf16LittleEndianCodePointEnumerator otherEnumerator = new Utf16LittleEndianCodePointEnumerator(other);

            while (true)
            {
                bool hasNext = thisEnumerator.MoveNext();
                if (hasNext != otherEnumerator.MoveNext())
                {
                    return(false);
                }

                if (!hasNext)
                {
                    return(true);
                }

                if (thisEnumerator.Current != otherEnumerator.Current)
                {
                    return(false);
                }
            }
        }