Example #1
0
void DOMTokenListImp::add(Variadic<std::u16string> tokens)
{
    for (size_t i = 0; i < tokens.size(); ++i) {
        std::u16string token = tokens[i];
        stripLeadingAndTrailingWhitespace(token);
        if (token.empty())
            continue;   // TODO: throw
        if (!contains(token))
            this->tokens.push_back(token);
    }
    update();
}
bool HTMLElementImp::toUnsigned(std::u16string& value)
{
    stripLeadingAndTrailingWhitespace(value);
    if (value.empty())
        return false;
    const char16_t* s = value.c_str();
    while (*s) {
        if (!isDigit(*s))
            return false;
        ++s;
    }
    return true;
}
Example #3
0
void DOMTokenListImp::remove(Variadic<std::u16string> tokens)
{
    for (size_t i = 0; i < tokens.size(); ++i) {
        std::u16string token = tokens[i];
        stripLeadingAndTrailingWhitespace(token);
        if (token.empty())
            continue;   // TODO: throw
        auto found = std::find(this->tokens.begin(), this->tokens.end(), token);
        if (found != this->tokens.end())
            this->tokens.erase(found);
    }
    update();
}
Example #4
0
bool DOMTokenListImp::toggle(const std::u16string& token)
{
    std::u16string t(token);
    stripLeadingAndTrailingWhitespace(t);
    if (t.empty())
        return false; // TODO: throw
    auto found = std::find(tokens.begin(), tokens.end(), t);
    if (found != tokens.end()) {
        tokens.erase(found);
        update();
        return false;
    } else {
        tokens.push_back(t);
        update();
        return true;
    }
}
bool HTMLElementImp::toPxOrPercentage(std::u16string& value)
{
    stripLeadingAndTrailingWhitespace(value);
    if (value.empty())
        return false;
    const char16_t* s = value.c_str();
    while (*s) {
        if (*s == '%')
            break;
        if (!isDigit(*s))
            return false;
        ++s;
    }
    if (!*s) {
        value += u"px";
        return true;
    }
    assert(*s == '%');
    if (!s[1] && 1 < value.length())
        return true;
    return false;
}