-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Refactor DataSegment handling for improved encoding support #677
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 7 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
41dbc0b
Refactor DataSegment class to support multiple encoding modes and imp…
Shane32 44afd0b
Refactor CreateDataSegment method to utilize specialized segment clas…
Shane32 00047e4
Refactor CreateDataSegment method to remove conditional compilation a…
Shane32 9740625
Add GetBitLength and WriteToBitArray methods to AlphanumericEncoder f…
Shane32 b3ea2f0
Refactor WriteToBitArray method to improve parameter naming for clarity
Shane32 474d6f1
Refactor ByteDataSegment to calculate character count directly from d…
Shane32 686e493
Refactor QR code data segment classes to improve encoding logic and s…
Shane32 f0329d7
Apply suggestions from code review
Shane32 82d32e6
Update QRCoder/QRCodeGenerator/NumericDataSegment.cs
Shane32 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,63 @@ | ||
| namespace QRCoder; | ||
|
|
||
| public partial class QRCodeGenerator | ||
| { | ||
| /// <summary> | ||
| /// Data segment optimized for alphanumeric data encoding. | ||
| /// </summary> | ||
| private class AlphanumericDataSegment : DataSegment | ||
| { | ||
| /// <summary> | ||
| /// Gets the encoding mode (always Alphanumeric) | ||
| /// </summary> | ||
| public override EncodingMode EncodingMode => EncodingMode.Alphanumeric; | ||
|
|
||
| /// <summary> | ||
| /// Initializes a new instance of the AlphanumericDataSegment class. | ||
| /// </summary> | ||
| /// <param name="alphanumericText">The alphanumeric text to encode</param> | ||
| public AlphanumericDataSegment(string alphanumericText) | ||
| : base(alphanumericText) | ||
| { | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Calculates the total bit length for this segment when encoded for a specific QR code version. | ||
| /// </summary> | ||
| /// <param name="version">The QR code version (1-40, or -1 to -4 for Micro QR)</param> | ||
| /// <returns>The total number of bits required for this segment</returns> | ||
| public override int GetBitLength(int version) | ||
| { | ||
| int modeIndicatorLength = 4; | ||
| int countIndicatorLength = GetCountIndicatorLength(version, EncodingMode.Alphanumeric); | ||
| int dataLength = AlphanumericEncoder.GetBitLength(Text); | ||
| int length = modeIndicatorLength + countIndicatorLength + dataLength; | ||
|
|
||
| return length; | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Writes this data segment to an existing BitArray at the specified index. | ||
| /// </summary> | ||
| /// <param name="bitArray">The target BitArray to write to</param> | ||
| /// <param name="startIndex">The starting index in the BitArray</param> | ||
| /// <param name="version">The QR code version (1-40, or -1 to -4 for Micro QR)</param> | ||
| /// <returns>The next index in the BitArray after the last bit written</returns> | ||
| public override int WriteTo(BitArray bitArray, int startIndex, int version) | ||
| { | ||
| var index = startIndex; | ||
|
|
||
| // write mode indicator | ||
| index = DecToBin((int)EncodingMode.Alphanumeric, 4, bitArray, index); | ||
|
|
||
| // write count indicator | ||
| int countIndicatorLength = GetCountIndicatorLength(version, EncodingMode.Alphanumeric); | ||
| index = DecToBin(Text.Length, countIndicatorLength, bitArray, index); | ||
|
|
||
| // write data - encode alphanumeric text | ||
| index = AlphanumericEncoder.WriteToBitArray(Text, bitArray, index); | ||
|
|
||
| return index; | ||
| } | ||
| } | ||
| } | ||
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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.