Psi4
libpsi4util.h
Go to the documentation of this file.
1 /*
2  * @BEGIN LICENSE
3  *
4  * Psi4: an open-source quantum chemistry software package
5  *
6  * Copyright (c) 2007-2019 The Psi4 Developers.
7  *
8  * The copyrights for code used from other parties are included in
9  * the corresponding files.
10  *
11  * This file is part of Psi4.
12  *
13  * Psi4 is free software; you can redistribute it and/or modify
14  * it under the terms of the GNU Lesser General Public License as published by
15  * the Free Software Foundation, version 3.
16  *
17  * Psi4 is distributed in the hope that it will be useful,
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20  * GNU Lesser General Public License for more details.
21  *
22  * You should have received a copy of the GNU Lesser General Public License along
23  * with Psi4; if not, write to the Free Software Foundation, Inc.,
24  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
25  *
26  * @END LICENSE
27  */
28 
29 #ifndef _psi_src_lib_libpsi4util_libpsi4util_h_
30 #define _psi_src_lib_libpsi4util_libpsi4util_h_
31 
32 #include "psi4/pragma.h"
33 
34 #include <cctype>
35 #include <algorithm>
36 #include <chrono>
37 #include <string>
38 #include <vector>
39 
40 namespace psi {
41 
42 typedef std::vector<std::string> strvec;
43 
44 std::string file_to_string(std::string const &name);
45 
46 bool space(char c);
47 
48 bool not_space(char c);
49 
50 std::vector<std::string> split(const std::string &str);
51 
52 std::vector<std::string> split_indices(const std::string &str);
53 
54 void to_lower(std::string &str);
55 std::string to_lower_copy(const std::string &str);
56 
57 void to_upper(std::string &str);
58 std::string to_upper_copy(const std::string &str);
59 
60 std::string to_string(const int val);
61 
62 std::string to_string(const double val);
63 
64 double to_double(const std::string str);
65 
66 int to_integer(const std::string inString);
67 
68 void append_reference(std::string &str, int reference);
69 
70 std::string add_reference(std::string &str, int reference);
71 
72 void append_reference(std::string &str, int reference);
73 
74 std::string find_and_replace(std::string &source, const std::string &target, const std::string &replace);
75 
76 void trim_spaces(std::string &str);
77 
78 template <typename Range1T, typename Range2T>
79 bool iequals(const Range1T &Input, const Range2T &Test) {
80  if (std::distance(std::begin(Input), std::end(Input)) != std::distance(std::begin(Test), std::end(Test)))
81  return false;
82 
83  return std::equal(std::begin(Input), std::end(Input), std::begin(Test),
84  [](unsigned char a, unsigned char b) { return std::tolower(a) == std::tolower(b); });
85 }
86 
87 std::vector<std::string> split(const std::string &input, const std::string &regex);
88 
95 size_t edit_distance(const std::string &s1, const std::string &s2);
96 
97 class PSI_API Timer {
98  public:
99  Timer();
100  double get();
101 
102  private:
103  std::chrono::high_resolution_clock::time_point start;
104 };
105 
106 void generate_combinations(int n, int k, std::vector<std::vector<int>> &combinations);
107 }
108 
109 #endif // _psi_src_lib_libpsi4util_libpsi4util_h_
std::string to_string(const int val)
Definition: stl_string.cc:180
std::string find_and_replace(std::string &source, const std::string &target, const std::string &replace)
Definition: stl_string.cc:113
void reference()
Definition: reference.cc:51
std::string add_reference(std::string &str, int reference)
Definition: stl_string.cc:199
void to_lower(std::string &str)
Definition: stl_string.cc:162
std::chrono::high_resolution_clock::time_point start
Definition: libpsi4util.h:103
std::vector< std::string > split(const std::string &str)
Definition: stl_string.cc:49
void generate_combinations(int n, int k, std::vector< std::vector< int >> &combinations)
Definition: combinations.cc:41
size_t edit_distance(const std::string &s1, const std::string &s2)
Compute the Levenshtein distance between two strings.
Definition: stl_string.cc:141
std::vector< std::string > strvec
Definition: libpsi4util.h:42
int to_integer(const std::string inString)
Definition: stl_string.cc:192
void trim_spaces(std::string &str)
Definition: stl_string.cc:128
double combinations(int n, int k)
Definition: probabil.cc:70
bool iequals(const Range1T &Input, const Range2T &Test)
Definition: libpsi4util.h:79
void to_upper(std::string &str)
Definition: stl_string.cc:170
std::string file_to_string(std::string const &name)
std::string to_lower_copy(const std::string &str)
Definition: stl_string.cc:164
#define PSI_API
Definition: pragma.h:155
bool not_space(char c)
Definition: stl_string.cc:111
double to_double(const std::string str)
Definition: stl_string.cc:178
std::string to_upper_copy(const std::string &str)
Definition: stl_string.cc:172
bool space(char c)
Definition: stl_string.cc:109
std::vector< std::string > split_indices(const std::string &str)
Definition: stl_string.cc:88
Definition: libpsi4util.h:97
void append_reference(std::string &str, int reference)
Definition: stl_string.cc:201