Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <cstdio>
- #include <iostream>
- #include <vector>
- using namespace std;
- class ParseURL{
- private:
- int qualify; // 0 means we qualify
- public:
- string node;
- string service;
- bool primary;
- bool health;
- string epoch;
- // methods
- ParseURL(string URL);
- ~ParseURL();
- };
- ParseURL::ParseURL(string URL){
- vector<string> g2 = {"node", "service", "primary", "health", "epoch"};
- for (string tag : g2){
- auto found = URL.find(tag);
- if ( found != string::npos ){
- auto cut_from = found + 1 + tag.size() ;
- auto meh = URL.substr(cut_from, URL.substr(cut_from).find("&") );
- // is there a way we can avoid these lines below?
- if (tag.find("node",0) == 0){
- this->node = meh;
- } else if (tag.find("service",0) == 0 ){
- this->service = meh;
- } else if (tag.find("epoch",0) == 0) {
- this->epoch = meh;
- } else if (tag.find("health",0) == 0){
- this->health = (meh == "OK");
- } else if (tag.find("primary",0) == 0 ){
- this->primary == (this->node == meh);
- }
- }
- }
- }
- ParseURL::~ParseURL(){
- cout << "Tearing Down the classn";
- }
- int main(){
- char req[] = "GET /register?node=hostrpi3&service=potatoservice&primary=node1&health=OK&epoch=1559345106 HTTP";
- string Request = req;
- Request = Request.substr(Request.find_first_of(" ") );
- Request = Request.substr(0, Request.find(" HTTP"));
- ParseURL *a = new ParseURL(Request);
- cout.width(12);
- cout << "a->node: " << a->node << endl;
- cout.width(12);
- cout << "a->service: " << a->service << endl;
- cout.width(12);
- cout << "a->epoch: " << a->epoch << endl;
- cout.width(12);
- cout << "a->health: " << a->health << endl;
- cout.width(12);
- cout << "a->primary: " << a->primary << endl;
- delete(a);
- return 0;
- }
- a->node: hostrpi3
- a->service: potatoservice
- a->epoch: 1559345106
- a->health: 1
- a->primary: 0
- Tearing Down the class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement