As you see, I need to copy the
markdown_
string and make it achar*
. To do so, I used astd::vector
as suggested in Converting an std::string into a char array Converting an std::string into a char array, but I would like to know if doing it this way is appropriate in my case, or if there are other ways to achieve that.MMIOT *mkd_string(char *string, int size, int flags);
is defined in the main page to returnnull
on error. Is it correct to usenullptr
like I do in the following code to check the return value?Do you have suggestions to improve this code, or does it looks good?
As you see, I need to copy the
markdown_
string and make it achar*
. To do so, I used astd::vector
as suggested in Converting an std::string into a char array, but I would like to know if doing it this way is appropriate in my case, or if there are other ways to achieve that.MMIOT *mkd_string(char *string, int size, int flags);
is defined in the main page to returnnull
on error. Is it correct to usenullptr
like I do in the following code to check the return value?Do you have suggestions to improve this code, or does it looks good?
As you see, I need to copy the
markdown_
string and make it achar*
. To do so, I used astd::vector
as suggested in Converting an std::string into a char array, but I would like to know if doing it this way is appropriate in my case, or if there are other ways to achieve that.MMIOT *mkd_string(char *string, int size, int flags);
is defined in the main page to returnnull
on error. Is it correct to usenullptr
like I do in the following code to check the return value?Do you have suggestions to improve this code, or does it looks good?
Abstract
Abstract
I have little C/C++ skills, I. I've learned programming mainly with Java, and so I chose C++ (targeting C++11) as the language to learn better. In my current C++ project, I have to use the discount C library for its Markdown functions.
To explain briefly my code,: the member variable std::string markdown_
is the Markdown I want to "compile" to HTML. To do so, I have to use the following functions from discount:
Questions
Questions
As you see, I need to copy the
markdown_
string and make it achar*
. To do so, I used astd::vector
as suggested in Converting an std::string into a char array , but I would like to know if doing it this way is appropriate in my case, or if there are other ways to achieve that.MMIOT *mkd_string(char *string, int size, int flags);
is saiddefined in manthe main page to returnnull
on error. Is it correct to usenullptr
like I do in the following code to check the return value?Do you have suggestions to improve this code, or does it looks good?
Code extract
Code extract
Abstract
I have little C/C++ skills, I learned programming mainly with Java, and so I chose C++ (targeting C++11) as language to learn better. In my current C++ project I have to use the discount C library for its Markdown functions.
To explain briefly my code, the member variable std::string markdown_
is the Markdown I want to "compile" to HTML. To do so I have to use the following functions from discount:
Questions
As you see I need to copy the
markdown_
string and make it achar*
. To do so, I used astd::vector
as suggested in Converting an std::string into a char array but I would like to know if doing this way is appropriate in my case or if there are other ways to achieve that.MMIOT *mkd_string(char *string, int size, int flags);
is said in man page to returnnull
on error. Is it correct to usenullptr
like I do in the following code to check the return value?Do you have suggestions to improve this code or does it looks good?
Code extract
Abstract
I have little C/C++ skills. I've learned programming mainly with Java, and so I chose C++ (targeting C++11) as the language to learn better. In my current C++ project, I have to use the discount C library for its Markdown functions.
To explain briefly my code: the member variable std::string markdown_
is the Markdown I want to "compile" to HTML. To do so, I have to use the following functions from discount:
Questions
As you see, I need to copy the
markdown_
string and make it achar*
. To do so, I used astd::vector
as suggested in Converting an std::string into a char array , but I would like to know if doing it this way is appropriate in my case, or if there are other ways to achieve that.MMIOT *mkd_string(char *string, int size, int flags);
is defined in the main page to returnnull
on error. Is it correct to usenullptr
like I do in the following code to check the return value?Do you have suggestions to improve this code, or does it looks good?
Code extract
Abstract
I have little C/C++ skills, I learned programming mainly with Java, and so I chose C++ (targeting C++11) as language to learn better. In my current C++ project I have to use the discount C library for its Markdown functions.
To explain briefly my code, the member variable std::string markdown_
is the Markdown I want to "compile" to HTML. To do so I have to use the following functions from discount:
MMIOT *mkd_string(char *string, int size, int flags);
int mkd_compile(MMIOT *document, int flags);
int mkd_document(MMIOT *document, char **doc);
mkd_css
andmkd_toc
are alikemkd_document
Questions
As you see I need to copy the
markdown_
string and make it achar*
. To do so, I used astd::vector
as suggested in Converting an std::string into a char array but I would like to know if doing this way is appropriate in my case or if there are other ways to achieve that.MMIOT *mkd_string(char *string, int size, int flags);
is said in man page to returnnull
on error. Is it correct to usenullptr
like I do in the following code to check the return value?Do you have suggestions to improve this code or does it looks good?
Code extract
const std::string Markdown::error_msg_mkd_string = "libmarkdown failed to "
"parse the following Markdown:\n";
void Markdown::compile()
{
MMIOT* doc;
int size;
char *cstr_buff;
int flags = MKD_TOC|MKD_SAFELINK|MKD_EXTRA_FOOTNOTE;
std::vector<char> buff(markdown_.cbegin(), markdown_.cend());
doc = mkd_string(&buff[0], buff.size(), flags);
if(doc == nullptr)
throw std::runtime_error(
std::string(error_msg_mkd_string)
.append(&buff[0], buff.size())
);
mkd_compile(doc, flags);
// It is not a bad practice to reuse 'size' and 'cstr_buff' like in the
// following code, or is it?
size = mkd_css(doc, &cstr_buff);
css_.assign(cstr_buff, size);
size = mkd_document(doc, &cstr_buff);
html_.assign(cstr_buff, size);
size = mkd_toc(doc, &cstr_buff);
toc_.assign(cstr_buff, size);
mkd_cleanup(doc);
}
Abstract
I have little C/C++ skills, I learned programming mainly with Java, and so I chose C++ (targeting C++11) as language to learn better. In my current C++ project I have to use the discount C library for its Markdown functions.
To explain briefly my code, the member variable std::string markdown_
is the Markdown I want to "compile" to HTML. To do so I have to use the following functions from discount:
MMIOT *mkd_string(char *string, int size, int flags);
int mkd_compile(MMIOT *document, int flags);
int mkd_document(MMIOT *document, char **doc);
mkd_css
andmkd_toc
are alikemkd_document
Questions
As you see I need to copy the
markdown_
string and make it achar*
. To do so, I used astd::vector
as suggested in Converting an std::string into a char array but I would like to know if doing this way is appropriate in my case or if there are other ways to achieve that.MMIOT *mkd_string(char *string, int size, int flags);
is said in man page to returnnull
on error. Is it correct to usenullptr
like I do in the following code to check the return value?Do you have suggestions to improve this code or does it looks good?
Code extract
void Markdown::compile()
{
MMIOT* doc;
int size;
char *cstr_buff;
int flags = MKD_TOC|MKD_SAFELINK|MKD_EXTRA_FOOTNOTE;
std::vector<char> buff(markdown_.cbegin(), markdown_.cend());
doc = mkd_string(&buff[0], buff.size(), flags);
if(doc == nullptr)
throw std::runtime_error(
std::string(error_msg_mkd_string)
.append(&buff[0], buff.size())
);
mkd_compile(doc, flags);
// It is not a bad practice to reuse 'size' and 'cstr_buff' like in the
// following code, or is it?
size = mkd_css(doc, &cstr_buff);
css_.assign(cstr_buff, size);
size = mkd_document(doc, &cstr_buff);
html_.assign(cstr_buff, size);
size = mkd_toc(doc, &cstr_buff);
toc_.assign(cstr_buff, size);
mkd_cleanup(doc);
}
Abstract
I have little C/C++ skills, I learned programming mainly with Java, and so I chose C++ (targeting C++11) as language to learn better. In my current C++ project I have to use the discount C library for its Markdown functions.
To explain briefly my code, the member variable std::string markdown_
is the Markdown I want to "compile" to HTML. To do so I have to use the following functions from discount:
MMIOT *mkd_string(char *string, int size, int flags);
int mkd_compile(MMIOT *document, int flags);
int mkd_document(MMIOT *document, char **doc);
mkd_css
andmkd_toc
are alikemkd_document
Questions
As you see I need to copy the
markdown_
string and make it achar*
. To do so, I used astd::vector
as suggested in Converting an std::string into a char array but I would like to know if doing this way is appropriate in my case or if there are other ways to achieve that.MMIOT *mkd_string(char *string, int size, int flags);
is said in man page to returnnull
on error. Is it correct to usenullptr
like I do in the following code to check the return value?Do you have suggestions to improve this code or does it looks good?
Code extract
const std::string Markdown::error_msg_mkd_string = "libmarkdown failed to "
"parse the following Markdown:\n";
void Markdown::compile()
{
MMIOT* doc;
int size;
char *cstr_buff;
int flags = MKD_TOC|MKD_SAFELINK|MKD_EXTRA_FOOTNOTE;
std::vector<char> buff(markdown_.cbegin(), markdown_.cend());
doc = mkd_string(&buff[0], buff.size(), flags);
if(doc == nullptr)
throw std::runtime_error(
std::string(error_msg_mkd_string)
.append(&buff[0], buff.size())
);
mkd_compile(doc, flags);
// It is not a bad practice to reuse 'size' and 'cstr_buff' like in the
// following code, or is it?
size = mkd_css(doc, &cstr_buff);
css_.assign(cstr_buff, size);
size = mkd_document(doc, &cstr_buff);
html_.assign(cstr_buff, size);
size = mkd_toc(doc, &cstr_buff);
toc_.assign(cstr_buff, size);
mkd_cleanup(doc);
}