From 89f249075e185b8b3c3392546274f1b079b4e90f Mon Sep 17 00:00:00 2001 From: joegoldman2 <147369450+joegoldman2@users.noreply.github.com> Date: Fri, 5 Apr 2024 13:09:49 +0000 Subject: [PATCH 1/2] Take into account the provided format in Utf8Parser.TryParse for bool --- .../Text/Utf8Parser/Utf8Parser.Boolean.cs | 42 ++++++++++++++----- 1 file changed, 32 insertions(+), 10 deletions(-) diff --git a/src/libraries/System.Private.CoreLib/src/System/Buffers/Text/Utf8Parser/Utf8Parser.Boolean.cs b/src/libraries/System.Private.CoreLib/src/System/Buffers/Text/Utf8Parser/Utf8Parser.Boolean.cs index b19cee4e43ecc..1043c71e8ccb1 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Buffers/Text/Utf8Parser/Utf8Parser.Boolean.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Buffers/Text/Utf8Parser/Utf8Parser.Boolean.cs @@ -33,22 +33,44 @@ public static bool TryParse(ReadOnlySpan source, out bool value, out int b if (source.Length >= 4) { - int dw = BinaryPrimitives.ReadInt32LittleEndian(source) & ~0x20202020; - if (dw == 0x45555254 /* 'EURT' */) + int dw = BinaryPrimitives.ReadInt32LittleEndian(source); + if (standardFormat == default(char) || standardFormat == 'G') { - bytesConsumed = 4; - value = true; - return true; + if (dw == 0x65757254 /* 'eurT' */) + { + bytesConsumed = 4; + value = true; + return true; + } + + if (source.Length > 4) + { + if (dw == 0x736C6146 /* 'slaF' */ && source[4] == 'e') + { + bytesConsumed = 5; + value = false; + return true; + } + } } - - if (source.Length > 4) + else if (standardFormat == 'l') { - if (dw == 0x534c4146 /* 'SLAF' */ && (source[4] & ~0x20) == 'E') + if (dw == 0x65757274 /* 'eurt' */) { - bytesConsumed = 5; - value = false; + bytesConsumed = 4; + value = true; return true; } + + if (source.Length > 4) + { + if (dw == 0x736C6166 /* 'slaf' */ && source[4] == 'e') + { + bytesConsumed = 5; + value = false; + return true; + } + } } } From 01d574af5da0629d723b5c375a292c057b9a5d9a Mon Sep 17 00:00:00 2001 From: joegoldman2 <147369450+joegoldman@users.noreply.github.com> Date: Fri, 5 Apr 2024 14:11:05 +0000 Subject: [PATCH 2/2] Remove trailing spaces --- .../src/System/Buffers/Text/Utf8Parser/Utf8Parser.Boolean.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/libraries/System.Private.CoreLib/src/System/Buffers/Text/Utf8Parser/Utf8Parser.Boolean.cs b/src/libraries/System.Private.CoreLib/src/System/Buffers/Text/Utf8Parser/Utf8Parser.Boolean.cs index 1043c71e8ccb1..cb9af01b2327f 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Buffers/Text/Utf8Parser/Utf8Parser.Boolean.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Buffers/Text/Utf8Parser/Utf8Parser.Boolean.cs @@ -42,7 +42,7 @@ public static bool TryParse(ReadOnlySpan source, out bool value, out int b value = true; return true; } - + if (source.Length > 4) { if (dw == 0x736C6146 /* 'slaF' */ && source[4] == 'e') @@ -61,7 +61,7 @@ public static bool TryParse(ReadOnlySpan source, out bool value, out int b value = true; return true; } - + if (source.Length > 4) { if (dw == 0x736C6166 /* 'slaf' */ && source[4] == 'e')