refactor: deduplicate visual/source helpers, simplify fmtThousands#182
Merged
Merged
Conversation
Three behavior-preserving cleanups:
1. Extract visual.zig — Shared UTF-8 display-width module (visualWidth,
writeCharRepeated, writeSpaces) used by table.zig and markdown.zig.
Removed ~170 lines of verbatim duplication. 3 public fns, 4 private helpers.
2. Extract source.zig — Shared openInput() returning SourceFile{file, needs_close}
with deinit() method. Replaces 9 duplicate file-or-stdin switch blocks
across columns.zig, sample.zig, and validate.zig.
3. Simplify fmtThousands — Reduced 17-line implementation to 8 lines
using (digits.len - i) % 3 == 0 instead of first_group calculation.
All tests pass (zig build unit-test + zig build test, exit 0).
Net: +63 lines, -301 lines (-238 net).
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.
Three behavior-preserving cleanups reducing net code by -238 lines.
Changes
Extract visual.zig — Shared UTF-8 display-width module (visualWidth, writeCharRepeated, writeSpaces) used by
table.zigandmarkdown.zig. Removed ~170 lines of verbatim duplication. 3 public functions, 4 private helpers.Extract source.zig — Shared
openInput()returningSourceFile{file, needs_close}withdeinit()method. Replaces 9 duplicate file-or-stdin switch-with-error-handling blocks acrosscolumns.zig,sample.zig, andvalidate.zig.Simplify fmtThousands — Reduced 17-line implementation to 8 lines using
(digits.len - i) % 3 == 0instead of two-conditionfirst_groupcalculation. Oracle-reviewed for mathematical equivalence.Validation
zig build unit-test— ✅ (CSV unit tests with leak detection)zig build test— ✅ (120 integration tests + XML unit tests)@oraclesubagentFiles Changed
src/visual.zigsrc/modes/source.zigsrc/table.zigsrc/markdown.zigsrc/modes/columns.zigsrc/modes/validate.zigsrc/modes/sample.zigsrc/loader.zigCloses: — (internal cleanup, no issue)