source: XIOS/dev/branch_yushan_merged/src/indent_xml.cpp @ 1205

Last change on this file since 1205 was 1134, checked in by yushan, 7 years ago

branch merged with trunk r1130

  • 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      #pragma omp threadprivate(LineNB)
18     
19      if (CIndent::WithLine) out << LineNB++ << ". ";
20      for(unsigned int i = 0; i < CIndent::Indent; out << CIndent::Increm , i++){}
21      return (out);
22   }
23
24   StdOStream & CIndent::IncIndent(StdOStream& out)
25   { CIndent::Indent++; return (CIndent::NIndent(out)); }
26
27   StdOStream & CIndent::DecEndl  (StdOStream& out)
28   { CIndent::Indent--; return (out); }
29
30   ///----------------------------------------
31
32   StdString CIndentedXml::Indented(const StdString & content)
33   {
34      StdOStringStream retvalue;
35      std::vector<StdString> str;
36      boost::split(str, content, boost::is_any_of("\n"));
37     
38      std::vector<StdString>::iterator it = str.begin(), end = str.end();
39     
40      for (; it != end; it++)
41      {
42         StdString & line = *it;
43         if (line.find("<? ") != StdString::npos ||
44             line.find(xml::CXMLNode::GetRootName()) != StdString::npos)
45            retvalue << CIndent::NIndent << line <<  std::endl;
46         else if (line.find("</") != StdString::npos)
47            retvalue << CIndent::NIndent   << line << CIndent::DecEndl << std::endl;
48         else if (line.find(" />") != StdString::npos)
49            retvalue << CIndent::IncIndent << line << CIndent::DecEndl << std::endl;
50         else
51            retvalue << CIndent::IncIndent << line <<  std::endl;
52      }
53      return (retvalue.str());
54   }
55} // namespace xios
Note: See TracBrowser for help on using the repository browser.