projects
/
biaweb2.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Refactored template loading to its own class for performance
[biaweb2.git]
/
biawebutil.hpp
diff --git
a/biawebutil.hpp
b/biawebutil.hpp
index
c8603ea
..
279d394
100644
(file)
--- a/
biawebutil.hpp
+++ b/
biawebutil.hpp
@@
-1,6
+1,7
@@
#ifndef __BIAWEBUTIL__
#define __BIAWEBUTIL__
#include <string>
#ifndef __BIAWEBUTIL__
#define __BIAWEBUTIL__
#include <string>
+#include <fstream>
// "discount" markdown library is a C library and hence requires to be wrapped in
// extern "C"
// "discount" markdown library is a C library and hence requires to be wrapped in
// extern "C"
@@
-11,6
+12,13
@@
extern "C" {
// utility functions for Biaweb that don't fit into any class and can be used by
// any class
namespace biaweb {
// utility functions for Biaweb that don't fit into any class and can be used by
// any class
namespace biaweb {
+ // load a string from file
+ std::string load_from_file (std::string filename) {
+ std::ifstream f (filename);
+ std::string r ((std::istreambuf_iterator<char> (f)),
+ (std::istreambuf_iterator<char> ()));
+ return r;
+ }
// convert markdown
std::string convert_to_markdown (std::string str) {
// convert markdown
std::string convert_to_markdown (std::string str) {
@@
-29,11
+37,7
@@
namespace biaweb {
FILE *f = fdopen (fd, "w");
markdown (doc, f, 0);
fclose (f);
FILE *f = fdopen (fd, "w");
markdown (doc, f, 0);
fclose (f);
- std::ifstream ftmp (tempfile);
- std::string tmpl ( (std::istreambuf_iterator<char> (ftmp)),
- (std::istreambuf_iterator<char> ())
- );
- ftmp.close ();
+ std::string tmpl = load_from_file (tempfile);
mkd_cleanup (doc);
remove (tempfile);
return tmpl;
mkd_cleanup (doc);
remove (tempfile);
return tmpl;