Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/main'
Browse files Browse the repository at this point in the history
  • Loading branch information
sven-oly committed Jun 6, 2024
2 parents ca2d4a5 + 843673f commit f46ec37
Show file tree
Hide file tree
Showing 7 changed files with 97 additions and 147 deletions.
30 changes: 9 additions & 21 deletions executors/cpp/coll.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include <unicode/ustring.h>
#include <unicode/utypes.h>

#include <cstring>
#include <iostream>
#include <string>

Expand Down Expand Up @@ -132,8 +133,7 @@ const string TestCollator(json_object *json_in) {

if (rules_string != "") {
char uni_rules_out[1000] = "";
int32_t rule_chars_out =
uni_rules.extract(uni_rules_out, 1000, nullptr, status);
uni_rules.extract(uni_rules_out, 1000, nullptr, status); // ignore length

// Make sure normalization is consistent
rb_coll = new RuleBasedCollator(uni_rules, UCOL_ON, status);
Expand Down Expand Up @@ -165,10 +165,9 @@ const string TestCollator(json_object *json_in) {
delete rb_coll;
} else {
// Not a rule-based collator.
if (locale_string == "") {
if (strlen(locale_string) <= 0) {
uni_coll = Collator::createInstance(status);
} else {
cout << "# Locale set to " << locale_string << endl;
uni_coll = Collator::createInstance(Locale(locale_string), status);
}

Expand Down Expand Up @@ -219,20 +218,10 @@ const string TestCollator(json_object *json_in) {
}

// Just to check the result.
UColAttributeValue alternate_value =
uni_coll->getAttribute(UCOL_ALTERNATE_HANDLING, status);
uni_coll->getAttribute(UCOL_ALTERNATE_HANDLING, status); // ignore return

// Try two differen APIs
uni_result_utf8 = uni_coll->compareUTF8(string1, string2, status);
// This one seems to work better.
// Perform the string comparison
uni_result = uni_coll->compare(us1, us2, status);

if (uni_result != uni_result_utf8) {
cout << "# UNI_COLL COMPARE Unicode String " << uni_result << " ";
cout << "# UNI_COLL COMPARE UTF8 String " << uni_result_utf8 << endl;
cout << "# ******* results different in " << label_string << endl;
}

if (U_FAILURE(status)) {
json_object_object_add(
return_json,
Expand All @@ -243,8 +232,7 @@ const string TestCollator(json_object *json_in) {
error_message << endl;
}
if (uni_coll) {
UColAttributeValue alternate_value =
uni_coll->getAttribute(UCOL_ALTERNATE_HANDLING, status);
uni_coll->getAttribute(UCOL_ALTERNATE_HANDLING, status); // ignore result
}
delete uni_coll;
}
Expand All @@ -259,7 +247,7 @@ const string TestCollator(json_object *json_in) {
// Check unescaped versions.
char char_out1[1000] = "";
char char_out2[1000] = "";
int32_t chars_out = us1.extract(char_out1, 1000, nullptr, status);
us1.extract(char_out1, 1000, nullptr, status); // ignore result
if (U_FAILURE(status)) {
test_result = error_message;
json_object_object_add(
Expand All @@ -270,7 +258,7 @@ const string TestCollator(json_object *json_in) {
test_result << endl;
}

int32_t chars_out2 = us2.extract(char_out2, 1000, nullptr, status);
us2.extract(char_out2, 1000, nullptr, status); // ignore result
if (U_FAILURE(status)) {
test_result = error_message;
// TODO: report the error in creating the instance
Expand All @@ -289,7 +277,7 @@ const string TestCollator(json_object *json_in) {
json_object_object_add(
return_json, "s2", json_object_new_string(string2.c_str()));

// What was the actual returned value?
// Record the actual returned value
json_object_object_add(
return_json, "compare", json_object_new_int64(uni_result));
} else {
Expand Down
12 changes: 3 additions & 9 deletions executors/cpp/datetime_fmt.cpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
/********************************************************************
* Comments and license as needed
************************************
/******
* testing datetime format
* testing icu4c datetime format
*/

#include <json-c/json.h>
Expand Down Expand Up @@ -251,11 +247,9 @@ const string TestDatetimeFmt(json_object *json_in) {
df->format(test_date_time, formatted_result);

// Get the resulting value as a string
string test_result;
int32_t chars_out; // Extracted characters from Unicode string
char test_result_string[1000] = "";
chars_out = formatted_result.extract(
test_result_string, 1000, nullptr, status);
formatted_result.extract(
test_result_string, 1000, nullptr, status); // ignore return value

if (U_FAILURE(status)) {
json_object_object_add(
Expand Down
9 changes: 2 additions & 7 deletions executors/cpp/langnames.cpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
/********************************************************************
* Comments and license as needed
************************************
/******
* testing language display names
* testing icu4c for language display names
*/

#include <json-c/json.h>
Expand Down Expand Up @@ -60,8 +56,7 @@ const string TestLangNames (json_object *json_in) {

char test_result_string[1000] = "";

int32_t chars_out = testLang.extract(
test_result_string, 1000, nullptr, status);
testLang.extract(test_result_string, 1000, nullptr, status); // ignore return
if (U_FAILURE(status)) {
json_object_object_add(
return_json,
Expand Down
62 changes: 31 additions & 31 deletions executors/cpp/likely_subtags.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,7 @@ const string TestLikelySubtags(json_object *json_in) {

Locale displayLocale(locale_string.c_str());

const char* test_result;
const string error_message_max = "error in maximize";
const string error_message_min = "error in minimize";
const string protected_msg = "This ICU4C API is protected";
const char* empty_result = "";
string test_result = "";

json_object *return_json = json_object_new_object();
json_object_object_add(return_json, "label", label_obj);
Expand All @@ -52,17 +48,13 @@ const string TestLikelySubtags(json_object *json_in) {
string name_string;
StringByteSink<string> byteSink(&name_string);

// If needed.
json_object *error_msg = json_object_new_object();

test_result = empty_result;
if (option_string == "maximize") {
// This makes the maximized form
Locale maximized(displayLocale);
maximized.addLikelySubtags(status);

if (U_FAILURE(status)) {
test_result = error_message_max.c_str();
test_result = "error in maximize";
} else {
maximized.toLanguageTag(byteSink, status);

Expand All @@ -72,17 +64,18 @@ const string TestLikelySubtags(json_object *json_in) {
"error",
json_object_new_string("toLanguageTag"));
}
test_result = name_string.c_str();
test_result = name_string;
}
} else if (option_string == "minimize" ||
option_string == "minimizeFavorRegion") {
// Minimize
displayLocale.minimizeSubtags(status);
if (U_FAILURE(status)) {
test_result = error_message_min.c_str();
const string error_message_min = "error in minimize";
test_result = error_message_min;
} else {
displayLocale.toLanguageTag(byteSink, status);
test_result = name_string.c_str();
test_result = name_string;

if (U_FAILURE(status)) {
json_object_object_add(
Expand All @@ -94,18 +87,23 @@ const string TestLikelySubtags(json_object *json_in) {
} else if (option_string == "minimizeFavorScript") {
// Minimize with script preferred.
bool favorScript = true;
json_object_object_add(return_json,
"error",
json_object_new_string("unsupported option"));
json_object_object_add(return_json,
"error_type",
json_object_new_string("unsupported"));
json_object_object_add(return_json,
"unsupported",
json_object_new_string(option_string.c_str()));
json_object_object_add(return_json,
"error_detail",
json_object_new_string(protected_msg.c_str()));
json_object_object_add(
return_json,
"error",
json_object_new_string("unsupported option"));
json_object_object_add(
return_json,
"error_type",
json_object_new_string("unsupported"));
json_object_object_add(
return_json,
"unsupported",
json_object_new_string(option_string.c_str()));
json_object_object_add(
return_json,
"error_detail",
json_object_new_string("This ICU4C API is protected"));

// This is a protected API in ICU4C.
// displayLocale.minimizeSubtags(favorScript, status);
} else {
Expand All @@ -121,14 +119,16 @@ const string TestLikelySubtags(json_object *json_in) {
}

if (U_FAILURE(status)) {
json_object_object_add(return_json,
"error",
json_object_new_string(test_result));
json_object_object_add(
return_json,
"error",
json_object_new_string(test_result.c_str()));
} else {
// The output of the likely subtag operation.
json_object_object_add(return_json,
"result",
json_object_new_string(test_result));
json_object_object_add(
return_json,
"result",
json_object_new_string(test_result.c_str()));
}

return json_object_to_json_string(return_json);
Expand Down
19 changes: 7 additions & 12 deletions executors/cpp/list_fmt.cpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
/********************************************************************
* Comments and license as needed
************************************
/******
* testing list formatting
* testing list formatting in icu4c
*/
#include <json-c/json.h>

Expand Down Expand Up @@ -51,7 +47,6 @@ const string TestListFmt (json_object* json_in) {
std::vector<UnicodeString> u_strings;
int u_strings_size = 0;
if (input_list_obj) {
struct array_list* input_list_array = json_object_get_array(input_list_obj);
int input_length = json_object_array_length(input_list_obj);

// Construct the list of Unicode Strings
Expand All @@ -61,7 +56,7 @@ const string TestListFmt (json_object* json_in) {
string item_string = json_object_get_string(item);
u_strings.push_back(item_string.c_str());
}
u_strings_size = u_strings_size = u_strings.size();
u_strings_size = u_strings.size();
} else {
json_object_object_add(
return_json,
Expand Down Expand Up @@ -110,9 +105,9 @@ const string TestListFmt (json_object* json_in) {
UnicodeString *u_array = &u_strings[0];
UnicodeString u_result_string;
u_result_string = list_formatter->format(u_array,
u_strings_size,
u_result_string,
status);
u_strings_size,
u_result_string,
status);

char test_result_string[1000] = "";
if (U_FAILURE(status)) {
Expand All @@ -121,8 +116,8 @@ const string TestListFmt (json_object* json_in) {
"error",
json_object_new_string("calling list format"));
} else {
int32_t chars_out =
u_result_string.extract(test_result_string, 1000, nullptr, status);
u_result_string.extract(
test_result_string, 1000, nullptr, status); // result ignored
}

if (U_FAILURE(status)) {
Expand Down
Loading

0 comments on commit f46ec37

Please sign in to comment.