Add Encoding.WithoutPreamble() extension method#28
Merged
Conversation
Agent-Logs-Url: https://github.com/Tyrrrz/PowerKit/sessions/8c7ef6da-8614-4f0c-9c03-def636b66214 Co-authored-by: Tyrrrz <1935960+Tyrrrz@users.noreply.github.com>
Copilot created this pull request from a session on behalf of
Tyrrrz
April 14, 2026 19:30
View session
Tyrrrz
approved these changes
Apr 14, 2026
Contributor
There was a problem hiding this comment.
Pull request overview
Adds a general-purpose way to strip BOM/preamble from any Encoding by introducing an Encoding.WithoutPreamble() extension and refactoring Encoding.Utf8WithoutBom to use it.
Changes:
- Added a file-local
NoPreambleEncodingwrapper that overridesGetPreamble()to return an empty preamble while delegating encoding/decoding operations to an innerEncoding. - Added
Encoding.WithoutPreamble()extension that returns the original encoding when it already has no preamble, otherwise wraps it. - Updated
Utf8WithoutBomto useEncoding.UTF8.WithoutPreamble()and added tests for the new behavior.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| PowerKit/Extensions/EncodingExtensions.cs | Implements NoPreambleEncoding, adds WithoutPreamble(), and updates Utf8WithoutBom to use the new extension. |
| PowerKit.Tests/EncodingExtensionsTests.cs | Adds unit tests covering WithoutPreamble() behavior and instance-return semantics. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
…ecoder, fix net35 compatibility Agent-Logs-Url: https://github.com/Tyrrrz/PowerKit/sessions/c5fdc587-3fa8-4564-a9cd-54d151626c61 Co-authored-by: Tyrrrz <1935960+Tyrrrz@users.noreply.github.com>
Owner
|
@copilot build errors |
…te[0] for GetPreamble Agent-Logs-Url: https://github.com/Tyrrrz/PowerKit/sessions/92664b43-fcf9-43aa-985b-07da7fd12b5b Co-authored-by: Tyrrrz <1935960+Tyrrrz@users.noreply.github.com>
Contributor
Author
Fixed in 7c11b70. Two net35 build errors:
|
This was referenced May 1, 2026
This was referenced May 1, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds a general-purpose
Encoding.WithoutPreamble()extension that produces a derived encoding with an empty preamble, applicable to anyEncoding— not just UTF-8.Changes
NoPreambleEncoding(file-local) — sealed wrapper that delegates all abstract encode/decode methods and identity properties (CodePage,EncodingName,WebName, etc.) to the inner encoding, overriding onlyGetPreamble()to returnArray.Empty<byte>()WithoutPreamble()extension — returnsthisif the encoding already has no preamble; otherwise wraps inNoPreambleEncodingUtf8WithoutBomupdated — now implemented viaEncoding.UTF8.WithoutPreamble()instead ofnew UTF8Encoding(false)Usage