Exemple #1
0
static DialogFeaturesMap parseDialogFeaturesMap(const String& string)
{
    // FIXME: Not clear why we take such a different approach to parsing dialog features
    // as opposed to window features (using a map, different parsing quirks).

    DialogFeaturesMap features;

    Vector<String> vector;
    string.split(';', vector);

    for (auto& featureString : vector) {
        size_t separatorPosition = featureString.find('=');
        size_t colonPosition = featureString.find(':');
        if (separatorPosition != notFound && colonPosition != notFound)
            continue; // ignore strings that have both = and :
        if (separatorPosition == notFound)
            separatorPosition = colonPosition;

        String key = featureString.left(separatorPosition).stripWhiteSpace();

        // Null string for value indicates key without value.
        String value;
        if (separatorPosition != notFound) {
            value = featureString.substring(separatorPosition + 1).stripWhiteSpace();
            value = value.left(value.find(' '));
        }

        features.set(key, value);
    }

    return features;
}
Exemple #2
0
bool WindowFeatures::boolFeature(const DialogFeaturesMap& features, const char* key, bool defaultValue)
{
    DialogFeaturesMap::const_iterator it = features.find(key);
    if (it == features.end())
        return defaultValue;
    const String& value = it->value;
    return value.isNull() || value == "1" || value == "yes" || value == "on";
}
Exemple #3
0
static Optional<bool> boolFeature(const DialogFeaturesMap& features, const char* key)
{
    auto it = features.find(key);
    if (it == features.end())
        return Nullopt;

    auto& value = it->value;
    return value.isNull()
        || value == "1"
        || equalLettersIgnoringASCIICase(value, "yes")
        || equalLettersIgnoringASCIICase(value, "on");
}
int WindowFeatures::intFeature(const DialogFeaturesMap& features, const char* key, int min, int max, int defaultValue)
{
    DialogFeaturesMap::const_iterator it = features.find(key);
    if (it == features.end())
        return defaultValue;
    bool ok;
    int parsedNumber = it->value.toInt(&ok);
    if (!ok)
        return defaultValue;
    if (parsedNumber < min || max <= min)
        return min;
    if (parsedNumber > max)
        return max;
    return parsedNumber;
}
Exemple #5
0
void WindowFeatures::parseDialogFeatures(const String& string, DialogFeaturesMap& map)
{
    Vector<String> vector;
    string.split(';', vector);
    size_t size = vector.size();
    for (size_t i = 0; i < size; ++i) {
        const String& featureString = vector[i];

        size_t separatorPosition = featureString.find('=');
        size_t colonPosition = featureString.find(':');
        if (separatorPosition != kNotFound && colonPosition != kNotFound)
            continue; // ignore strings that have both = and :
        if (separatorPosition == kNotFound)
            separatorPosition = colonPosition;

        String key = featureString.left(separatorPosition).stripWhiteSpace().lower();

        // Null string for value indicates key without value.
        String value;
        if (separatorPosition != kNotFound) {
            value = featureString.substring(separatorPosition + 1).stripWhiteSpace().lower();
            value = value.left(value.find(' '));
        }

        map.set(key, value);
    }
}
Exemple #6
0
float WindowFeatures::floatFeature(const DialogFeaturesMap& features, const char* key, float min, float max, float defaultValue)
{
    DialogFeaturesMap::const_iterator it = features.find(key);
    if (it == features.end())
        return defaultValue;
    // FIXME: The toDouble function does not offer a way to tell "0q" from string with no digits in it: Both
    // return the number 0 and false for ok. But "0q" should yield the minimum rather than the default.
    bool ok;
    double parsedNumber = it->value.toDouble(&ok);
    if ((!parsedNumber && !ok) || std::isnan(parsedNumber))
        return defaultValue;
    if (parsedNumber < min || max <= min)
        return min;
    if (parsedNumber > max)
        return max;
    // FIXME: Seems strange to cast a double to int and then convert back to a float. Why is this a good idea?
    return static_cast<int>(parsedNumber);
}