summaryrefslogtreecommitdiff
path: root/src/inlines.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/inlines.c')
-rw-r--r--src/inlines.c45
1 files changed, 26 insertions, 19 deletions
diff --git a/src/inlines.c b/src/inlines.c
index c8bdebc..a855c5a 100644
--- a/src/inlines.c
+++ b/src/inlines.c
@@ -515,17 +515,10 @@ static void process_emphasis(subject *subj, delimiter *stack_bottom) {
delimiter *opener;
delimiter *old_closer;
bool opener_found;
- bool odd_match;
- delimiter *openers_bottom[3][128];
- int i;
-
- // initialize openers_bottom:
- for (i=0; i < 3; i++) {
- openers_bottom[i]['*'] = stack_bottom;
- openers_bottom[i]['_'] = stack_bottom;
- openers_bottom[i]['\''] = stack_bottom;
- openers_bottom[i]['"'] = stack_bottom;
- }
+ int openers_bottom_index;
+ delimiter *openers_bottom[6] = { stack_bottom, stack_bottom,
+ stack_bottom, stack_bottom,
+ stack_bottom, stack_bottom };
// move back to first relevant delim.
while (closer != NULL && closer->previous != stack_bottom) {
@@ -535,18 +528,33 @@ static void process_emphasis(subject *subj, delimiter *stack_bottom) {
// now move forward, looking for closers, and handling each
while (closer != NULL) {
if (closer->can_close) {
+ switch (closer->delim_char) {
+ case '"':
+ openers_bottom_index = 0;
+ break;
+ case '\'':
+ openers_bottom_index = 1;
+ break;
+ case '_':
+ openers_bottom_index = 2;
+ break;
+ case '*':
+ openers_bottom_index = 3 + (closer->length % 3);
+ break;
+ default:
+ assert(false);
+ }
+
// Now look backwards for first matching opener:
opener = closer->previous;
opener_found = false;
- odd_match = false;
- while (opener != NULL && opener != stack_bottom &&
- opener != openers_bottom[closer->length % 3][closer->delim_char]) {
+ while (opener != NULL &&
+ opener != openers_bottom[openers_bottom_index]) {
if (opener->can_open && opener->delim_char == closer->delim_char) {
// interior closer of size 2 can't match opener of size 1
// or of size 1 can't match 2
- odd_match = (closer->can_open || opener->can_close) &&
- ((opener->length + closer->length) % 3 == 0);
- if (!odd_match) {
+ if (!(closer->can_open || opener->can_close) ||
+ ((opener->length + closer->length) % 3) != 0) {
opener_found = true;
break;
}
@@ -579,8 +587,7 @@ static void process_emphasis(subject *subj, delimiter *stack_bottom) {
}
if (!opener_found) {
// set lower bound for future searches for openers
- openers_bottom[old_closer->length % 3][old_closer->delim_char] =
- old_closer->previous;
+ openers_bottom[openers_bottom_index] = old_closer->previous;
if (!old_closer->can_open) {
// we can remove a closer that can't be an
// opener, once we've seen there's no