StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
PythiaStdlib.cc
1 // PythiaStdlib.cc is a part of the PYTHIA event generator.
2 // Copyright (C) 2020 Torbjorn Sjostrand.
3 // PYTHIA is licenced under the GNU GPL v2 or later, see COPYING for details.
4 // Please respect the MCnet Guidelines, see GUIDELINES for details.
5 
6 // Function definitions (not found in the header) for
7 
8 #include "Pythia8/PythiaStdlib.h"
9 
10 namespace Pythia8 {
11 
12 //==========================================================================
13 
14 // Convert string to lowercase for case-insensitive comparisons.
15 // By default remove any initial and trailing blanks or escape characters.
16 
17 string toLower(const string& name, bool trim) {
18 
19  // Copy string without initial and trailing blanks or escape characters.
20  string temp = name;
21  if (trim) {
22  if (name.find_first_not_of(" \n\t\v\b\r\f\a") == string::npos) return "";
23  int firstChar = name.find_first_not_of(" \n\t\v\b\r\f\a");
24  int lastChar = name.find_last_not_of(" \n\t\v\b\r\f\a");
25  temp = name.substr( firstChar, lastChar + 1 - firstChar);
26  }
27 
28  // Convert to lowercase letter by letter.
29  for (int i = 0; i < int(temp.length()); ++i) temp[i] = tolower(temp[i]);
30  return temp;
31 
32 }
33 
34 //==========================================================================
35 
36 } // end namespace Pythia8