From 3a0c305f14cccc19860a64c93ee76da245586099 Mon Sep 17 00:00:00 2001 From: Pavel Djundik Date: Fri, 9 Feb 2024 21:42:39 +0200 Subject: [PATCH] Rebase --- .../TextKV3/BasicKV3TestCases.cs | 4 +- .../TextKV3/HeadersTestCase.cs | 3 -- .../TextKV3/Kv1ToKv3TestCase.cs | 4 -- .../TextKV3/Kv3ToKv1TestCase.cs | 3 -- .../TextKV3/RootTypesTestCase.cs | 2 - .../TextKV3/SerializationTestCase.cs | 3 -- .../KeyValues3/KV3TextReader.cs | 4 +- .../KeyValues3/KV3TextReaderState.cs | 2 +- .../KeyValues3/KV3TextReaderStateMachine.cs | 2 - .../KeyValues3/KV3TokenReader.cs | 3 -- ValveKeyValue/ValveKeyValue/KVArrayValue.cs | 2 - ValveKeyValue/ValveKeyValue/KVBinaryBlob.cs | 1 - ValveKeyValue/ValveKeyValue/KVFile.cs | 2 - ValveKeyValue/ValveKeyValue/KVFlag.cs | 2 - ValveKeyValue/ValveKeyValue/KVHeader.cs | 2 - .../ValveKeyValue/KeyValues3/Encoding.cs | 2 - .../ValveKeyValue/KeyValues3/Format.cs | 2 - .../KeyValues1/KV1TextSerializer.cs | 2 +- .../KeyValues3/KV3TextSerializer.cs | 5 +-- ValveKeyValue/ValveKeyValue/Utils.cs | 42 ------------------- 20 files changed, 5 insertions(+), 87 deletions(-) delete mode 100644 ValveKeyValue/ValveKeyValue/Utils.cs diff --git a/ValveKeyValue/ValveKeyValue.Test/TextKV3/BasicKV3TestCases.cs b/ValveKeyValue/ValveKeyValue.Test/TextKV3/BasicKV3TestCases.cs index aaf3cebd..42921934 100644 --- a/ValveKeyValue/ValveKeyValue.Test/TextKV3/BasicKV3TestCases.cs +++ b/ValveKeyValue/ValveKeyValue.Test/TextKV3/BasicKV3TestCases.cs @@ -1,5 +1,3 @@ -using NUnit.Framework; - namespace ValveKeyValue.Test.TextKV3 { class BasicKV3TestCases @@ -97,7 +95,7 @@ public void DeserializesArray() var arrayValue = (KVArrayValue)data["arrayValue"]; - Assert.That(arrayValue.Count, Is.EqualTo(2)); + Assert.That(arrayValue, Has.Count.EqualTo(2)); Assert.That(arrayValue[0].ToString(), Is.EqualTo("a")); Assert.That(arrayValue[1].ToString(), Is.EqualTo("b")); diff --git a/ValveKeyValue/ValveKeyValue.Test/TextKV3/HeadersTestCase.cs b/ValveKeyValue/ValveKeyValue.Test/TextKV3/HeadersTestCase.cs index 3e398dc2..4c715620 100644 --- a/ValveKeyValue/ValveKeyValue.Test/TextKV3/HeadersTestCase.cs +++ b/ValveKeyValue/ValveKeyValue.Test/TextKV3/HeadersTestCase.cs @@ -1,7 +1,4 @@ -using System; -using System.IO; using System.Text; -using NUnit.Framework; namespace ValveKeyValue.Test.TextKV3 { diff --git a/ValveKeyValue/ValveKeyValue.Test/TextKV3/Kv1ToKv3TestCase.cs b/ValveKeyValue/ValveKeyValue.Test/TextKV3/Kv1ToKv3TestCase.cs index e6037eb6..5eba97b6 100644 --- a/ValveKeyValue/ValveKeyValue.Test/TextKV3/Kv1ToKv3TestCase.cs +++ b/ValveKeyValue/ValveKeyValue.Test/TextKV3/Kv1ToKv3TestCase.cs @@ -1,7 +1,3 @@ -using System; -using System.IO; -using NUnit.Framework; - namespace ValveKeyValue.Test.TextKV3 { class Kv1ToKv3TestCase diff --git a/ValveKeyValue/ValveKeyValue.Test/TextKV3/Kv3ToKv1TestCase.cs b/ValveKeyValue/ValveKeyValue.Test/TextKV3/Kv3ToKv1TestCase.cs index 7be5493d..3ede1317 100644 --- a/ValveKeyValue/ValveKeyValue.Test/TextKV3/Kv3ToKv1TestCase.cs +++ b/ValveKeyValue/ValveKeyValue.Test/TextKV3/Kv3ToKv1TestCase.cs @@ -1,6 +1,3 @@ -using System.IO; -using NUnit.Framework; - namespace ValveKeyValue.Test.TextKV3 { class Kv3ToKv1TestCase diff --git a/ValveKeyValue/ValveKeyValue.Test/TextKV3/RootTypesTestCase.cs b/ValveKeyValue/ValveKeyValue.Test/TextKV3/RootTypesTestCase.cs index e685b105..ff047f1e 100644 --- a/ValveKeyValue/ValveKeyValue.Test/TextKV3/RootTypesTestCase.cs +++ b/ValveKeyValue/ValveKeyValue.Test/TextKV3/RootTypesTestCase.cs @@ -1,5 +1,3 @@ -using NUnit.Framework; - namespace ValveKeyValue.Test.TextKV3 { class RootTypesTestCase diff --git a/ValveKeyValue/ValveKeyValue.Test/TextKV3/SerializationTestCase.cs b/ValveKeyValue/ValveKeyValue.Test/TextKV3/SerializationTestCase.cs index 69dff8e5..71ac6899 100644 --- a/ValveKeyValue/ValveKeyValue.Test/TextKV3/SerializationTestCase.cs +++ b/ValveKeyValue/ValveKeyValue.Test/TextKV3/SerializationTestCase.cs @@ -1,6 +1,3 @@ -using System.IO; -using NUnit.Framework; - namespace ValveKeyValue.Test.TextKV3 { class SerializationTestCase diff --git a/ValveKeyValue/ValveKeyValue/Deserialization/KeyValues3/KV3TextReader.cs b/ValveKeyValue/ValveKeyValue/Deserialization/KeyValues3/KV3TextReader.cs index ea4f34fa..a59a0f23 100644 --- a/ValveKeyValue/ValveKeyValue/Deserialization/KeyValues3/KV3TextReader.cs +++ b/ValveKeyValue/ValveKeyValue/Deserialization/KeyValues3/KV3TextReader.cs @@ -1,6 +1,4 @@ -using System; using System.Globalization; -using System.IO; using ValveKeyValue.Abstraction; namespace ValveKeyValue.Deserialization.KeyValues3 @@ -183,7 +181,7 @@ void ReadText(string text) void ReadBinaryBlob(string text) { - var bytes = Utils.ParseHexStringAsByteArrayNoReverse(text); + var bytes = HexStringHelper.ParseHexStringAsByteArray(text); var value = new KVBinaryBlob(bytes) { Flag = stateMachine.GetAndResetFlag() diff --git a/ValveKeyValue/ValveKeyValue/Deserialization/KeyValues3/KV3TextReaderState.cs b/ValveKeyValue/ValveKeyValue/Deserialization/KeyValues3/KV3TextReaderState.cs index dae406f7..b4a0a685 100644 --- a/ValveKeyValue/ValveKeyValue/Deserialization/KeyValues3/KV3TextReaderState.cs +++ b/ValveKeyValue/ValveKeyValue/Deserialization/KeyValues3/KV3TextReaderState.cs @@ -1,4 +1,4 @@ -namespace ValveKeyValue.Deserialization.KeyValues3 +namespace ValveKeyValue.Deserialization.KeyValues3 { enum KV3TextReaderState { diff --git a/ValveKeyValue/ValveKeyValue/Deserialization/KeyValues3/KV3TextReaderStateMachine.cs b/ValveKeyValue/ValveKeyValue/Deserialization/KeyValues3/KV3TextReaderStateMachine.cs index 127ec45d..b233dc88 100644 --- a/ValveKeyValue/ValveKeyValue/Deserialization/KeyValues3/KV3TextReaderStateMachine.cs +++ b/ValveKeyValue/ValveKeyValue/Deserialization/KeyValues3/KV3TextReaderStateMachine.cs @@ -1,5 +1,3 @@ -using System.Collections.Generic; - namespace ValveKeyValue.Deserialization.KeyValues3 { class KV3TextReaderStateMachine diff --git a/ValveKeyValue/ValveKeyValue/Deserialization/KeyValues3/KV3TokenReader.cs b/ValveKeyValue/ValveKeyValue/Deserialization/KeyValues3/KV3TokenReader.cs index 7a6124c0..91625ced 100644 --- a/ValveKeyValue/ValveKeyValue/Deserialization/KeyValues3/KV3TokenReader.cs +++ b/ValveKeyValue/ValveKeyValue/Deserialization/KeyValues3/KV3TokenReader.cs @@ -1,6 +1,3 @@ -using System; -using System.Collections.Generic; -using System.IO; using System.Linq; using System.Text; using ValveKeyValue.KeyValues3; diff --git a/ValveKeyValue/ValveKeyValue/KVArrayValue.cs b/ValveKeyValue/ValveKeyValue/KVArrayValue.cs index df2e3d10..2bcc6f7c 100644 --- a/ValveKeyValue/ValveKeyValue/KVArrayValue.cs +++ b/ValveKeyValue/ValveKeyValue/KVArrayValue.cs @@ -1,6 +1,4 @@ -using System; using System.Collections; -using System.Collections.Generic; namespace ValveKeyValue { diff --git a/ValveKeyValue/ValveKeyValue/KVBinaryBlob.cs b/ValveKeyValue/ValveKeyValue/KVBinaryBlob.cs index 2a045400..c2956fb9 100644 --- a/ValveKeyValue/ValveKeyValue/KVBinaryBlob.cs +++ b/ValveKeyValue/ValveKeyValue/KVBinaryBlob.cs @@ -1,4 +1,3 @@ -using System; using System.Text; namespace ValveKeyValue diff --git a/ValveKeyValue/ValveKeyValue/KVFile.cs b/ValveKeyValue/ValveKeyValue/KVFile.cs index bae07fc6..e90f75fb 100644 --- a/ValveKeyValue/ValveKeyValue/KVFile.cs +++ b/ValveKeyValue/ValveKeyValue/KVFile.cs @@ -1,5 +1,3 @@ -using System; - namespace ValveKeyValue { public class KVFile : KVObject diff --git a/ValveKeyValue/ValveKeyValue/KVFlag.cs b/ValveKeyValue/ValveKeyValue/KVFlag.cs index 25e20c31..eea986e0 100644 --- a/ValveKeyValue/ValveKeyValue/KVFlag.cs +++ b/ValveKeyValue/ValveKeyValue/KVFlag.cs @@ -1,5 +1,3 @@ -using System; - namespace ValveKeyValue { public enum KVFlag diff --git a/ValveKeyValue/ValveKeyValue/KVHeader.cs b/ValveKeyValue/ValveKeyValue/KVHeader.cs index 6f02091a..17ab54aa 100644 --- a/ValveKeyValue/ValveKeyValue/KVHeader.cs +++ b/ValveKeyValue/ValveKeyValue/KVHeader.cs @@ -1,5 +1,3 @@ -using System; - namespace ValveKeyValue { public class KVHeader diff --git a/ValveKeyValue/ValveKeyValue/KeyValues3/Encoding.cs b/ValveKeyValue/ValveKeyValue/KeyValues3/Encoding.cs index 3bfac429..d2f6b21b 100644 --- a/ValveKeyValue/ValveKeyValue/KeyValues3/Encoding.cs +++ b/ValveKeyValue/ValveKeyValue/KeyValues3/Encoding.cs @@ -1,5 +1,3 @@ -using System; - namespace ValveKeyValue.KeyValues3 { public class Encoding diff --git a/ValveKeyValue/ValveKeyValue/KeyValues3/Format.cs b/ValveKeyValue/ValveKeyValue/KeyValues3/Format.cs index 017efd84..b2c6ebb2 100644 --- a/ValveKeyValue/ValveKeyValue/KeyValues3/Format.cs +++ b/ValveKeyValue/ValveKeyValue/KeyValues3/Format.cs @@ -1,5 +1,3 @@ -using System; - namespace ValveKeyValue.KeyValues3 { public class Format diff --git a/ValveKeyValue/ValveKeyValue/Serialization/KeyValues1/KV1TextSerializer.cs b/ValveKeyValue/ValveKeyValue/Serialization/KeyValues1/KV1TextSerializer.cs index 31f736a8..57a1bfe3 100644 --- a/ValveKeyValue/ValveKeyValue/Serialization/KeyValues1/KV1TextSerializer.cs +++ b/ValveKeyValue/ValveKeyValue/Serialization/KeyValues1/KV1TextSerializer.cs @@ -21,7 +21,7 @@ public KV1TextSerializer(Stream stream, KVSerializerOptions options) readonly KVSerializerOptions options; readonly TextWriter writer; int indentation = 0; - Stack arrayCount = new(); + readonly Stack arrayCount = new(); public void Dispose() { diff --git a/ValveKeyValue/ValveKeyValue/Serialization/KeyValues3/KV3TextSerializer.cs b/ValveKeyValue/ValveKeyValue/Serialization/KeyValues3/KV3TextSerializer.cs index 715f8bea..d330ddc9 100644 --- a/ValveKeyValue/ValveKeyValue/Serialization/KeyValues3/KV3TextSerializer.cs +++ b/ValveKeyValue/ValveKeyValue/Serialization/KeyValues3/KV3TextSerializer.cs @@ -1,6 +1,3 @@ -using System; -using System.Collections.Generic; -using System.IO; using System.Text; using ValveKeyValue.Abstraction; @@ -23,7 +20,7 @@ public KV3TextSerializer(Stream stream) readonly TextWriter writer; int indentation = 0; - Stack inArray = new(); + readonly Stack inArray = new(); bool IsInArray => inArray.Count > 0 && inArray.Peek(); diff --git a/ValveKeyValue/ValveKeyValue/Utils.cs b/ValveKeyValue/ValveKeyValue/Utils.cs deleted file mode 100644 index 5d4f8282..00000000 --- a/ValveKeyValue/ValveKeyValue/Utils.cs +++ /dev/null @@ -1,42 +0,0 @@ -using System; -using System.Globalization; - -namespace ValveKeyValue -{ - internal class Utils - { - // TODO: Need to figure out whether Array.Reverse is actually correct for kv1 - public static byte[] ParseHexStringAsByteArrayNoReverse(string hexadecimalRepresentation) - { - Require.NotNull(hexadecimalRepresentation, nameof(hexadecimalRepresentation)); - - var data = new byte[hexadecimalRepresentation.Length / 2]; - for (var i = 0; i < data.Length; i++) - { - var currentByteText = hexadecimalRepresentation.Substring(i * 2, 2); - data[i] = byte.Parse(currentByteText, NumberStyles.HexNumber, CultureInfo.InvariantCulture); - } - - return data; - } - - public static byte[] ParseHexStringAsByteArray(string hexadecimalRepresentation) - { - Require.NotNull(hexadecimalRepresentation, nameof(hexadecimalRepresentation)); - - var data = new byte[hexadecimalRepresentation.Length / 2]; - for (var i = 0; i < data.Length; i++) - { - var currentByteText = hexadecimalRepresentation.Substring(i * 2, 2); - data[i] = byte.Parse(currentByteText, NumberStyles.HexNumber, CultureInfo.InvariantCulture); - } - - if (BitConverter.IsLittleEndian) - { - Array.Reverse(data); - } - - return data; - } - } -}