Add TOON format encoding and decoding functionality#2
Add TOON format encoding and decoding functionality#2ghost1face merged 9 commits intotoon-format:mainfrom
Conversation
- Implement StringUtils for string manipulation, including escaping and unescaping. - Create ValidationShared for key validation and safety checks. - Introduce ToonDecodeOptions and ToonEncodeOptions for customizable encoding/decoding settings. - Develop ToonDecoder for parsing TOON format strings into JsonNode objects. - Implement ToonEncoder for converting data structures into TOON format strings. - Add ToonFormatException for error handling during parsing and encoding. - Create unit tests for ToonDecoder and ToonEncoder to ensure functionality and data integrity. - Remove outdated UnitTest1.cs file.
There was a problem hiding this comment.
Pull Request Overview
This PR implements the complete TOON format encoder and decoder functionality, replacing the placeholder implementations. TOON is a data serialization format that provides human-readable encoding/decoding of structured data with support for arrays, objects, and primitive types.
Key changes:
- Implements encoding logic to convert .NET objects to TOON format strings
- Implements decoding logic to parse TOON format strings back into JSON structures
- Adds comprehensive test coverage for encoding, decoding, and round-trip scenarios
- Introduces encoding/decoding options with customizable indentation, delimiters, and validation modes
Reviewed Changes
Copilot reviewed 25 out of 25 changed files in this pull request and generated 17 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/ToonFormat.Tests/UnitTest1.cs | Removed placeholder tests that checked for NotImplementedException |
| tests/ToonFormat.Tests/ToonRoundTripTests.cs | Added round-trip tests verifying encoding and decoding preserve data integrity |
| tests/ToonFormat.Tests/ToonEncoderTests.cs | Added comprehensive encoder tests covering primitives, arrays, objects, and formatting options |
| tests/ToonFormat.Tests/ToonDecoderTests.cs | Added decoder tests for parsing TOON strings into JSON structures |
| src/ToonFormat/ToonFormatException.cs | Added custom exception type with error categorization and contextual error messages |
| src/ToonFormat/ToonFormat.csproj | Added empty folder placeholders for internal encoder/decoder organization |
| src/ToonFormat/ToonEncoder.cs | Implemented TOON encoder with multiple overloads for encoding to strings, bytes, and streams |
| src/ToonFormat/ToonDecoder.cs | Implemented TOON decoder with multiple overloads for decoding from strings, bytes, and streams |
| src/ToonFormat/Options/ToonEncodeOptions.cs | Added encoding configuration options (indent, delimiter, length marker) |
| src/ToonFormat/Options/ToonDecodeOptions.cs | Added decoding configuration options (indent, strict mode) |
| src/ToonFormat/Internal/Shared/ValidationShared.cs | Added validation utilities for key and value quoting rules |
| src/ToonFormat/Internal/Shared/StringUtils.cs | Added string escaping/unescaping and quote handling utilities |
| src/ToonFormat/Internal/Shared/LiteralUtils.cs | Added literal type detection for booleans, null, and numbers |
| src/ToonFormat/Internal/Encode/Primitives.cs | Implemented primitive value encoding and header formatting |
| src/ToonFormat/Internal/Encode/Normalize.cs | Implemented .NET object to JsonNode normalization |
| src/ToonFormat/Internal/Encode/LineWriter.cs | Added utility for building indented TOON output |
| src/ToonFormat/Internal/Encode/Encoders.cs | Implemented main encoding logic for objects, arrays, and nested structures |
| src/ToonFormat/Internal/Decode/Validation.cs | Added decoding validation logic for strict mode checks |
| src/ToonFormat/Internal/Decode/Scanner.cs | Implemented source text scanning into structured lines with depth tracking |
| src/ToonFormat/Internal/Decode/Parser.cs | Implemented TOON format parsing for headers, values, and tokens |
| src/ToonFormat/Internal/Decode/Decoders.cs | Implemented main decoding logic for converting TOON to JSON structures |
| src/ToonFormat/Internal/Converters/SingleNamedFloatToNullConverter.cs | Added JSON converter to normalize float NaN/Infinity to null |
| src/ToonFormat/Internal/Converters/DoubleNamedFloatToNullConverter.cs | Added JSON converter to normalize double NaN/Infinity to null |
| src/ToonFormat/Constants.cs | Added shared constants for TOON format structural characters and delimiters |
| src/ToonFormat/Class1.cs | Removed placeholder implementation file |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
|
Hi @239573049 thanks for your contribution, we've recently just formed this repo and team, so we're forming some initial plans before we start taking contributions. We will definitely keep this for consideration! |
|
@239573049 I'm creating a new pull request which builds on your changes to add support for PathExpansion and KeyFolding with passing test coverage according to the V2 spec |
|
@ghost1face Thanks for being on it! @239573049 Would you mind commenting on the Copilot issues? If the teams wants, they can merge this PR and then build upon it. I'd love to see the repo take shape, so thanks for all the contributions. |
|
I will first attempt to merge the content provided by Copilot |
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Optimize the performance of the `ParseDelimitedValues` and `ToParsedLines` methods: - Reduce memory allocation by using `StringBuilder` and `ReadOnlySpan<char>`. - Allocate capacity in advance to avoid dynamic resizing. - Replace string operations with more efficient logic. Fix the code formatting and logic of `IsArrayHeaderAfterHyphen` and `ParseStringLiteral`: - Adjust the format of the `return` statement. - Eliminate redundant code. New `MapRowValuesToPrimitives` method: - Supports mapping string arrays to JSON primitive values. Other minor optimizations: - Fixed the logic for handling blank lines. - Replaced some string operations with more efficient implementations. - Fixed the issue of character encoding in comments, improving code readability.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
…rs, and a new FloatUtils utility class has been added. Introduce the FloatUtils utility class and provide the NormalizeSignedZero method, to uniformly handle the logic of negated zero normalization for floating-point numbers, replacing the original repetitive implementations. Update the relevant code in Parser.cs and Normalize.cs to enhance readability. Add the NearlyEqual method for approximate comparison of floating-point numbers. Delete the references to the Internal\Shared\ folder.
ghost1face
left a comment
There was a problem hiding this comment.
Will approve and merge, I will be aligning several pieces for full spec validation and implementing missing pieces.
We'll also start to take contribution for minor enhancements such as @Daniel-iel 's recommendations as well.
Thanks for the help everyone!
Description
Type of Change
Related Issues
Closes #
Changes Made
SPEC Compliance
Testing
Checklist
dotnet formatAdditional Context