Make things work #1

Merged
etenie merged 10 commits from fix-regex into master 2024-11-10 18:35:45 +00:00
3 changed files with 39 additions and 11 deletions
Showing only changes of commit 8295c5ddf9 - Show all commits

5
.gitignore vendored
View File

@ -1,3 +1,4 @@
cmake-build*
.idea
build
.cache
.idea

View File

@ -2,13 +2,28 @@ cmake_minimum_required(VERSION 3.30)
project(nutri)
set(CMAKE_CXX_STANDARD 26)
set(CMAKE_EXPORT_COMPILE_COMMANDS 1)
find_package(fmt REQUIRED)
find_package(cpr REQUIRED)
find_package(nlohmann_json REQUIRED)
include_directories(${CMAKE_SOURCE_DIR}/external/ctre/include)
add_subdirectory(external/ctre/)
include(FetchContent)
FetchContent_Declare(
ctre
GIT_REPOSITORY https://github.com/hanickadot/compile-time-regular-expressions.git
GIT_TAG v3.9.0
GIT_SHALLOW TRUE
)
FetchContent_Declare(
cpr
GIT_REPOSITORY https://github.com/libcpr/cpr.git
GIT_TAG 1.11.0
GIT_SHALLOW TRUE
)
FetchContent_MakeAvailable(ctre cpr)
add_executable(
nutri

View File

@ -1,8 +1,18 @@
#include "ArgParser.hpp"
#include "Helpers/WolframAlpha.hpp"
#include <ctre.hpp>
#include <iostream>
#include <nlohmann/json.hpp>
#include <print>
#include <string_view>
void getVal(std::string_view sv) {
auto m = ctre::search<"(?<=protein\\s)(\\d+)\\s*(\\w+)">(sv);
double d = m.get<1>().to_number();
std::string u = m.get<2>().to_string();
std::println("1: {}\n2: {}", d, u);
}
int main(const int argc, char* argv[]) {
try {
@ -13,13 +23,15 @@ int main(const int argc, char* argv[]) {
args.addArg("-h", "--help", "Print help", false);
args.parse(argc, argv);
const auto food = args.get<std::string>("--food");
const double amount = args.get<double>("--amount") / 100;
// const auto food = args.get<std::string>("--food");
// const double amount = args.get<double>("--amount") / 100;
// if (!args.has("--source") || args.get<std::string>("--source") == "Wolfram") {
// WolframAlpha wa(food, amount);
// std::println("Calories: {:.2f} kcal\nProtein: {:.2f} g\nCarbs: {:.2f} g\nFat: {:.2f} g", wa.getCalories(), wa.getProtein(), wa.getCarbs(), wa.getFat());
// }
getVal("carbs 14 g | protein 20 mg | fat 11 g");
if (!args.has("--source") || args.get<std::string>("--source") == "Wolfram") {
WolframAlpha wa(food, amount);
std::println("Calories: {:.2f} kcal\nProtein: {:.2f} g\nCarbs: {:.2f} g\nFat: {:.2f} g", wa.getCalories(), wa.getProtein(), wa.getCarbs(), wa.getFat());
}
} catch (const std::exception& e) {
std::println(stderr, "Error: {}", e.what());
return 1;