Storm 1.14.0.1
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 STORM_LOG_THROW(str != *end, storm::exceptions::WrongFormatException,
24 "Error while parsing integer. Next input token is not a number.\n\tUpcoming input is: \"" << std::string(str, 0, 16) << "\".");
25 return res;
26}
27
36double checked_strtod(char const* str, char const** end) {
37 double res = strtod(str, const_cast<char**>(end));
38 STORM_LOG_THROW(str != *end, storm::exceptions::WrongFormatException,
39 "Error while parsing floating point. Next input token is not a number.\n\tUpcoming input is: \"" << std::string(str, 0, 16) << "\".");
40 return res;
41}
42
49char const* skipWord(char const* buf) {
50 while (!isspace(*buf) && *buf != '\0') {
51 buf++;
52 }
53 return buf;
54}
55
62char const* trimWhitespaces(char const* buf) {
63 while (isspace(*buf)) {
64 buf++;
65 }
66 return buf;
67}
68
72char const* forwardToLineEnd(char const* buffer) {
73 return buffer + strcspn(buffer, "\n\r\0");
74}
75
79char const* forwardToNextLine(char const* buffer) {
80 char const* lineEnd = forwardToLineEnd(buffer);
81 while ((*lineEnd == '\n') || (*lineEnd == '\r')) {
82 lineEnd++;
83 }
84 return lineEnd;
85}
86
87} // namespace cstring
88
89} // namespace utility
90
91} // namespace storm
#define STORM_LOG_THROW(cond, exception, message)
Definition macros.h:28
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:72
char const * skipWord(char const *buf)
Skips all numbers, letters and special characters.
Definition cstring.cpp:49
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:36
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:79
char const * trimWhitespaces(char const *buf)
Skips spaces, tabs, newlines and carriage returns.
Definition cstring.cpp:62