fixed error in entab that left more than minimum required spaces and tabs#100
fixed error in entab that left more than minimum required spaces and tabs#100TimmyTheTaterTot wants to merge 2 commits intoohkimur:mainfrom
Conversation
WalkthroughA single C file was updated to explicitly preserve input tab characters: tabs now reset the accumulated-space counter, are emitted directly, and advance the column position to the next tab stop. Space-to-tab conversion remains for runs of spaces at tab boundaries. Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
📜 Recent review detailsConfiguration used: Organization UI Review profile: CHILL Plan: Pro 📒 Files selected for processing (1)
🔇 Additional comments (3)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
chapter_1/exercise_1_21/entab.c (1)
16-18: Consider the space-to-tab conversion algorithm limitations.The current algorithm only converts spaces to tabs when reaching exact tab stop boundaries (
line_pos % TAB_LENGTH == 0). This means sequences like 7 spaces followed by a non-space character will output 7 spaces, rather than converting to a tab + spaces.This is a valid algorithm design for a simple entab implementation (convert only at tab stops), but be aware that it won't produce minimal output for all cases.
Example: " x" (7 spaces + 'x') at the start of a line will output as-is, but could be "\tx" (tab + 'x' would position at column 8, then backtrack with spaces if needed, though that's more complex).
I noticed that the included solution was leaving extra unneeded spaces where a tab would have just sufficed. For example, with the input "Hello, \t\t \tWorld!" (just replace \t with the actual tab character to test that for example). Just added a base case to catch \t and insert them rather than inserting nr_spaces THEN the tab character.
Summary by CodeRabbit
✏️ Tip: You can customize this high-level summary in your review settings.