예제 #1
0
파일: xhtml.c 프로젝트: bnoordhuis/upskirt
static void
rndr_smartypants(struct buf *ob, struct buf *text, void *opaque)
{
	struct xhtml_renderopt *options = opaque;
	size_t i;

	if (!text)
		return;

	for (i = 0; i < text->size; ++i) {
		size_t sub;
		char c = text->data[i];

		for (sub = 0; sub < SUBS_COUNT; ++sub) {
			if (c == smartypants_subs[sub].c0 &&
				smartypants_cmpsub(text, i, smartypants_subs[sub].pattern)) {

				if (smartypants_subs[sub].entity)
					bufputs(ob, smartypants_subs[sub].entity);

				i += smartypants_subs[sub].skip;
				break;
			}
		}

		if (sub < SUBS_COUNT)
			continue;

		switch (c) {
		case '\"':
			if (smartypants_quotes(ob, text, i, options->quotes.in_dquote)) {
				options->quotes.in_dquote = !options->quotes.in_dquote;
				continue;
			}
			break;

		case '\'':
			if (smartypants_quotes(ob, text, i, options->quotes.in_squote)) {
				options->quotes.in_squote = !options->quotes.in_squote;
				continue;
			}
			break;
		}

		/*
		 * Copy raw character
		 */
		put_scaped_char(ob, c);
	}
}
예제 #2
0
파일: render.c 프로젝트: rcstolle/redcarpet
/* Smarty-pants-style chrome for quotes, -, ellipses, and (r)(c)(tm)
 */
static void
smartypants(struct buf *ob, struct buf *text)
{
	size_t i;
	int open_single = 0, open_double = 0;

	for (i = 0; i < text->size; ++i) {
		size_t sub;
		char c = text->data[i];

		for (sub = 0; sub < SUBS_COUNT; ++sub) {
			if (c == smartypants_subs[sub].c0 &&
				smartypants_cmpsub(text, i, smartypants_subs[sub].pattern)) {

				if (smartypants_subs[sub].entity)
					bufputs(ob, smartypants_subs[sub].entity);

				i += smartypants_subs[sub].skip;
				break;
			}
		}

		if (sub < SUBS_COUNT)
			continue;

		switch (c) {
		case '\"':
			bufputs(ob, smartypants_dquotes[open_double]);
			open_double = !open_double;
			continue;

		case '\'':
			bufputs(ob, smartypants_squotes[open_single]);
			open_single = !open_single;
			continue;

			/* TODO: advanced quotes like `` and '' */
		}

		bufputc(ob, text->data[i]);
	}

} /* smartypants */