source: XIOS/trunk/src/indent_xml.cpp @ 1542

Last change on this file since 1542 was 501, checked in by ymipsl, 9 years ago

Add licence copyright to all file ond directory src using the command :
svn propset -R copyright -F header_licence src

XIOS is now officialy under CeCILL licence

YM

  • Property copyright set to
    Software name : XIOS (Xml I/O Server)
    http://forge.ipsl.jussieu.fr/ioserver
    Creation date : January 2009
    Licence : CeCCIL version2
    see license file in root directory : Licence_CeCILL_V2-en.txt
    or http://www.cecill.info/licences/Licence_CeCILL_V2-en.html
    Holder : CEA/LSCE (Laboratoire des Sciences du CLimat et de l'Environnement)
    CNRS/IPSL (Institut Pierre Simon Laplace)
    Project Manager : Yann Meurdesoif
    yann.meurdesoif@cea.fr
  • Property svn:eol-style set to native
File size: 1.8 KB
Line 
1#include "indent_xml.hpp"
2
3/// boost headers ///
4#include <boost/algorithm/string.hpp>
5#include <boost/algorithm/string/split.hpp>
6
7namespace xios
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 xios
Note: See TracBrowser for help on using the repository browser.