Files
spark/src/server/sparkd/cmds/spartan/common/cli/RangeArg.cpp
T
John Colvin 82332bf92f refactor: Replace SimBooks cmd with Matcher->BooksCmd
This is in anticipation of adding a similar subcommand to record fills,
and proc times.  Basic functionality expected to be shared by these
three commands is abstracted out of the former SimBooks command into
common classes.
2021-02-01 23:44:20 -06:00

32 lines
898 B
C++

#include "RangeArg.h"
#include <stdio.h>
#include <string.h>
namespace bts::spartan::cli {
RangeArg::RangeArg() : _result() {}
RangeArg::RangeArg(const std::string &arg) {
// absolute range
auto split_pos = arg.find('-');
if (split_pos == 0 || split_pos == arg.length() - 1)
return;
if (split_pos != std::string::npos) {
_result.start() = std::stoi(arg.substr(0, split_pos));
_result.length() = std::stoi(arg.substr(split_pos + 1)) - _result.start();
return;
}
// relative range
split_pos = arg.find(':');
if (split_pos == 0 || split_pos == arg.length() - 1)
return;
if (split_pos != std::string::npos) {
_result.start() = std::stoi(arg.substr(0, split_pos));
_result.length() = std::stoi(arg.substr(split_pos + 1));
}
}
const Range<std::uint64_t> &RangeArg::result() { return _result; }
} // namespace bts::spartan::cli