Multiscale Universal Interface  2.0
A Concurrent Framework for Coupling Heterogeneous Solvers
linalg_util.h
Go to the documentation of this file.
1 /*****************************************************************************
2 * Multiscale Universal Interface Code Coupling Library *
3 * *
4 * Copyright (C) 2023 W. Liu *
5 * *
6 * This software is jointly licensed under the Apache License, Version 2.0 *
7 * and the GNU General Public License version 3, you may use it according *
8 * to either. *
9 * *
10 * ** Apache License, version 2.0 ** *
11 * *
12 * Licensed under the Apache License, Version 2.0 (the "License"); *
13 * you may not use this file except in compliance with the License. *
14 * You may obtain a copy of the License at *
15 * *
16 * http://www.apache.org/licenses/LICENSE-2.0 *
17 * *
18 * Unless required by applicable law or agreed to in writing, software *
19 * distributed under the License is distributed on an "AS IS" BASIS, *
20 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. *
21 * See the License for the specific language governing permissions and *
22 * limitations under the License. *
23 * *
24 * ** GNU General Public License, version 3 ** *
25 * *
26 * This program is free software: you can redistribute it and/or modify *
27 * it under the terms of the GNU General Public License as published by *
28 * the Free Software Foundation, either version 3 of the License, or *
29 * (at your option) any later version. *
30 * *
31 * This program is distributed in the hope that it will be useful, *
32 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
33 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
34 * GNU General Public License for more details. *
35 * *
36 * You should have received a copy of the GNU General Public License *
37 * along with this program. If not, see <http://www.gnu.org/licenses/>. *
38 *****************************************************************************/
39 
47 #ifndef MUI_LINALG_UTIL_H_
48 #define MUI_LINALG_UTIL_H_
49 
50 #include <sstream>
51 #include <cassert>
52 #include <algorithm>
53 #include <cctype>
54 
55 namespace mui {
56 namespace linalg {
57 
58 // Function to left trim a string - helper function on matrix file I/O
59 inline std::string ltrim(const std::string &s) {
60  const std::string WHITESPACE = " \n\r\t\f\v";
61  std::string::size_type start = s.find_first_not_of(WHITESPACE);
62  return (start == std::string::npos) ? "" : s.substr(start);
63 }
64 
65 // Function to right trim a string - helper function on matrix file I/O
66 inline std::string rtrim(const std::string &s) {
67  const std::string WHITESPACE = " \n\r\t\f\v";
68  std::string::size_type end = s.find_last_not_of(WHITESPACE);
69  return (end == std::string::npos) ? "" : s.substr(0, end + 1);
70 }
71 
72 // Function to trim a string on both sides - helper function on matrix file I/O
73 inline std::string trim(const std::string &s) {
74  return rtrim(ltrim(s));
75 }
76 
77 // Function to convert the input string to all lowercase characters - helper function on matrix file I/O
78 inline std::string string_to_lower(const std::string &s) {
79  std::string lower;
80  std::transform(s.begin(), s.end(), std::back_inserter(lower), [](unsigned char c){ return std::tolower(c); });
81  return lower;
82 }
83 
84 // Function to convert the input string to all uppercase characters - helper function on matrix file I/O
85 inline std::string string_to_upper(const std::string &s) {
86  std::string upper;
87  std::transform(s.begin(), s.end(), std::back_inserter(upper), [](unsigned char c){ return std::toupper(c); });
88  return upper;
89 }
90 
91 } // linalg
92 } // mui
93 
94 #endif /* MUI_LINALG_UTIL_H_ */
std::string string_to_lower(const std::string &s)
Definition: linalg_util.h:78
std::string trim(const std::string &s)
Definition: linalg_util.h:73
std::string rtrim(const std::string &s)
Definition: linalg_util.h:66
std::string ltrim(const std::string &s)
Definition: linalg_util.h:59
std::string string_to_upper(const std::string &s)
Definition: linalg_util.h:85
Definition: comm.h:54