예제 #1
0
bool Uri::Private::parsePctEncoded()
{
    if (expectChar('%')) {
        Char curr = m_uri[m_parserPos];
        size_t currValue = curr.value();
        if (!currValue || currValue > 127 || !isHexdig[currValue]) {
            return false;
        }
        m_parserAux += curr;
        ++m_parserPos;
        curr = m_uri[m_parserPos];
        currValue = curr.value();
        if (!currValue || currValue > 127 || !isHexdig[currValue]) {
            return false;
        }
        m_parserAux += curr;
        ++m_parserPos;
    } else {
        const Char curr = m_uri[m_parserPos];
        const iuint32 currValue = curr.value();
        if (curr.octetsRequired() > 1) {
            m_parserAux += curr;
            ++m_parserPos;
        } else if (currValue && currValue < 128 && (!isUnreserved[currValue] && !isGendelim[currValue] &&
                                                    !isSubdelim[currValue] && curr != ':' && curr != '@')) {
            m_parserTrick = true;
            m_parserAux += getHex(curr);
            ++m_parserPos;
        } else {
            return false;
        }
    }
    return true;
}
예제 #2
0
String Uri::Private::getHex(Char ch) const
{
    String res;
    union {
        iuint32 value;
        ichar v[4];
    } fragmentedValue;
    fragmentedValue.value = ch.value();
    const iint32 octetsRequired = ch.octetsRequired();
    for (iint32 i = 0; i < octetsRequired; ++i) {
        res += '%';
        res += uri_hex[(fragmentedValue.v[octetsRequired - i - 1] >> 4) & 0xf];
        res += uri_hex[fragmentedValue.v[octetsRequired - i - 1] & 0xf];
    }
    return res;
}