From cd57d1780e20d13ff42a749c57731ac71c16bfa6 Mon Sep 17 00:00:00 2001 From: Craig Cornelius Date: Thu, 23 May 2024 08:37:40 -0700 Subject: [PATCH] Add plural rules to CPP executor (#232) * Add plural rules to CPP executor * Fixing lint warnings * Remove magic number in looping --- executors/cpp/main.cpp | 79 +++++++++++++++++++----------------------- 1 file changed, 35 insertions(+), 44 deletions(-) diff --git a/executors/cpp/main.cpp b/executors/cpp/main.cpp index de3ff528..0d03e8b1 100644 --- a/executors/cpp/main.cpp +++ b/executors/cpp/main.cpp @@ -17,21 +17,16 @@ * and returns results via STDOUT. */ -const char gHelpString[] = - "usage: executor" - "-help Display this message.\n" - "-debug n Level of debug - default = -1\n" - ; - -#include -#include +#include #include #include #include #include -#include +#include +#include +#include using std::cin; using std::cout; @@ -45,18 +40,7 @@ extern const string test_langnames(json_object *json_in); extern const string test_likely_subtags(json_object *json_in); extern const string test_list_fmt(json_object *json_in); extern const string test_numfmt(json_object *json_in); - -std::string supported_tests[6] = { - "collation_short", - "datetime_fmt", - "likely_subtags", - "list_fmt", - "lang_names", - "number_fmt" -}; - - -std::string cppVersion = "1.0"; +extern const string TestPluralRules(json_object *json_in); /** * Main -- process command line, call tests or return data @@ -64,8 +48,19 @@ std::string cppVersion = "1.0"; * commands start with "#" * test data is JSON format */ -int main(int argc, const char** argv) -{ +int main(int argc, const char** argv) { + // All the currently supported test types. + std::vector supported_tests; + supported_tests = { + "collation_short", + "datetime_fmt", + "likely_subtags", + "list_fmt", + "lang_names", + "number_fmt", + "plural_rules" + }; + for (std::string line; std::getline(cin, line);) { if (line == "#EXIT") { return 0; @@ -83,15 +78,15 @@ int main(int argc, const char** argv) // TODO: get from the array of supported tests json_object *tests_supported = json_object_new_object(); json_object *test_array = json_object_new_array(); - for (int index = 0; index < 4; index ++) { - json_object_array_add(test_array, - json_object_new_string(supported_tests[index].c_str())); + for (int index = 0; index < supported_tests.size(); index ++) { + json_object_array_add( + test_array, + json_object_new_string(supported_tests[index].c_str())); } json_object_object_add(tests_supported, "supported_tests", test_array); std::cout << json_object_to_json_string(tests_supported) << endl; } else { - // Parse the JSON data. // Get the test type and call the test function. @@ -99,28 +94,25 @@ int main(int argc, const char** argv) struct json_object *json_input; json_input = json_tokener_parse(line.c_str()); - json_object *test_type_obj = json_object_object_get(json_input, "test_type"); + json_object *test_type_obj = + json_object_object_get(json_input, "test_type"); std::string test_type = json_object_get_string(test_type_obj); - if (test_type == "collation_short" ) { + if (test_type == "collation_short") { outputLine = test_collator(json_input); - } - else if (test_type == "datetime_fmt") { - outputLine = TestDatetimeFmt(json_input); - } - else if (test_type == "number_fmt") { - outputLine = test_numfmt(json_input); - } - else if (test_type == "likely_subtags") { + } else if (test_type == "datetime_fmt") { + outputLine = TestDatetimeFmt(json_input); + } else if (test_type == "number_fmt") { + outputLine = test_numfmt(json_input); + } else if (test_type == "likely_subtags") { outputLine = test_likely_subtags(json_input); - } - else if (test_type == "list_fmt") { + } else if (test_type == "list_fmt") { outputLine = test_list_fmt(json_input); - } - else if (test_type == "lang_names") { + } else if (test_type == "lan1g_names") { outputLine = test_langnames(json_input); - } - else { + } else if (test_type == "plural_rules") { + outputLine = TestPluralRules(json_input); + } else { outputLine = "# BAD TEST " + test_type; // "{\"error\": \"unknown test type\"," + // "\"test_type\":" + test_type + "," + @@ -129,7 +121,6 @@ int main(int argc, const char** argv) cout << outputLine << endl; } - } return 0;