From b2dac901288a3431fdadd9bbefb7875596a13e4d Mon Sep 17 00:00:00 2001 From: Nick Wellnhofer Date: Sat, 22 Nov 2014 17:23:37 +0100 Subject: Make parser accept a char* --- api_test/main.c | 4 ++-- src/blocks.c | 16 ++++++++-------- src/cmark.c | 2 +- src/cmark.h | 6 +++--- src/main.c | 2 +- 5 files changed, 15 insertions(+), 15 deletions(-) diff --git a/api_test/main.c b/api_test/main.c index a946c1a..b3b5b5a 100644 --- a/api_test/main.c +++ b/api_test/main.c @@ -76,7 +76,7 @@ constructor(test_batch_runner *runner) static void accessors(test_batch_runner *runner) { - static const unsigned char markdown[] = + static const char markdown[] = "## Header\n" "\n" "* Item 1\n" @@ -445,7 +445,7 @@ render_html(test_batch_runner *runner) { char *html; - static const unsigned char markdown[] = + static const char markdown[] = "foo *bar*\n" "\n" "paragraph 2\n"; diff --git a/src/blocks.c b/src/blocks.c index ab9f667..a30560f 100644 --- a/src/blocks.c +++ b/src/blocks.c @@ -416,13 +416,13 @@ static cmark_node *finalize_document(cmark_doc_parser *parser) extern cmark_node *cmark_parse_file(FILE *f) { - unsigned char buffer[4096]; + char buffer[4096]; cmark_doc_parser *parser = cmark_new_doc_parser(); size_t offset; cmark_node *document; - while (fgets((char *)buffer, sizeof(buffer), f)) { - offset = strlen((char *)buffer); + while (fgets(buffer, sizeof(buffer), f)) { + offset = strlen(buffer); cmark_process_line(parser, buffer, offset); } @@ -431,16 +431,16 @@ extern cmark_node *cmark_parse_file(FILE *f) return document; } -extern cmark_node *cmark_parse_document(const unsigned char *buffer, size_t len) +extern cmark_node *cmark_parse_document(const char *buffer, size_t len) { int linenum = 1; - const unsigned char *end = buffer + len; + const char *end = buffer + len; size_t offset; cmark_doc_parser *parser = cmark_new_doc_parser(); cmark_node *document; while (buffer < end) { - const unsigned char *eol = (unsigned char *)memchr(buffer, '\n', end - buffer); + const char *eol = memchr(buffer, '\n', end - buffer); offset = eol ? (eol - buffer) + 1 : eol - buffer; cmark_process_line(parser, buffer, offset); buffer += offset; @@ -470,7 +470,7 @@ static void chop_trailing_hashtags(chunk *ch) } } -void cmark_process_line(cmark_doc_parser *parser, const unsigned char *buffer, +void cmark_process_line(cmark_doc_parser *parser, const char *buffer, size_t bytes) { cmark_node* last_matched_container; @@ -487,7 +487,7 @@ void cmark_process_line(cmark_doc_parser *parser, const unsigned char *buffer, int indent; chunk input; - utf8proc_detab(parser->curline, buffer, bytes); + utf8proc_detab(parser->curline, (unsigned char *)buffer, bytes); // Add a newline to the end if not present: // TODO this breaks abstraction: diff --git a/src/cmark.c b/src/cmark.c index 07b7c4c..273a37b 100644 --- a/src/cmark.c +++ b/src/cmark.c @@ -7,7 +7,7 @@ #include "cmark.h" #include "buffer.h" -char *cmark_markdown_to_html(unsigned char *text, int len) +char *cmark_markdown_to_html(const char *text, int len) { cmark_node *blocks; char *result; diff --git a/src/cmark.h b/src/cmark.h index 206b667..6131024 100644 --- a/src/cmark.h +++ b/src/cmark.h @@ -176,10 +176,10 @@ CMARK_EXPORT cmark_node *cmark_finish(cmark_doc_parser *parser); CMARK_EXPORT -void cmark_process_line(cmark_doc_parser *parser, const unsigned char *buffer, size_t bytes); +void cmark_process_line(cmark_doc_parser *parser, const char *buffer, size_t bytes); CMARK_EXPORT -cmark_node *cmark_parse_document(const unsigned char *buffer, size_t len); +cmark_node *cmark_parse_document(const char *buffer, size_t len); CMARK_EXPORT cmark_node *cmark_parse_file(FILE *f); @@ -193,7 +193,7 @@ CMARK_EXPORT char *cmark_render_html(cmark_node *root); CMARK_EXPORT -char *cmark_markdown_to_html(unsigned char *text, int len); +char *cmark_markdown_to_html(const char *text, int len); #ifndef CMARK_NO_SHORT_NAMES #define NODE_DOCUMENT CMARK_NODE_DOCUMENT diff --git a/src/main.c b/src/main.c index 61d98dc..96e53ce 100644 --- a/src/main.c +++ b/src/main.c @@ -33,7 +33,7 @@ int main(int argc, char *argv[]) int i, numfps = 0; bool ast = false; int *files; - unsigned char buffer[4096]; + char buffer[4096]; cmark_doc_parser *parser; size_t offset; cmark_node *document; -- cgit v1.2.3