1 | #include "indent_xml.hpp" |
---|
2 | |
---|
3 | /// boost headers /// |
---|
4 | #include <boost_extract.hpp> |
---|
5 | |
---|
6 | namespace xios |
---|
7 | { |
---|
8 | /// ////////////////////// Définitions ////////////////////// /// |
---|
9 | unsigned int CIndent::Indent = 0; |
---|
10 | StdString CIndent::Increm = StdString(" "); |
---|
11 | bool CIndent::WithLine = false; |
---|
12 | |
---|
13 | StdOStream & CIndent::NIndent(StdOStream& out) |
---|
14 | { |
---|
15 | static unsigned int LineNB = 1; |
---|
16 | if (CIndent::WithLine) out << LineNB++ << ". "; |
---|
17 | for(unsigned int i = 0; i < CIndent::Indent; out << CIndent::Increm , i++){} |
---|
18 | return (out); |
---|
19 | } |
---|
20 | |
---|
21 | StdOStream & CIndent::IncIndent(StdOStream& out) |
---|
22 | { CIndent::Indent++; return (CIndent::NIndent(out)); } |
---|
23 | |
---|
24 | StdOStream & CIndent::DecEndl (StdOStream& out) |
---|
25 | { CIndent::Indent--; return (out); } |
---|
26 | |
---|
27 | ///---------------------------------------- |
---|
28 | |
---|
29 | StdString CIndentedXml::Indented(const StdString & content) |
---|
30 | { |
---|
31 | StdOStringStream retvalue; |
---|
32 | std::vector<StdString> str; |
---|
33 | xios_split<std::vector<StdString>>(str, content, "\n"); |
---|
34 | |
---|
35 | std::vector<StdString>::iterator it = str.begin(), end = str.end(); |
---|
36 | |
---|
37 | for (; it != end; it++) |
---|
38 | { |
---|
39 | StdString & line = *it; |
---|
40 | if (line.find("<? ") != StdString::npos || |
---|
41 | line.find(xml::CXMLNode::GetRootName()) != StdString::npos) |
---|
42 | retvalue << CIndent::NIndent << line << std::endl; |
---|
43 | else if (line.find("</") != StdString::npos) |
---|
44 | retvalue << CIndent::NIndent << line << CIndent::DecEndl << std::endl; |
---|
45 | else if (line.find(" />") != StdString::npos) |
---|
46 | retvalue << CIndent::IncIndent << line << CIndent::DecEndl << std::endl; |
---|
47 | else |
---|
48 | retvalue << CIndent::IncIndent << line << std::endl; |
---|
49 | } |
---|
50 | return (retvalue.str()); |
---|
51 | } |
---|
52 | } // namespace xios |
---|