FREE Subscription to Dr. Dobb’s Digest: Same Great Content, New Digital Edition
Site Archive (Complete)
Dobbs M-Dev
Email
Print
Reprint

add to:
Del.icio.us
Digg
Google
Furl
Slashdot
Y! MyWeb
Blink
October 01, 2003

URL Canonicalization Testing

(Page 6 of 16)
URL Canonicalization Testing

Listing 4 Collapsing IP quads


std::wstring CIPEncoder::CollapseQuads(std::wstring quadOne
    , std::wstring quadTwo) const
    {
    return CollapseQuads(quadOne, quadTwo, L"", L"");
    }
std::wstring CIPEncoder::CollapseQuads(std::wstring quadOne
    , std::wstring quadTwo, std::wstring quadThree) const
    {
    return CollapseQuads(quadOne, quadTwo, quadThree, L"");
    }
std::wstring CIPEncoder::CollapseQuads(std::wstring quadOne
    , std::wstring quadTwo, std::wstring quadThree, std::wstring quadFour) const
    {
    // An empty string converts to a single 0, but to make the math work 
    // correctly we need two-digit hex values.  Thus we prepend the missing
    // 0 if the conversion gives an odd number of digits.
    quadOne = CConverters::DecimalToHex(quadOne);
    if (1 == (quadOne.length() % 2))
        {
        quadOne = L"0" + quadOne;
        }
    quadTwo = CConverters::DecimalToHex(quadTwo);
    if (1 == (quadTwo.length() % 2))
        {
        quadTwo = L"0" + quadTwo;
        }
    quadThree = CConverters::DecimalToHex(quadThree);
    if (1 == (quadThree.length() % 2))
        {
        quadThree = L"0" + quadThree;
        }
    quadFour = CConverters::DecimalToHex(quadFour);
    if (1 == (quadFour.length() % 2))
        {
        quadFour = L"0" + quadFour;
        }
    return CConverters::HexToDecimal(quadOne + quadTwo + quadThree + quadFour);
    }

Previous Page | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 Next Page
TOP 5 ARTICLES
No Top Articles.



MICROSITES
FEATURED TOPIC

ADDITIONAL TOPICS

INFO-LINK