Hi all, I'm attempting to use boost::format, where my formatting string is the HTML below. I intend to insert 3x std::strings at locations specified by %s placeholders.
In other words - I'm opening the below *.html file for reading, read it's contents into a single std::string and use it as the formatter. Next I'm attempting to do the following :
std::string output = (boost::format(formatter) % str1 % str2 % str3).str();
Where str1-3 are strings containing text which I'm attempting to insert - obviously. The format attempt throws an exception saying that the format string is ill-formed. I've been trying to analyze it for the better part of the last 2 hrs but I've failed and I need some help.
What is wrong with the below HTML - why can't it become the proper formatter string? What are the limitations I should be aware of ?
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>KP&D</title>
<style type="text/css">
html, body
{
height: 100%;
margin: 0;
padding: 0;
}
img#bg
{
position:fixed;
top:0;
left:0;
width:100%;
height:100%;
}
#content
{
position:relative;
z-index:1;
}
</style>
</head>
<body>
<img src="Images/PageBackground.png" alt="background image" id="bg" />
<div id="content">
<br/>
<img src="Images/MyLogoReflected.png" alt="logo image"/>
<br />
<img src="Images/PDC_StatusPage.png" alt="remote status page image" />
<br />
<img src="Images/PDC_RemoteConfiguration.png" alt="remote config image" />
<br />
%s
<br />
<img src="Images/PDC_RemoteSubsystemStatus.png" alt="remote status image" />
<br />
%s
<br />
<img src="Images/PDC_RemoteConnectivityStatus.png" alt="remote status image" />
<br />
%s
<br />
</div>
</body>
</html>
Here's the code snippet responsible for loading the forementioned file :
#include <string>
#include <fstream>
#include <boost/algorithm/string.hpp>
#include <boost/format.hpp>
int main()
{
std::ifstream ifs("welcome.html"); // the html is in that file
if(!ifs.good())
return 1;
std::string buffer = "";
while(!ifs.eof())
{
char buf[256];
ifs.getline(buf, 256);
buffer += buf;
}
buffer = boost::trim_right_copy(buffer);
const std::string str1 = "aaa";
const std::string str2 = "bbb";
const std::string str3 = "ccc";
std::string Out = "";
try{
Out = (boost::format(buffer)
% str1
% str2
% str3
).str();
} catch(std::exception &e)
{
err = e.what();
return 1;
}
return 0;
}