1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81
|
// Copyright (c) 2014-2017 Josh Blum
// 2021 Nicholas Corgan
// SPDX-License-Identifier: BSL-1.0
#include <SoapySDR/Types.hpp>
#include <cctype>
static std::string trim(const std::string &s)
{
std::string out = s;
while (not out.empty() and std::isspace(out[0])) out = out.substr(1);
while (not out.empty() and std::isspace(out[out.size()-1])) out = out.substr(0, out.size()-1);
return out;
}
SoapySDR::Kwargs SoapySDR::KwargsFromString(const std::string &markup)
{
SoapySDR::Kwargs kwargs;
bool inKey = true;
std::string key, val;
for (size_t i = 0; i < markup.size(); i++)
{
const char ch = markup[i];
if (inKey)
{
if (ch == '=') inKey = false;
else if (ch == ',') inKey = true;
else key += ch;
}
else
{
if (ch == ',') inKey = true;
else val += ch;
}
if ((inKey and (not val.empty() or (ch == ','))) or ((i+1) == markup.size()))
{
key = trim(key);
val = trim(val);
if (not key.empty()) kwargs[key] = val;
key = "";
val = "";
}
}
return kwargs;
}
std::string SoapySDR::KwargsToString(const SoapySDR::Kwargs &args)
{
std::string markup;
for (const auto &pair : args)
{
if (not markup.empty()) markup += ", ";
markup += pair.first + "=" + pair.second;
}
return markup;
}
SoapySDR::Range::Range(void):
_min(0.0),
_max(0.0),
_step(0.0)
{
return;
}
SoapySDR::Range::Range(const double minimum, const double maximum, const double step):
_min(minimum),
_max(maximum),
_step(step)
{
return;
}
SoapySDR::ArgInfo::ArgInfo(void)
{
return;
}
|