-
Notifications
You must be signed in to change notification settings - Fork 4.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add Utf8.TryWrite Initial implementation of Utf8.TryWriteUtf8. The performance of this won't be great at present, but will improve as our cores types add implementation of IUtf8SpanFormattable. For tests, I copy/pasted the tests we had for MemoryExtensions.TryWrite and searched/replaced to make them work for Utf8.TryWrite. * Address PR feedback
- Loading branch information
1 parent
cc01464
commit 2c8cb12
Showing
7 changed files
with
1,286 additions
and
1 deletion.
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
21 changes: 21 additions & 0 deletions
21
src/libraries/System.Private.CoreLib/src/System/IUtf8SpanFormattable.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,21 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
namespace System | ||
{ | ||
/// <summary>Provides functionality to format the string representation of an object into a span as UTF8.</summary> | ||
public interface IUtf8SpanFormattable | ||
{ | ||
/// <summary>Tries to format the value of the current instance as UTF8 into the provided span of bytes.</summary> | ||
/// <param name="destination">When this method returns, this instance's value formatted as a span of bytes.</param> | ||
/// <param name="bytesWritten">When this method returns, the number of bytes that were written in <paramref name="destination"/>.</param> | ||
/// <param name="format">A span containing the characters that represent a standard or custom format string that defines the acceptable format for <paramref name="destination"/>.</param> | ||
/// <param name="provider">An optional object that supplies culture-specific formatting information for <paramref name="destination"/>.</param> | ||
/// <returns><see langword="true"/> if the formatting was successful; otherwise, <see langword="false"/>.</returns> | ||
/// <remarks> | ||
/// An implementation of this interface should produce the same string of characters as an implementation of <see cref="IFormattable.ToString"/> or <see cref="ISpanFormattable.TryFormat"/> | ||
/// on the same type. TryFormat should return false only if there is not enough space in the destination buffer; any other failures should throw an exception. | ||
/// </remarks> | ||
bool TryFormat(Span<byte> destination, out int bytesWritten, ReadOnlySpan<char> format, IFormatProvider? provider); | ||
} | ||
} |
418 changes: 418 additions & 0 deletions
418
src/libraries/System.Private.CoreLib/src/System/Text/Unicode/Utf8.cs
Large diffs are not rendered by default.
Oops, something went wrong.
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
Oops, something went wrong.