Example #1
0
bool mapToDimension(std::u16string& value)
{
    if (stripLeadingWhitespace(value).empty())
        return false;
    if (value[0] == '+') {
        if (value.erase(0, 1).empty())
            return false;
    }
    size_t pos = 0;
    while (value[pos] == '0')
        ++pos;
    if (0 < pos) {
        if (value.erase(0, pos).empty())
            return false;
    }
    pos = 0;
    while (isDigit(value[pos]))
        ++pos;
    if (value.length() <= pos) {
        value += u"px";
        return true;
    }
    size_t end = pos;
    if (value[pos] == '.') {
        ++pos;
        if (value.length() <= pos || !isDigit(value[pos])) {
            value.replace(end, std::u16string::npos, u"px");
            return true;
        }
        ++pos;
        while (isDigit(value[pos]))
            ++pos;
    }
    if (pos < value.length() && value[pos] == '%') {
        value.erase(++pos);
        return true;
    }
    value.replace(pos, std::u16string::npos, u"px");    // TODO: Check whether floating point length should be allowed
    return true;
}
Example #2
0
bool mapToPixelLength(std::u16string& value)
{
    if (stripLeadingWhitespace(value).empty())
        return false;
    const char16_t* input = value.c_str();
    const char16_t* end = input + value.length();
    int u;
    end = parseInt(input, end, u);
    if (!end || u < 0)
        return false;
    if (0 < u)
        value.replace(end - input, std::u16string::npos, u"px");
    else
        value.erase(end - input);
    return true;
}