Пример #1
0
static bool asJson(yarp::os::ConstString &accum,
                   yarp::os::Value &v) {
    if (v.isInt()||v.isDouble()) {
        accum += v.toString();
        return true;
    }
    if (v.isString()||v.isVocab()) {
        yarp::os::ConstString x = v.toString();
        accum += "\"";
        for (int j=0; j<(int)x.length(); j++) {
            char ch = x[j];
            if (ch=='\n') {
                accum += '\\';
                accum += 'n';
            } else if (ch=='\r') {
                accum += '\\';
                accum += 'r';
            } else if (ch=='\0') {
                accum += '\\';
                accum += '0';
            } else {
                if (ch=='\\'||ch=='\"') {
                    accum += '\\';
                }
                accum += ch;
            }
        }
        accum += "\"";
    }
    if (v.isList()) {
        yarp::os::Bottle *bot = v.asList();
        return asJson(accum,bot);
    }
    return false;
}
Пример #2
0
yarp::os::Value yarp::os::Searchable::check(const ConstString& key,
                                            const yarp::os::Value& fallback,
                                            const ConstString& comment) const {
    if (getMonitor()!=NULL && comment!="") {
        yarp::os::SearchReport report;
        report.key = key;
        report.value = comment;
        report.isComment = true;
        reportToMonitor(report);
    }
    if (getMonitor()!=NULL) {
        yarp::os::SearchReport report;
        report.key = key;
        report.value = fallback.toString();
        report.isDefault = true;
        reportToMonitor(report);
    }
    yarp::os::Value& bit = find(key);
    bool ok = !(bit.isNull());
    if (ok) {
        return bit;
    }
    return fallback;
}