Commit d1c36492 authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent b6246fd3
...@@ -203,6 +203,10 @@ bool has_prefix(const string &s, const string &prefix) { ...@@ -203,6 +203,10 @@ bool has_prefix(const string &s, const string &prefix) {
return s.compare(0, prefix.size(), prefix); return s.compare(0, prefix.size(), prefix);
} }
bool has_prefix(const string &s, char prefix) {
return (s.size() >= 1 && s[0] == prefix);
}
vector<string> split(const string &s, char sep) { vector<string> split(const string &s, char sep) {
vector<string> r; vector<string> r;
int psep_prev=-1; int psep_prev=-1;
......
...@@ -144,6 +144,7 @@ error errorf (const char *format, ...) ...@@ -144,6 +144,7 @@ error errorf (const char *format, ...)
namespace strings { namespace strings {
bool has_prefix(const string &s, const string &prefix); bool has_prefix(const string &s, const string &prefix);
bool has_prefix(const string &s, char prefix);
vector<string> split(const string &s, char sep); vector<string> split(const string &s, char sep);
} // strings:: } // strings::
......
...@@ -700,7 +700,27 @@ static error _parsePinReq(PinReq *pin, const rxPkt *pkt) { ...@@ -700,7 +700,27 @@ static error _parsePinReq(PinReq *pin, const rxPkt *pkt) {
if (argv.size() != 3) if (argv.size() != 3)
return fmt::errorf("expected 3 arguments, got %zd", argv.size()); return fmt::errorf("expected 3 arguments, got %zd", argv.size());
// XXX error err;
tie(pin->foid, err) = _parseHex64(argv[0]);
if (err != nil)
return fmt::errorf("invalid foid");
if (!strings::has_prefix(argv[1], '#'))
return fmt::errorf("invalid blk");
tie(pin->blk, err) = _parseInt(argv[1].substr(1));
if (err != nil)
return fmt::errorf("invalid blk");
if (!strings::has_prefix(argv[2], '@'))
return fmt::errorf("invalid at");
auto at = argv[2].substr(1);
if (at == "head") {
pin->at = TidHead;
} else {
tie(pin->at, err) = _parseHex64(at);
if (err != nil)
return fmt::errorf("invalid at");
}
return nil; return nil;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment