Parsing Input

So basically I'm creating a database I guess you could call it. I have a function that scans the input and then compares it to the key of a map and if it matches a value then it calls a function based on the value associated with that key. Now here's what I have no clue how to do. I have commands that take parameters and I'm not sure how I would compare the input to the key value of the map since the parameters will be based on what the user types in. For example, I have a function DBAddAccount(std::string name). That function would normally get called by typing in "DB.Add.User" However it takes a parameter so it'd really be "DB.Add.User(abc)". I'm not really sure if i explained it well enough but hopefully someone understands what I'm trying to do.

Thankyou in advance.
Last edited on
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#include <utility>
#include <sstream>
#include <string>

std::pair <std::string, std::string> parse_command(const std::string  &command) {
    std::istringstream iss(command);
    
    
    std::string func;
    std::getline(iss, func, '('); // get the function name

    std::string params;
    std::getline(iss, params, ')'); // get the parameters for the function
    
    return std::pair<std::string, std::string> (std::move(func), std::move(params));
}


Usage:
http://coliru.stacked-crooked.com/a/137ce7c5ad0a6513
I love you<3 Works perfectly. Thankyou so much.
Topic archived. No new replies allowed.