Skip to content

Commit

Permalink
Rename functions.
Browse files Browse the repository at this point in the history
cmark_is_block -> cmark_node_is_block
and similarly for cmark_is_leaf, cmark_is_inline
  • Loading branch information
jgm committed Sep 5, 2024
1 parent e1b44d7 commit 164d9e4
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 12 deletions.
19 changes: 19 additions & 0 deletions api_test/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,24 @@ static void constructor(test_batch_runner *runner) {
}
}

static void classifiers(test_batch_runner *runner) {
cmark_node *node = cmark_node_new(CMARK_NODE_BLOCK_QUOTE);
OK(runner, cmark_node_is_block(node), "is block CMARK_NODE_BLOCK_QUOTE");
OK(runner, !cmark_node_is_inline(node), "is not inline CMARK_NODE_BLOCK_QUOTE");
OK(runner, !cmark_node_is_leaf(node), "is not leaf CMARK_NODE_BLOCK_QUOTE");
cmark_node_free(node);
node = cmark_node_new(CMARK_NODE_EMPH);
OK(runner, !cmark_node_is_block(node), "is not block CMARK_NODE_EMPH");
OK(runner, cmark_node_is_inline(node), "is inline CMARK_NODE_EMPH");
OK(runner, !cmark_node_is_leaf(node), "is not leaf CMARK_NODE_EMPH");
cmark_node_free(node);
node = cmark_node_new(CMARK_NODE_THEMATIC_BREAK);
OK(runner, cmark_node_is_block(node), "is block CMARK_NODE_THEMATIC_BREAK");
OK(runner, !cmark_node_is_inline(node), "is not inline CMARK_NODE_THEMATIC_BREAK");
OK(runner, cmark_node_is_leaf(node), "is leaf CMARK_NODE_THEMATIC_BREAK");
cmark_node_free(node);
}

static void accessors(test_batch_runner *runner) {
static const char markdown[] = "## Header\n"
"\n"
Expand Down Expand Up @@ -1142,6 +1160,7 @@ int main(void) {

version(runner);
constructor(runner);
classifiers(runner);
accessors(runner);
free_parent(runner);
node_check(runner);
Expand Down
8 changes: 4 additions & 4 deletions man/man3/cmark.3
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.TH cmark 3 "September 02, 2024" "cmark 0.31.1" "Library Functions Manual"
.TH cmark 3 "September 05, 2024" "cmark 0.31.1" "Library Functions Manual"
.SH
NAME
.PP
Expand Down Expand Up @@ -125,19 +125,19 @@ Returns a pointer to the default memory allocator.
Classifying nodes

.PP
\fIbool\f[] \fBcmark_is_block\f[](\fIcmark_node *node\f[])
\fIbool\f[] \fBcmark_node_is_block\f[](\fIcmark_node *node\f[])

.PP
Returns true if the node is a block node. */

.PP
\fIbool\f[] \fBcmark_is_inline\f[](\fIcmark_node *node\f[])
\fIbool\f[] \fBcmark_node_is_inline\f[](\fIcmark_node *node\f[])

.PP
Returns true if the node is an inline node. */

.PP
\fIbool\f[] \fBcmark_is_leaf\f[](\fIcmark_node *node\f[])
\fIbool\f[] \fBcmark_node_is_leaf\f[](\fIcmark_node *node\f[])

.PP
Returns true if the node is a leaf node (a node that cannot contain
Expand Down
6 changes: 3 additions & 3 deletions src/cmark.h
Original file line number Diff line number Diff line change
Expand Up @@ -111,16 +111,16 @@ CMARK_EXPORT cmark_mem *cmark_get_default_mem_allocator(void);

/** Returns true if the node is a block node.
*/
CMARK_EXPORT bool cmark_is_block(cmark_node *node);
CMARK_EXPORT bool cmark_node_is_block(cmark_node *node);

/** Returns true if the node is an inline node.
*/
CMARK_EXPORT bool cmark_is_inline(cmark_node *node);
CMARK_EXPORT bool cmark_node_is_inline(cmark_node *node);

/** Returns true if the node is a leaf node (a node that cannot
contain children).
*/
CMARK_EXPORT bool cmark_is_leaf(cmark_node *node);
CMARK_EXPORT bool cmark_node_is_leaf(cmark_node *node);

/**
* ## Creating and Destroying Nodes
Expand Down
10 changes: 5 additions & 5 deletions src/node.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,23 @@

static void S_node_unlink(cmark_node *node);

bool cmark_is_block(cmark_node *node) {
bool cmark_node_is_block(cmark_node *node) {
if (node == NULL) {
return false;
}
return node->type >= CMARK_NODE_FIRST_BLOCK &&
node->type <= CMARK_NODE_LAST_BLOCK;
}

bool cmark_is_inline(cmark_node *node) {
bool cmark_node_is_inline(cmark_node *node) {
if (node == NULL) {
return false;
}
return node->type >= CMARK_NODE_FIRST_INLINE &&
node->type <= CMARK_NODE_LAST_INLINE;
}

bool cmark_is_leaf(cmark_node *node) {
bool cmark_node_is_leaf(cmark_node *node) {
if (node == NULL) {
return false;
}
Expand Down Expand Up @@ -63,7 +63,7 @@ static bool S_can_contain(cmark_node *node, cmark_node *child) {
case CMARK_NODE_DOCUMENT:
case CMARK_NODE_BLOCK_QUOTE:
case CMARK_NODE_ITEM:
return cmark_is_block(child) && child->type != CMARK_NODE_ITEM;
return cmark_node_is_block(child) && child->type != CMARK_NODE_ITEM;

case CMARK_NODE_LIST:
return child->type == CMARK_NODE_ITEM;
Expand All @@ -78,7 +78,7 @@ static bool S_can_contain(cmark_node *node, cmark_node *child) {
case CMARK_NODE_LINK:
case CMARK_NODE_IMAGE:
case CMARK_NODE_CUSTOM_INLINE:
return cmark_is_inline(child);
return cmark_node_is_inline(child);

default:
break;
Expand Down

0 comments on commit 164d9e4

Please sign in to comment.