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-2018 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 <algorithm>
35 #include <chrono>
36 #include <string>
37 #include <vector>
38 
39 namespace psi {
40 
41 typedef std::vector<std::string> strvec;
42 
43 std::string file_to_string(std::string const &name);
44 
45 bool space(char c);
46 
47 bool not_space(char c);
48 
49 std::vector<std::string> split(const std::string &str);
50 
51 std::vector<std::string> split_indices(const std::string &str);
52 
53 void to_lower(std::string &str);
54 std::string to_lower_copy(const std::string &str);
55 
56 void to_upper(std::string &str);
57 std::string to_upper_copy(const std::string &str);
58 
59 std::string to_string(const int val);
60 
61 std::string to_string(const double val);
62 
63 double to_double(const std::string str);
64 
65 int to_integer(const std::string inString);
66 
67 void append_reference(std::string &str, int reference);
68 
69 std::string add_reference(std::string &str, int reference);
70 
71 void append_reference(std::string &str, int reference);
72 
73 std::string find_and_replace(std::string &source, const std::string &target, const std::string &replace);
74 
75 void trim_spaces(std::string &str);
76 
77 template <typename Range1T, typename Range2T>
78 bool iequals(const Range1T &Input, const Range2T &Test) {
79  if (std::distance(std::begin(Input), std::end(Input)) != std::distance(std::begin(Test), std::end(Test)))
80  return false;
81 
82  return std::equal(std::begin(Input), std::end(Input), std::begin(Test),
83  [](unsigned char a, unsigned char b) { return std::tolower(a) == std::tolower(b); });
84 }
85 
86 std::vector<std::string> split(const std::string &input, const std::string &regex);
87 
94 size_t edit_distance(const std::string &s1, const std::string &s2);
95 
96 class PSI_API Timer {
97  public:
98  Timer();
99  double get();
100 
101  private:
102  std::chrono::high_resolution_clock::time_point start;
103 };
104 
105 void generate_combinations(int n, int k, std::vector<std::vector<int>> &combinations);
106 }
107 
108 #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
void generate_combinations(int n, int k, std::vector< std::vector< int > > &combinations)
Definition: combinations.cc:42
std::chrono::high_resolution_clock::time_point start
Definition: libpsi4util.h:102
std::vector< std::string > split(const std::string &str)
Definition: stl_string.cc:49
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:41
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:78
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:96
void append_reference(std::string &str, int reference)
Definition: stl_string.cc:201