Attribute Parser

  • + 1 comment

    if '~' is replaced with '.' in query string, we can modify processing of query like this:

    void process_queries(int q, std::map <std::string, std::string> &attributes)
    {
        std::string str;
        for (int i = 0; i < q; i++)
        {
            getline(std::cin, str);
            if (attributes.find(str) == attributes.end())
            {
                size_t pos = str.find("~");
                if (pos != std::string::npos)
                {
                    str[pos] = '.';
                    if (attributes.find(str) != attributes.end())
                    {
                        std::cout << attributes[str] << "\n";
                    }
                }
                std::cout << "Not Found!\n";
            }
            else
            {
                std::cout << attributes[str] << "\n";
            }
        }
    }