#include "handler.ih"

void Handler::saveZip(string &line)
{
    do
    {
        size_t begin = line.find("filename=");

        if (begin == string::npos)
            continue;

        begin = line.find('=', begin) + 1;          // char beyond =

        size_t end =
            line[begin] == '"' ?                    // beyond is ": "name"
                line.find('"', ++begin)             // ...name"
            :
                line.find_first_of(" \t");          // name

        saveTheZip(line.substr(begin, end - begin));
        return;
    }
    while (getline(cin, line));

    throw Exception{REPLY} << 
            "`filename=...' not found while looking for the zip-filename";
}

