source: XMLIO_V2/dev/dev_rv/src/indent.cpp @ 141

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

Mise à jour depuis un autre dépôt

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