在复习Primer的时候看到的。


void RetrieveEmailFromPage(const string& page, const string& url)
{
    int posCur = 0, posStart, posAt, posEnd, posTmp;
    string email;
    string tags = "._-" "abcdefg" "hijklmn" "opqrst" "uvwxyz"
        "ABCDEFG" "HIJKLMN" "OPQRST" "UVWXYZ" "0123456789";

    while (true) {
        if ((posAt = page.find('@', posCur)) != string::npos) {
            posStart = page.find_last_not_of(tags, posAt - 1) + 1;
            posEnd = page.find_first_not_of(tags, posAt + 1);
            posTmp = page.find('.', posAt + 1);
// domain has at least one dot "xxx.yy"

            if (posTmp != string::npos && posTmp < posEnd - 1 && posStart != posAt && posEnd != posAt + 1) {
                email = page.substr(posStart, posEnd - posStart);
                AddEmail(email, url); // add the email to special data struct
            }
            posCur = posEnd;
        } else {
            return;
        }
    }
//while
}