BlinkenArea - GitList
Repositories
Blog
Wiki
permissioner
Code
Commits
Branches
Tags
Search
Tree:
1cbbe96
Branches
Tags
master
permissioner
libpermissioner
src
StringUtils.cpp
add nice and I/O idle config
Stefan Schuermans
commited
1cbbe96
at 2020-09-19 12:44:39
StringUtils.cpp
Blame
History
Raw
/** * Permissioner: set file ownerships and permissions * Copyright 2020: Stefan Schuermans, Aachen, Germany <stefan@schuermans.info> * Copyleft: GNU GENERAL PUBLIC LICENSE version 3 (see LICENSE) */ #include <permissioner/StringUtils.h> #include <cstdlib> #include <sstream> #include <stdexcept> #include <string> void StringUtils::getNextField(std::string const &str, std::string::size_type &pos, std::string &field, std::string const &name) { static const std::string whitespace(" \t"); std::string::size_type begin = str.find_first_not_of(whitespace, pos); if (begin == std::string::npos) { std::stringstream msg; msg << "<" << name << "> field missing in \"" << str << "\""; throw std::runtime_error(msg.str()); } std::string::size_type end = str.find_first_of(whitespace, begin); if (end == std::string::npos) { end = str.length(); } field = str.substr(begin, end - begin); pos = str.find_first_not_of(whitespace, end); if (pos == std::string::npos) { pos = str.length(); } } long StringUtils::str2long(std::string const &str, std::string const &name) { char const *c_str = str.c_str(); char *end; long val = strtol(c_str, &end, 0); if (end == c_str || *end != 0) { std::stringstream msg; msg << "invalid integer value \"" << str << "\" for <" << name << "> field"; throw std::runtime_error(msg.str()); } return val; } int StringUtils::str2intRange(std::string const &str, int minVal, int maxVal, std::string const &name) { long val = str2long(str, name); if (val < minVal || val > maxVal) { std::stringstream msg; msg << "value " << val << "of <" << name << "> field out of range " << minVal << " - " << maxVal; throw std::runtime_error(msg.str()); } return val; }