This repository has been archived by the owner on Aug 2, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 344
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
BufferWriter.WriteLine String/Utf8String (#2176)
* Bug fix in BufferWriter * BufferWriter WriteLine Strings
- Loading branch information
1 parent
587b6a2
commit f5eb04e
Showing
6 changed files
with
129 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
src/System.Buffers.ReaderWriter/System/Buffers/Writer/BufferWriterT_ints.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
// See the LICENSE file in the project root for more information. | ||
|
||
using System.Buffers.Text; | ||
using System.Runtime.CompilerServices; | ||
|
||
namespace System.Buffers.Writer | ||
{ | ||
public ref partial struct BufferWriter<T> where T : IBufferWriter<byte> | ||
{ | ||
[MethodImpl(MethodImplOptions.AggressiveInlining)] | ||
public void Write(int value, StandardFormat format = default) | ||
{ | ||
int written; | ||
while (!Utf8Formatter.TryFormat(value, Buffer, out written, format)) | ||
{ | ||
Enlarge(); | ||
} | ||
Advance(written); | ||
} | ||
|
||
[MethodImpl(MethodImplOptions.AggressiveInlining)] | ||
public void Write(ulong value, StandardFormat format = default) | ||
{ | ||
int written; | ||
while (!Utf8Formatter.TryFormat(value, Buffer, out written, format)) | ||
{ | ||
Enlarge(); | ||
} | ||
Advance(written); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
src/System.Buffers.ReaderWriter/System/Buffers/Writer/BufferWriterT_writable.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
// See the LICENSE file in the project root for more information. | ||
|
||
using System.Buffers.Text; | ||
using System.Runtime.CompilerServices; | ||
|
||
namespace System.Buffers.Writer | ||
{ | ||
public ref partial struct BufferWriter<T> where T : IBufferWriter<byte> | ||
{ | ||
public void Write<TWritable>(TWritable value, TransformationFormat format) where TWritable : IWritable | ||
{ | ||
int written; | ||
while (true) | ||
{ | ||
while (!value.TryWrite(Buffer, out written, format.Format)) | ||
{ | ||
Enlarge(); | ||
} | ||
if (format.TryTransform(Buffer, ref written)) break; | ||
Enlarge(); | ||
} | ||
Advance(written); | ||
} | ||
|
||
[MethodImpl(MethodImplOptions.AggressiveInlining)] | ||
public void Write<TWritable>(TWritable value, StandardFormat format) where TWritable : IWritable | ||
{ | ||
int written; | ||
while (!value.TryWrite(Buffer, out written, format)) | ||
{ | ||
Enlarge(); | ||
} | ||
Advance(written); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters