summaryrefslogtreecommitdiff
path: root/src/blocks.c
diff options
context:
space:
mode:
authorJohn MacFarlane <jgm@berkeley.edu>2016-02-06 14:52:12 -0800
committerJohn MacFarlane <jgm@berkeley.edu>2016-02-06 14:52:12 -0800
commit455e59fa39fb3cd18a1f01b31eea5ead26fbf7c4 (patch)
tree51242db330904425eb2e1119bd4a6402d30b6833 /src/blocks.c
parent22fa64426a24df5b906bf39e718acf1d64e5d8cf (diff)
Clarify logic in S_advance_offset.
Diffstat (limited to 'src/blocks.c')
-rw-r--r--src/blocks.c21
1 files changed, 16 insertions, 5 deletions
diff --git a/src/blocks.c b/src/blocks.c
index 20ea579..ff102c9 100644
--- a/src/blocks.c
+++ b/src/blocks.c
@@ -17,6 +17,10 @@
#define CODE_INDENT 4
#define TAB_STOP 4
+#ifndef MIN
+#define MIN(x, y) ((x < y) ? x : y)
+#endif
+
#define peek_at(i, n) (i)->data[n]
static inline bool S_is_line_end_char(char c) {
@@ -587,11 +591,18 @@ static void S_advance_offset(cmark_parser *parser, cmark_chunk *input,
while (count > 0 && (c = peek_at(input, parser->offset))) {
if (c == '\t') {
chars_to_tab = TAB_STOP - (parser->column % TAB_STOP);
- parser->partially_consumed_tab = columns && chars_to_tab > count;
- chars_to_advance = parser->partially_consumed_tab ? count : chars_to_tab;
- parser->column += chars_to_advance;
- parser->offset += parser->partially_consumed_tab ? 0 : 1;
- count -= (columns ? chars_to_advance : 1);
+ if (columns) {
+ parser->partially_consumed_tab = chars_to_tab > count;
+ chars_to_advance = MIN(count, chars_to_tab);
+ parser->column += chars_to_advance;
+ parser->offset += (parser->partially_consumed_tab ? 0 : 1);
+ count -= chars_to_advance;
+ } else {
+ parser->partially_consumed_tab = false;
+ parser->column += chars_to_tab;
+ parser->offset += 1;
+ count -= 1;
+ }
} else {
parser->partially_consumed_tab = false;
parser->offset += 1;