Storm
A Modern Probabilistic Model Checker
Loading...
Searching...
No Matches
cstring.cpp
Go to the documentation of this file.
2
3#include <cstring>
4
7namespace storm {
8
9namespace utility {
10
11namespace cstring {
12
21uint_fast64_t checked_strtol(char const* str, char const** end) {
22 uint_fast64_t res = strtol(str, const_cast<char**>(end), 10);
23 if (str == *end) {
24 STORM_LOG_ERROR("Error while parsing integer. Next input token is not a number.");
25 STORM_LOG_ERROR("\tUpcoming input is: \"" << std::string(str, 0, 16) << "\"");
26 throw storm::exceptions::WrongFormatException("Error while parsing integer. Next input token is not a number.");
27 }
28 return res;
29}
30
39double checked_strtod(char const* str, char const** end) {
40 double res = strtod(str, const_cast<char**>(end));
41 if (str == *end) {
42 STORM_LOG_ERROR("Error while parsing floating point. Next input token is not a number.");
43 STORM_LOG_ERROR("\tUpcoming input is: \"" << std::string(str, 0, 16) << "\"");
44 throw storm::exceptions::WrongFormatException("Error while parsing floating point. Next input token is not a number.");
45 }
46 return res;
47}
48
55char const* skipWord(char const* buf) {
56 while (!isspace(*buf) && *buf != '\0') buf++;
57 return buf;
58}
59
66char const* trimWhitespaces(char const* buf) {
67 while (isspace(*buf)) buf++;
68 return buf;
69}
70
74char const* forwardToLineEnd(char const* buffer) {
75 return buffer + strcspn(buffer, "\n\r\0");
76}
77
81char const* forwardToNextLine(char const* buffer) {
82 char const* lineEnd = forwardToLineEnd(buffer);
83 while ((*lineEnd == '\n') || (*lineEnd == '\r')) lineEnd++;
84 return lineEnd;
85}
86
87} // namespace cstring
88
89} // namespace utility
90
91} // namespace storm
#define STORM_LOG_ERROR(message)
Definition logging.h:31
char const * forwardToLineEnd(char const *buffer)
Encapsulates the usage of function @strcspn to forward to the end of the line (next char is the newli...
Definition cstring.cpp:74
char const * skipWord(char const *buf)
Skips all numbers, letters and special characters.
Definition cstring.cpp:55
double checked_strtod(char const *str, char const **end)
Calls strtod() internally and checks if the new pointer is different from the original one,...
Definition cstring.cpp:39
uint_fast64_t checked_strtol(char const *str, char const **end)
Calls strtol() internally and checks if the new pointer is different from the original one,...
Definition cstring.cpp:21
char const * forwardToNextLine(char const *buffer)
Encapsulates the usage of function @strchr to forward to the next line.
Definition cstring.cpp:81
char const * trimWhitespaces(char const *buf)
Skips spaces, tabs, newlines and carriage returns.
Definition cstring.cpp:66
LabParser.cpp.
Definition cli.cpp:18