Loading ttt_interface/ttt.cpp +8 −11 Original line number Diff line number Diff line Loading @@ -10,8 +10,9 @@ #include "HttpConnect.h" #include "ttt.h" // HELPERS - mostly by ChatGPT // trim whitespace // HELPERS // trim whitespace, based on ChatGPT std::string trim(const std::string& str) { size_t start = str.find_first_not_of(" \t\n\r\f\v"); size_t end = str.find_last_not_of(" \t\n\r\f\v"); Loading @@ -26,7 +27,7 @@ std::string removeQuotes(const std::string& str) { return str; } // Basic JSON parser for flat key-value pairs // Basic JSON parser for flat key-value pairs, based on ChatGPT map<string, string> parseJson(const std::string& jsonString) { map<string, string> result; string trimmedJson = trim(jsonString); Loading @@ -44,8 +45,7 @@ map<string, string> parseJson(const std::string& jsonString) { while (getline(ss, item, ',')) { size_t colonPos = item.find(':'); if (colonPos == std::string::npos) { // ignore invalide key-value pair // std::cerr << "Invalid key-value pair." << std::endl; // ignore invalid key-value pair continue; } Loading @@ -61,7 +61,7 @@ map<string, string> parseJson(const std::string& jsonString) { return result; } // parses an HTTP response and returns the body of the response // parses an HTTP response and returns the body of the response, based on ChatGPT string parseHttpResponse(const string &httpResponse) { std::istringstream responseStream(httpResponse); std::string line; Loading Loading @@ -102,8 +102,8 @@ string parseHttpResponse(const string &httpResponse) { return body; } // Courtesy of ChatGPT string url_encode(const std::string &value) { // URL-encode a given string, based on ChatGPT string url_encode(const string &value) { std::ostringstream escaped; escaped.fill('0'); escaped << std::hex; Loading @@ -127,10 +127,8 @@ string url_encode(const std::string &value) { * @return The Http response. */ string requestTTT(string script) { // cout << "Trying " +script << endl; string answer = parseHttpResponse(HttpConnect::makeRequest("agile.bu.edu", "/backend/web/" + script, "8013")); //parseHttpResponse(HttpConnect::makeRequest("localhost", "/" + script, "8080")); return answer; } Loading @@ -144,7 +142,6 @@ int strToInt(string theStr) { // IMPLEMENTATIONS PLAYER_CODE newPlayer(string name) { return requestTTT("newPlayer.pl"); } Loading Loading
ttt_interface/ttt.cpp +8 −11 Original line number Diff line number Diff line Loading @@ -10,8 +10,9 @@ #include "HttpConnect.h" #include "ttt.h" // HELPERS - mostly by ChatGPT // trim whitespace // HELPERS // trim whitespace, based on ChatGPT std::string trim(const std::string& str) { size_t start = str.find_first_not_of(" \t\n\r\f\v"); size_t end = str.find_last_not_of(" \t\n\r\f\v"); Loading @@ -26,7 +27,7 @@ std::string removeQuotes(const std::string& str) { return str; } // Basic JSON parser for flat key-value pairs // Basic JSON parser for flat key-value pairs, based on ChatGPT map<string, string> parseJson(const std::string& jsonString) { map<string, string> result; string trimmedJson = trim(jsonString); Loading @@ -44,8 +45,7 @@ map<string, string> parseJson(const std::string& jsonString) { while (getline(ss, item, ',')) { size_t colonPos = item.find(':'); if (colonPos == std::string::npos) { // ignore invalide key-value pair // std::cerr << "Invalid key-value pair." << std::endl; // ignore invalid key-value pair continue; } Loading @@ -61,7 +61,7 @@ map<string, string> parseJson(const std::string& jsonString) { return result; } // parses an HTTP response and returns the body of the response // parses an HTTP response and returns the body of the response, based on ChatGPT string parseHttpResponse(const string &httpResponse) { std::istringstream responseStream(httpResponse); std::string line; Loading Loading @@ -102,8 +102,8 @@ string parseHttpResponse(const string &httpResponse) { return body; } // Courtesy of ChatGPT string url_encode(const std::string &value) { // URL-encode a given string, based on ChatGPT string url_encode(const string &value) { std::ostringstream escaped; escaped.fill('0'); escaped << std::hex; Loading @@ -127,10 +127,8 @@ string url_encode(const std::string &value) { * @return The Http response. */ string requestTTT(string script) { // cout << "Trying " +script << endl; string answer = parseHttpResponse(HttpConnect::makeRequest("agile.bu.edu", "/backend/web/" + script, "8013")); //parseHttpResponse(HttpConnect::makeRequest("localhost", "/" + script, "8080")); return answer; } Loading @@ -144,7 +142,6 @@ int strToInt(string theStr) { // IMPLEMENTATIONS PLAYER_CODE newPlayer(string name) { return requestTTT("newPlayer.pl"); } Loading