summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAotrix <[email protected]>2025-03-21 03:02:59 +0100
committerAotrix <[email protected]>2025-03-21 03:02:59 +0100
commit04f6a758a0cc32574be220cb9ca2550b8a171310 (patch)
treec94468ff64a78eea83f6e1d0d769b957a9a9bca5
parent332c0ffde6d60b7bac3cb14df31cbae3f27383a7 (diff)
changed std::string_view to std::string for regex
-rw-r--r--CMakeLists.txt8
-rw-r--r--include/postgresHandler.h2
-rw-r--r--resources/token_info.txt2
-rw-r--r--src/hearthstoneAPIHandler.cpp1
-rw-r--r--src/main.cpp2
-rw-r--r--src/postgresHandler.cpp11
6 files changed, 16 insertions, 10 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index e601a7e..f2a7f51 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -13,11 +13,13 @@ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++20")
add_definitions(-DSOURCE_DIR_PATH="${CMAKE_SOURCE_DIR}")
find_package(Catch2 3 REQUIRED)
-add_executable(tests src/tests/tests.cpp)
-target_link_libraries(tests PRIVATE Catch2::Catch2WithMain pqxx pq curl)
-
file(GLOB SRC_FILES ${PROJECT_SOURCE_DIR}/src/*.cpp)
+file(GLOB SRC_TESTS_FILES ${PROJECT_SOURCE_DIR}/src/tests/*.cpp)
file(GLOB INCLUDE_DIR ${PROJECT_SOURCE_DIR}/include)
+add_executable(tests ${SRC_FILES} ${SRC_TESTS_FILES})
+target_include_directories(tests PRIVATE ${INCLUDE_DIR})
+target_link_libraries(tests PRIVATE Catch2::Catch2WithMain pqxx pq curl)
+
add_executable(${FNAME} ${SRC_FILES})
target_include_directories(${FNAME} PRIVATE ${INCLUDE_DIR})
target_link_libraries(${FNAME} pqxx pq curl)
diff --git a/include/postgresHandler.h b/include/postgresHandler.h
index 1b83618..1aaa422 100644
--- a/include/postgresHandler.h
+++ b/include/postgresHandler.h
@@ -6,4 +6,4 @@ const pqxx::result execute_query(pqxx::work &t_transaction,
void display_query_result(const pqxx::result &t_r);
-void add_cards_to_database(std::string_view t_cards, pqxx::work &t_tx);
+void add_cards_to_database(const std::string &t_cards, pqxx::work &t_tx);
diff --git a/resources/token_info.txt b/resources/token_info.txt
index df41a3e..565db7c 100644
--- a/resources/token_info.txt
+++ b/resources/token_info.txt
@@ -1 +1 @@
-EUvjwfDgLlqiTsLV7w4SHV42oZH3SEMWvU 483951 \ No newline at end of file
+EUYEPGK48vlJ2yGdmPRQkh5fYLIH6spP4M 484055 \ No newline at end of file
diff --git a/src/hearthstoneAPIHandler.cpp b/src/hearthstoneAPIHandler.cpp
index 5dd28d4..5961e1f 100644
--- a/src/hearthstoneAPIHandler.cpp
+++ b/src/hearthstoneAPIHandler.cpp
@@ -139,6 +139,5 @@ HearthstoneAPIHandler::make_api_request(const std::string &t_url,
std::string
HearthstoneAPIHandler::get_cards(const std::string &t_card_parameters) {
- // TODO: Use a parser to generate a std::map or something like that
return make_api_request(get_set_of_cards_url(t_card_parameters), m_header);
}
diff --git a/src/main.cpp b/src/main.cpp
index 6786a5b..54079a7 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -15,6 +15,6 @@ int main() {
// TODO: for test purposes
// use get_cards output instead?
- add_cards_to_database("{\"name\":3}", tx);
+ add_cards_to_database(hs_handler.get_cards("678?locale=fr_FR"), tx);
return 0;
}
diff --git a/src/postgresHandler.cpp b/src/postgresHandler.cpp
index 212202e..a92faaf 100644
--- a/src/postgresHandler.cpp
+++ b/src/postgresHandler.cpp
@@ -17,9 +17,14 @@ void display_query_result(const pqxx::result &t_r) {
}
}
-void add_cards_to_database(std::string_view t_cards, pqxx::work &t_tx) {
+void add_cards_to_database(const std::string &t_cards, pqxx::work &t_tx) {
// TODO: to complete
std::cout << "adding cards..." << std::endl;
- std::regex key_regex; // TODO: to define
- std::cout << t_cards.substr(1, 6) << std::endl;
+ std::regex key_regex("(\".*\"),"); // TODO: write correct regex
+ auto words_begin =
+ std::sregex_iterator(t_cards.begin(), t_cards.end(), key_regex);
+ auto words_end = std::sregex_iterator();
+ for (auto it = words_begin; it != words_end; ++it) {
+ std::cout << (*it).str() << std::endl;
+ }
}