source: XMLIO_V2/dev/common/src/xmlio/indent.cpp @ 219

Last change on this file since 219 was 219, checked in by hozdoba, 13 years ago

Préparation nouvelle arborescence

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