source: XIOS3/trunk/src/indent_xml.cpp

Last change on this file was 2629, checked in by jderouillat, 2 months ago

Delete boost dependencies, the few features used are replaced by functions stored in extern/boost_extraction

  • 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.7 KB
Line 
1#include "indent_xml.hpp"
2
3/// boost headers ///
4#include <boost_extract.hpp>
5
6namespace 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
Note: See TracBrowser for help on using the repository browser.