ATLAS Offline Software
Loading...
Searching...
No Matches
utils.h File Reference
#include <string>
#include <vector>
#include <iostream>
Include dependency graph for utils.h:

Go to the source code of this file.

Functions

std::string chop (std::string &, const std::string &)
std::string chomp (std::string &, const std::string &)
std::string choptoken (std::string &, const std::string &)
std::string chomptoken (std::string &, const std::string &)
void removespace (std::string &s, const std::string &s2=" \t")
void replace (std::string &s, const std::string &s2=" \t", const std::string &s3="-")
void replace (std::string &s, char c1, char c2) noexcept
std::string chopfirst (std::string &s1, const std::string &s2="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_.:/")
std::string choplast (std::string &s1, const std::string &s2="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_")
std::string chopends (std::string &s1, const std::string &s2=" \t")
std::string basename (std::string name)
std::string dirname (std::string name)
void depunctuate (std::string &)
double deltaPhi (double, double)
bool canopen (const std::string &)
std::string number (const int &i, const std::string &s="%d")
std::string number (const double &d, const std::string &s="%lf")

Detailed Description

Author
M.Sutton
Date
Thu Jun 23 01:53:36 BST 2005

Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration

Definition in file utils.h.

Function Documentation

◆ basename()

std::string basename ( std::string name)

Definition at line 207 of file utils.cxx.

207 {
208 std::string::size_type pos = name.find( '/' );
209 while ( pos!=std::string::npos ) {
210 name = name.substr( pos+1, name.size()-pos-1 );
211 pos = name.find( '/' );
212 }
213 return name;
214}

◆ canopen()

bool canopen ( const std::string & s)

Definition at line 178 of file utils.cxx.

178 {
179 FILE* f = fopen(s.c_str(), "r");
180 if ( f ) { fclose(f); return true; }
181 return false;
182}

◆ chomp()

std::string chomp ( std::string & s1,
const std::string & s2 )

Definition at line 216 of file hcg.cxx.

217{
218 std::string::size_type pos = s1.find(s2);
219 std::string s3;
220 if ( pos == std::string::npos ) {
221 s3 = s1;
222 s1.clear();
223 }
224 else {
225 s3 = s1.substr(pos+s2.size(),s1.size());
226 s1.erase(pos,s1.size());
227 }
228 return s3;
229}

◆ chomptoken()

std::string chomptoken ( std::string & s1,
const std::string & s2 )

Definition at line 249 of file hcg.cxx.

250{
251 std::string s3 = "";
252 std::string::size_type pos = s1.find(s2);
253 if ( pos != std::string::npos ) {
254 s3 = s1.substr(pos, s1.size());
255 s1.erase(pos, s1.size());
256 }
257 return s3;
258}

◆ chop()

std::string chop ( std::string & s1,
const std::string & s2 )

Definition at line 163 of file hcg.cxx.

164{
165 std::string::size_type pos = s1.find(s2);
166 std::string s3;
167 if ( pos == std::string::npos ) {
168 s3 = s1;
169 s1.erase(0, s1.size());
170 }
171 else {
172 s3 = s1.substr(0, pos);
173 s1.erase(0, pos+s2.size());
174 }
175 return s3;
176}

◆ chopends()

std::string chopends ( std::string & s1,
const std::string & s2 = " \t" )

Definition at line 292 of file hcg.cxx.

293{
294 chopfirst(s1, s2);
295 choplast(s1, s2);
296 return s1;
297}
std::string chopfirst(std::string &s1, const std::string &s2)
Definition hcg.cxx:262
std::string choplast(std::string &s1, const std::string &s2)
Definition hcg.cxx:278

◆ chopfirst()

std::string chopfirst ( std::string & s1,
const std::string & s2 = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_.:/" )

Definition at line 262 of file hcg.cxx.

263{
264 std::string s3;
265 std::string::size_type pos = s1.find_first_not_of(s2);
266 if ( pos != std::string::npos ) {
267 s3 = s1.substr(0, pos);
268 s1.erase(0, pos);
269 }
270 else {
271 s3 = s1;
272 s1.clear();
273 }
274 return s3;
275}

◆ choplast()

std::string choplast ( std::string & s1,
const std::string & s2 = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_" )

Definition at line 278 of file hcg.cxx.

279{
280 std::string s3 = "";
281 std::string::size_type pos = s1.find_last_not_of(s2);
282 if ( pos != std::string::npos ) {
283 s3 = s1.substr(pos+1, s1.size());
284 s1.erase(pos+1, s1.size());
285 }
286 return s3;
287}

◆ choptoken()

std::string choptoken ( std::string & s1,
const std::string & s2 )

Definition at line 235 of file hcg.cxx.

236{
237 std::string s3 = "";
238 std::string::size_type pos = s1.find(s2);
239 if ( pos != std::string::npos ) {
240 s3 = s1.substr(0, pos+s2.size());
241 s1.erase(0, pos+s2.size());
242 }
243 return s3;
244}

◆ deltaPhi()

double deltaPhi ( double phi1,
double phi2 )

Definition at line 169 of file utils.cxx.

169 {
170 double delta = fabs(phi1-phi2);
171 delta = (delta > M_PI) ? (2.0*M_PI - delta) : delta;
172 return delta;
173}
#define M_PI

◆ depunctuate()

void depunctuate ( std::string & s)

Definition at line 157 of file utils.cxx.

158{
159 std::string::size_type pos;
160 while ( (pos = s.find(':'))!=std::string::npos ) {
161 s.erase(pos, 1);
162 }
163}

◆ dirname()

std::string dirname ( std::string name)

Definition at line 200 of file utils.cxx.

200 {
201 std::string::size_type pos = name.find_last_of( '/' );
202 if ( pos!=std::string::npos ) name.resize( pos );
203 return name;
204}

◆ number() [1/2]

std::string number ( const double & d,
const std::string & s = "%lf" )

Definition at line 186 of file utils.cxx.

186 {
187 char tmp[512];
188 sprintf(tmp, s.c_str(), d);
189 return tmp;
190}

◆ number() [2/2]

std::string number ( const int & i,
const std::string & s = "%d" )

Definition at line 192 of file utils.cxx.

192 {
193 char tmp[512];
194 sprintf(tmp, s.c_str(), i);
195 return tmp;
196}

◆ removespace()

void removespace ( std::string & s,
const std::string & s2 = " \t" )

Definition at line 302 of file hcg.cxx.

303{
304 std::string::size_type pos;
305 while ( (pos = s.find(s2))!=std::string::npos ) {
306 s.erase(pos, s2.size());
307 }
308}

◆ replace() [1/2]

void replace ( std::string & s,
char c1,
char c2 )
noexcept

Definition at line 152 of file utils.cxx.

152 {
153 std::replace(s.begin(), s.end(), c1, c2);
154}

◆ replace() [2/2]

void replace ( std::string & s,
const std::string & s2 = " \t",
const std::string & s3 = "-" )

Definition at line 142 of file utils.cxx.

143{
144 std::string::size_type pos;
145 // while ( (pos = s.find(" "))!=std::string::npos ) {
146 // s.replace(pos, 1, "-");
147 while ( (pos = s.find(s2))!=std::string::npos ) {
148 s.replace(pos, 1, s3);
149 }
150}