summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTzu-ping Chung <uranusjr@gmail.com>2014-08-10 02:03:54 +0800
committerTzu-ping Chung <uranusjr@gmail.com>2014-08-10 02:03:54 +0800
commit2301e4caa2ad89a9c442db9f49b58eb710fe837f (patch)
tree2700ce61ec7ecdbc61928737a514e6efdd3a70d2
parentc8544810924d00c36f0a3d7671b9402fa796fd92 (diff)
downloadrust-hoedown-2301e4caa2ad89a9c442db9f49b58eb710fe837f.tar.gz
Better logic to handle backslashes
is_escaped actually counts backslashes instead of looking back one character to determine whether a character is escaped. This handles inputs like *Foo\\* correctly (as `<p><em>Foo\<em></p>`; would be `<p>Foo\*</p>` previously).
-rw-r--r--src/document.c16
1 files changed, 15 insertions, 1 deletions
diff --git a/src/document.c b/src/document.c
index eecbb84..7e1858d 100644
--- a/src/document.c
+++ b/src/document.c
@@ -465,6 +465,20 @@ parse_inline(hoedown_buffer *ob, hoedown_document *doc, uint8_t *data, size_t si
}
}
+/* is_escaped • returns whether special char at data[loc] is escaped by '\\' */
+static int
+is_escaped(uint8_t *data, size_t loc)
+{
+ size_t i = loc;
+ while (i >= 1 && data[i - 1] == '\\')
+ i--;
+
+ /* odd numbers of backslashes escapes data[loc] */
+ if ((loc - i) % 2)
+ return 1;
+ return 0;
+}
+
/* find_emph_char • looks for the next emph uint8_t, skipping other constructs */
static size_t
find_emph_char(uint8_t *data, size_t size, uint8_t c)
@@ -479,7 +493,7 @@ find_emph_char(uint8_t *data, size_t size, uint8_t c)
return 0;
/* not counting escaped chars */
- if (i && data[i - 1] == '\\') {
+ if (is_escaped(data, i)) {
i++; continue;
}