LifeV
StringUtility.cpp
Go to the documentation of this file.
1 //@HEADER
2 /*
3 *******************************************************************************
4 
5 Copyright (C) 2004, 2005, 2007 EPFL, Politecnico di Milano, INRIA
6 Copyright (C) 2010 EPFL, Politecnico di Milano, Emory University
7 
8 This file is part of LifeV.
9 
10 LifeV is free software; you can redistribute it and/or modify
11 it under the terms of the GNU Lesser General Public License as published by
12 the Free Software Foundation, either version 3 of the License, or
13 (at your option) any later version.
14 
15 LifeV is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 Lesser General Public License for more details.
19 
20 You should have received a copy of the GNU Lesser General Public License
21 along with LifeV. If not, see <http://www.gnu.org/licenses/>.
22 
23 *******************************************************************************
24 */
25 //@HEADER
26 /*!
27  @file
28  @brief String utilities
29 
30  @date 13-12-2010
31  @author
32 
33  @maintainer Radu Popescu <radu.popescu@epfl.ch>
34 */
35 
36 #include <lifev/core/util/StringUtility.hpp>
37 
38 namespace LifeV
39 {
40 std::istream& eatLine ( std::istream& s ) // eat a whole line from std::istream
41 {
42  while ( s.get() != '\n' && s . good() )
43  {}
44  return s ;
45 }
46 
47 std::istream& eatComments ( std::istream& s ) //eat lines starting with '!%#;$'
48 {
49  char c = 'a';
50  s.get ( c ) ;
51  while ( c == '!' ||
52  c == '%' ||
53  c == '#' ||
54  c == ';' ||
55  c == '$' )
56  {
57  s >> eatLine ;
58  s.get ( c ) ;
59  }
60  return s.putback ( c ) ;
61 }
62 
63 std::istream& nextGoodLine ( std::istream& s, std::string& line )
64 {
65  s >> eatComments;
66  getline ( s, line );
67  return s;
68 }
69 
70 std::string& setStringLength ( std::string& s, unsigned int len, char c )
71 {
72  /*
73  always return a std::string with len characters
74  - if the s has more than len characters : keep only the first len
75  - if the s has less than len characters : complete with c until len
76  */
77  std::string stmp ( len, c );
78  if ( s.length() > len )
79  {
80  s.erase ( len, s.length() );
81  }
82  stmp.replace ( 0, s.length(), s );
83  s = stmp;
84  return s;
85 }
86 
87 int atoi ( const std::string& s )
88 {
89  return ::atoi ( s.c_str() );
90 }
91 
92 std::string operator+ ( const std::string& str, const int i )
93 {
94  int digits = i == 0 ? 2 : std::log10 ( std::abs (i) ) + 2;
95  char* str_i = new char[ digits ];
96  sprintf ( str_i, "%i", i );
97  std::string str2 = str + str_i;
98  delete[] str_i;
99  return str2;
100 }
101 
102 std::string operator+ ( const std::string& str, const long i )
103 {
104  int digits = i == 0 ? 2 : std::log10 ( std::abs (i) ) + 2;
105  char* str_i = new char[ digits ];
106  sprintf ( str_i, "%ld", i );
107  std::string str2 = str + str_i;
108  delete[] str_i;
109  return str2;
110 }
111 
112 std::string operator+ ( const std::string& str, const unsigned int i )
113 {
114  int digits = i == 0 ? 2 : std::log10 (i) + 2;
115  char* str_i = new char[ digits ];
116  sprintf ( str_i, "%u", i );
117  std::string str2 = str + str_i;
118  delete[] str_i;
119  return str2;
120 }
121 }
std::istream & eatLine(std::istream &s)
std::string operator+(const std::string &str, const long i)
void updateInverseJacobian(const UInt &iQuadPt)
std::istream & eatComments(std::istream &s)
skip lines starting with &#39;!%#;$&#39;