preCICE v3.1.2
Loading...
Searching...
No Matches
String.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <algorithm>
4#include <array>
5#include <sstream>
6#include <string>
7#include <vector>
8
9namespace precice {
10namespace utils {
11
13template <int MAX>
15public:
17 {
18 clear();
19 }
20
21 void clear()
22 {
23 _data.fill('\0');
24 }
25
26 char *data()
27 {
28 return _data.data();
29 }
30
36 {
37 return std::string(_data.data());
38 }
39
40private:
42};
43
45 const std::string &text,
46 int linewidth,
47 int indentation);
48
54std::string &checkAppendExtension(std::string &filename, const std::string &extension);
55
57
61bool convertStringToBool(std::string const &value);
62
70
72#define PRECICE_AS_STRING(message) [&] { \
73 std::ostringstream oss; \
74 oss << message; \
75 return oss.str(); \
76}()
77
79
83
84 bool operator<(const StringMatch &other) const
85 {
86 if (distance == other.distance) {
87 return name < other.name;
88 } else {
89 return distance < other.distance;
90 }
91 }
92};
93
94template <class Container>
96{
98 for (const auto &candidate : expected) {
99 entries.push_back(StringMatch{
100 candidate,
101 utils::editDistance(given, candidate)});
102 }
103 std::sort(entries.begin(), entries.end());
104 return entries;
105}
106
107} // namespace utils
108} // namespace precice
T begin(T... args)
Utility class to build a string from C functions with output pointers and static maximum length.
Definition String.hpp:14
std::string str() const
Definition String.hpp:35
std::array< char, MAX+1 > _data
Definition String.hpp:41
T data(T... args)
T end(T... args)
T fill(T... args)
std::size_t editDistance(std::string_view s1, std::string_view s2)
Definition String.cpp:78
bool convertStringToBool(std::string const &value)
Evaluates a string to find out if it represents a bool.
Definition String.cpp:55
std::string truncate_wstring_to_string(std::wstring wstr, char fill)
Definition String.cpp:65
std::string wrapText(const std::string &text, int linewidth, int indentation)
Definition String.cpp:12
std::string & checkAppendExtension(std::string &filename, const std::string &extension)
Checks if filename has the given extension, if not appends it.
Definition String.cpp:44
std::vector< StringMatch > computeMatches(std::string_view given, const Container &expected)
Definition String.hpp:95
Main namespace of the precice library.
T push_back(T... args)
T sort(T... args)
bool operator<(const StringMatch &other) const
Definition String.hpp:84