|
|
@@ -0,0 +1,49 @@ |
|
|
|
#include "cms_post.h" |
|
|
|
#include <stdlib.h> |
|
|
|
#include <stddef.h> |
|
|
|
#include <string.h> |
|
|
|
|
|
|
|
cms_post* cms_post_create() |
|
|
|
{ |
|
|
|
cms_post* post = malloc(sizeof(cms_post)); |
|
|
|
return post; |
|
|
|
} |
|
|
|
|
|
|
|
int cms_post_parse(cms_post* post, char* str) |
|
|
|
{ |
|
|
|
//Adding 1 because strlen() returns the length without \0 |
|
|
|
size_t len = strlen(str) + 1; |
|
|
|
|
|
|
|
post->_str = malloc(len * sizeof(char)); |
|
|
|
memcpy(post->_str, str, len * sizeof(char)); |
|
|
|
|
|
|
|
post->title = post->_str; |
|
|
|
|
|
|
|
size_t line = 0; |
|
|
|
for (size_t i = 0; i < len; ++i) |
|
|
|
{ |
|
|
|
char c = str[i]; |
|
|
|
|
|
|
|
switch (c) |
|
|
|
{ |
|
|
|
case '\n': |
|
|
|
line += 1; |
|
|
|
if (line == 1) |
|
|
|
post->slug = (post->_str + i + 1); |
|
|
|
else if (line == 2) |
|
|
|
post->markdown = (post->_str + i + 1); |
|
|
|
|
|
|
|
case '\r': |
|
|
|
post->_str[i] = '\0'; |
|
|
|
break; |
|
|
|
} |
|
|
|
|
|
|
|
if (line == 3) |
|
|
|
break; |
|
|
|
} |
|
|
|
|
|
|
|
if (line == 3) |
|
|
|
return 0; |
|
|
|
else |
|
|
|
return 1; |
|
|
|
} |