- Added ifdef to remove `Deconstruct` extension on everything except `NETSTANDARD2_0`tags/v0.6.0
| @@ -16,6 +16,15 @@ namespace LLama.Unittest | |||||
| Assert.True(chars[..count].SequenceEqual(str)); | Assert.True(chars[..count].SequenceEqual(str)); | ||||
| } | } | ||||
| private static void GetCharCountTest(string str) | |||||
| { | |||||
| var bytes = Encoding.UTF8.GetBytes(str); | |||||
| var count = EncodingExtensions.GetCharCountImpl(Encoding.UTF8, bytes); | |||||
| Assert.Equal(str.Length, count); | |||||
| } | |||||
| [Fact] | [Fact] | ||||
| public void GetCharsEmptyString() | public void GetCharsEmptyString() | ||||
| { | { | ||||
| @@ -33,5 +42,23 @@ namespace LLama.Unittest | |||||
| { | { | ||||
| GetCharsTest("猫坐在垫子上"); | GetCharsTest("猫坐在垫子上"); | ||||
| } | } | ||||
| [Fact] | |||||
| public void GetCharCountEmptyString() | |||||
| { | |||||
| GetCharCountTest(""); | |||||
| } | |||||
| [Fact] | |||||
| public void GetCharCountString() | |||||
| { | |||||
| GetCharCountTest("Hello World"); | |||||
| } | |||||
| [Fact] | |||||
| public void GetCharCountChineseString() | |||||
| { | |||||
| GetCharCountTest("猫坐在垫子上"); | |||||
| } | |||||
| } | } | ||||
| } | } | ||||
| @@ -35,6 +35,9 @@ internal static class EncodingExtensions | |||||
| internal static int GetCharCountImpl(Encoding encoding, ReadOnlySpan<byte> bytes) | internal static int GetCharCountImpl(Encoding encoding, ReadOnlySpan<byte> bytes) | ||||
| { | { | ||||
| if (bytes.Length == 0) | |||||
| return 0; | |||||
| unsafe | unsafe | ||||
| { | { | ||||
| fixed (byte* bytePtr = bytes) | fixed (byte* bytePtr = bytes) | ||||
| @@ -5,8 +5,9 @@ namespace LLama.Extensions | |||||
| /// <summary> | /// <summary> | ||||
| /// Extensions to the KeyValuePair struct | /// Extensions to the KeyValuePair struct | ||||
| /// </summary> | /// </summary> | ||||
| public static class KeyValuePairExtensions | |||||
| internal static class KeyValuePairExtensions | |||||
| { | { | ||||
| #if NETSTANDARD2_0 | |||||
| /// <summary> | /// <summary> | ||||
| /// Deconstruct a KeyValuePair into it's constituent parts. | /// Deconstruct a KeyValuePair into it's constituent parts. | ||||
| /// </summary> | /// </summary> | ||||
| @@ -20,5 +21,6 @@ namespace LLama.Extensions | |||||
| first = pair.Key; | first = pair.Key; | ||||
| second = pair.Value; | second = pair.Value; | ||||
| } | } | ||||
| #endif | |||||
| } | } | ||||
| } | } | ||||