本文整理汇总了C++中xml_document::allocate_string方法的典型用法代码示例。如果您正苦于以下问题:C++ xml_document::allocate_string方法的具体用法?C++ xml_document::allocate_string怎么用?C++ xml_document::allocate_string使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类xml_document
的用法示例。
在下文中一共展示了xml_document::allocate_string方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: add_to_toc
void add_to_toc(int level, xml_node<char> *title, xml_attribute<char> *id, bool not_numbered)
{
char *style_class;
char *fulltitle = doc.allocate_string(0, title->value_size() + 100);
if (level == 0)
{
style_class = "toc1";
if (not_numbered)
{
sprintf(fulltitle, title->value());
}
else
{
sprintf(fulltitle, "%i. %s", ++numbering[0], title->value());
numbering[1] = 0;
numbering[2] = 0;
}
}
else if (level == 1)
{
style_class = "toc2";
if (not_numbered)
{
sprintf(fulltitle, title->value());
}
else
{
sprintf(fulltitle, "%i.%i %s", numbering[0], ++numbering[1], title->value());
numbering[2] = 0;
}
}
else if (level == 2)
{
style_class = "toc3";
if (not_numbered)
{
sprintf(fulltitle, title->value());
}
else
{
sprintf(fulltitle, "%i.%i.%i %s", numbering[0], numbering[1], ++numbering[2], title->value());
}
}
else
throw std::exception("Invalid TOC level");
xml_node<char> *tocentry = doc.allocate_node(node_element, "a", fulltitle);
char *link = doc.allocate_string(0, id->value_size() + 1);
memcpy(link + 1, id->value(), id->value_size());
link[0] = '#';
tocentry->append_attribute(doc.allocate_attribute("href", link, 0, id->value_size() + 1));
tocentry->append_attribute(doc.allocate_attribute("class", style_class));
toc.append_node(tocentry);
toc.append_node(doc.allocate_node(node_element, "br"));
xml_node<char> *title_data = title->first_node();
if (title_data)
title->remove_node(title_data);
title->value(fulltitle);
}
示例2: AppendAttribute
void XmlParse::AppendAttribute(const std::string &NewAttributeName, const std::string &NewAttributeValue,
xml_document<> &doc, xml_node<> *ParentNode)
{
xml_attribute<> *attr = doc.allocate_attribute(doc.allocate_string(NewAttributeName.c_str()),
doc.allocate_string(NewAttributeValue.c_str()));
if (ParentNode)
{
ParentNode->append_attribute(attr);
}
}
示例3: process_contextless
void process_contextless(xml_node<char> *node)
{
// Translate contextless doxygen tags
if (string(node->name()) == "ulink")
{
node->name("a");
xml_attribute<char> *attr = node->first_attribute("url");
if (attr)
attr->name("href");
}
else if (string(node->name()) == "ref")
{
node->name("a");
xml_attribute<char> *attr = node->first_attribute("refid");
if (attr)
{
attr->name("href");
char *value = doc.allocate_string(0, attr->value_size() + 1);
std::memcpy(value + 1, attr->value(), attr->value_size());
value[0] = '#';
attr->value(value, attr->value_size() + 1);
}
}
else if (string(node->name()) == "computeroutput")
{
node->name("code");
}
else if (string(node->name()) == "verbatim")
{
node->name("pre");
}
else if (string(node->name()) == "linebreak")
{
node->name("br");
}
else if (string(node->name()) == "hruler")
{
node->name("hr");
}
else if (string(node->name()) == "heading")
{
xml_attribute<char> *attr = node->first_attribute("level");
if (attr)
{
int level = atoi(attr->value());
if (level == 0) node->name("h0");
else if (level == 1) node->name("h1");
else if (level == 2) node->name("h2");
else if (level == 3) node->name("h3");
else if (level == 4) node->name("h4");
else if (level == 5) node->name("h5");
else if (level == 6) node->name("h6");
else if (level == 7) node->name("h7");
else if (level == 8) node->name("h8");
else node->name("h9");
}
}
else if (string(node->name()) == "toc")
{
if (toc.parent() != 0)
throw std::exception("More than one <toc> tag found.");
toc.name("toc-contents");
node->append_node(&toc);
}
else if (string(node->name()) == "sect1")
{
xml_node<char> *title = node->first_node("title");
if (title)
{
title->name("h2");
xml_attribute<char> *id = node->first_attribute("id");
if (id)
{
xml_attribute<char> *not_numbered = node->first_attribute("not-numbered");
add_to_toc(0, title, id, not_numbered != 0);
id->parent()->remove_attribute(id);
title->append_attribute(id);
}
}
}
else if (string(node->name()) == "sect2")
{
xml_node<char> *title = node->first_node("title");
if (title)
{
title->name("h3");
xml_attribute<char> *id = node->first_attribute("id");
if (id)
{
xml_attribute<char> *not_numbered = node->first_attribute("not-numbered");
add_to_toc(1, title, id, not_numbered != 0);
id->parent()->remove_attribute(id);
title->append_attribute(id);
}
}
}
else if (string(node->name()) == "sect3")
{
xml_node<char> *title = node->first_node("title");
if (title)
//.........这里部分代码省略.........