diff options
Diffstat (limited to 'src/Jellyfin.Extensions/Json/Utf8JsonExtensions.cs')
| -rw-r--r-- | src/Jellyfin.Extensions/Json/Utf8JsonExtensions.cs | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/src/Jellyfin.Extensions/Json/Utf8JsonExtensions.cs b/src/Jellyfin.Extensions/Json/Utf8JsonExtensions.cs new file mode 100644 index 000000000..d06508a26 --- /dev/null +++ b/src/Jellyfin.Extensions/Json/Utf8JsonExtensions.cs @@ -0,0 +1,27 @@ +using System.Text.Json; + +namespace Jellyfin.Extensions.Json; + +/// <summary> +/// Extensions for Utf8JsonReader and Utf8JsonWriter. +/// </summary> +public static class Utf8JsonExtensions +{ + /// <summary> + /// Determines if the reader contains an empty string. + /// </summary> + /// <param name="reader">The reader.</param> + /// <returns>Whether the reader contains an empty string.</returns> + public static bool IsEmptyString(this Utf8JsonReader reader) + => reader.TokenType == JsonTokenType.String + && ((reader.HasValueSequence && reader.ValueSequence.IsEmpty) + || (!reader.HasValueSequence && reader.ValueSpan.IsEmpty)); + + /// <summary> + /// Determines if the reader contains a null value. + /// </summary> + /// <param name="reader">The reader.</param> + /// <returns>Whether the reader contains null.</returns> + public static bool IsNull(this Utf8JsonReader reader) + => reader.TokenType == JsonTokenType.Null; +} |
