示例#1
0
        public ImmutableArray <byte> GetChecksum()
        {
            if (_lazyChecksum.IsDefault)
            {
                using (var stream = new SourceTextStream(this, useDefaultEncodingIfNull: true))
                {
                    ImmutableInterlocked.InterlockedInitialize(ref _lazyChecksum, CalculateChecksum(stream, _checksumAlgorithm));
                }
            }

            return(_lazyChecksum);
        }
示例#2
0
 public void MinimumLength()
 {
     var sourceText = SourceText.From("hello world", s_utf8NoBom);
     using (var stream = new SourceTextStream(sourceText))
     {
         var buffer = new byte[100];
         var max = s_utf8NoBom.GetMaxByteCount(charCount: 1);
         for (int i = 0; i < max; i++)
         {
             var local = i;
             Assert.Throws(typeof(ArgumentException), () => stream.Read(buffer, 0, local));
         }
     }
 }
示例#3
0
        internal ImmutableArray <byte> GetChecksum()
        {
            if (_lazyChecksum.IsDefault)
            {
                // we shouldn't be asking for a checksum of encoding-less source text:
                Debug.Assert(this.Encoding != null);

                using (var stream = new SourceTextStream(this))
                {
                    ImmutableInterlocked.InterlockedInitialize(ref _lazyChecksum, CalculateChecksum(stream, _checksumAlgorithm));
                }
            }

            return(_lazyChecksum);
        }
示例#4
0
        internal ImmutableArray <byte> GetChecksum(bool useDefaultEncodingIfNull = false)
        {
            if (_lazyChecksum.IsDefault)
            {
                // we shouldn't be asking for a checksum of encoding-less source text, except for SourceText comparison.
                Debug.Assert(this.Encoding != null || useDefaultEncodingIfNull);

                using (var stream = new SourceTextStream(this, useDefaultEncodingIfNull: useDefaultEncodingIfNull))
                {
                    ImmutableInterlocked.InterlockedInitialize(ref _lazyChecksum, CalculateChecksum(stream, _checksumAlgorithm));
                }
            }

            return(_lazyChecksum);
        }
示例#5
0
        public void Issue1197()
        {
            var baseText = "food time";
            var text = string.Format("{0}{1}", baseText, '\u2019');
            var encoding = s_utf8NoBom;
            var sourceText = SourceText.From(text, encoding);
            using (var stream = new SourceTextStream(sourceText, bufferSize: text.Length * 2))
            {
                var buffer = new byte[baseText.Length + 1];
                Assert.Equal(baseText.Length, stream.Read(buffer, 0, buffer.Length));
                Assert.True(buffer.Take(baseText.Length).SequenceEqual(encoding.GetBytes(baseText)));

                Assert.Equal(3, stream.Read(buffer, 0, buffer.Length));
                Assert.True(buffer.Take(3).SequenceEqual(encoding.GetBytes(new[] { '\u2019' })));
            }
        }
示例#6
0
        internal ImmutableArray<byte> GetChecksum()
        {
            if (_lazyChecksum.IsDefault)
            {
                // we shouldn't be asking for a checksum of encoding-less source text:
                Debug.Assert(this.Encoding != null);

                using (var stream = new SourceTextStream(this))
                {
                    ImmutableInterlocked.InterlockedInitialize(ref _lazyChecksum, CalculateChecksum(stream, _checksumAlgorithm));
                }
            }

            return _lazyChecksum;
        }
示例#7
0
        public ImmutableArray<byte> GetChecksum()
        {
            if (_lazyChecksum.IsDefault)
            {
                using (var stream = new SourceTextStream(this, useDefaultEncodingIfNull: true))
                {
                    ImmutableInterlocked.InterlockedInitialize(ref _lazyChecksum, CalculateChecksum(stream, _checksumAlgorithm));
                }
            }

            return _lazyChecksum;
        }
示例#8
0
        internal ImmutableArray<byte> GetChecksum(bool useDefaultEncodingIfNull = false)
        {
            if (_lazyChecksum.IsDefault)
            {
                // we shouldn't be asking for a checksum of encoding-less source text, except for SourceText comparison.
                Debug.Assert(this.Encoding != null || useDefaultEncodingIfNull);

                using (var stream = new SourceTextStream(this, useDefaultEncodingIfNull: useDefaultEncodingIfNull))
                {
                    ImmutableInterlocked.InterlockedInitialize(ref _lazyChecksum, CalculateChecksum(stream, _checksumAlgorithm));
                }
            }

            return _lazyChecksum;
        }