Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ICU-22954 Revert to using std::u16string instead of UnicodeString #3328

Merged
merged 1 commit into from
Jan 8, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions icu4c/source/tools/ctestfw/tstdtmod.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
#include <stdarg.h>

#include "unicode/tstdtmod.h"
#include "unicode/unistr.h"
#include "cmemory.h"
#include <stdio.h>
#include "cstr.h"
Expand All @@ -21,15 +20,14 @@ TestLog::~TestLog() {}

IcuTestErrorCode::IcuTestErrorCode(TestLog &callingTestClass, const char *callingTestName)
: errorCode(U_ZERO_ERROR),
testClass(callingTestClass), testName(callingTestName), scopeMessage(*new UnicodeString) {
testClass(callingTestClass), testName(callingTestName), scopeMessage() {
}

IcuTestErrorCode::~IcuTestErrorCode() {
// Safe because our errlog() does not throw exceptions.
if(isFailure()) {
errlog(false, u"destructor: expected success", nullptr);
}
delete &scopeMessage;
}

UErrorCode IcuTestErrorCode::reset() {
Expand Down Expand Up @@ -126,7 +124,8 @@ UBool IcuTestErrorCode::expectErrorAndReset(UErrorCode expectedError, const char
}

void IcuTestErrorCode::setScope(const char* message) {
scopeMessage.remove().append({ message, -1, US_INV });
UnicodeString us(message, -1, US_INV);
scopeMessage = us;
}

void IcuTestErrorCode::setScope(std::u16string_view message) {
Expand All @@ -142,7 +141,7 @@ void IcuTestErrorCode::errlog(UBool dataErr, std::u16string_view mainMessage, co
msg.append(u' ').append(mainMessage);
msg.append(u" but got error: ").append(UnicodeString(errorName(), -1, US_INV));

if (!scopeMessage.isEmpty()) {
if (!scopeMessage.empty()) {
msg.append(u" scope: ").append(scopeMessage);
}

Expand Down
14 changes: 2 additions & 12 deletions icu4c/source/tools/ctestfw/unicode/testlog.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#ifndef U_TESTFW_TESTLOG
#define U_TESTFW_TESTLOG

#include <string>
#include <string_view>
#include "unicode/utypes.h"
#include "unicode/testtype.h"
Expand All @@ -34,10 +35,6 @@ class T_CTEST_EXPORT_API TestLog {
// unit tests that work without U_SHOW_CPLUSPLUS_API.
// So instead we *copy* the ErrorCode API.

U_NAMESPACE_BEGIN
class UnicodeString;
U_NAMESPACE_END

class T_CTEST_EXPORT_API IcuTestErrorCode {
public:
IcuTestErrorCode(const IcuTestErrorCode&) = delete;
Expand Down Expand Up @@ -76,14 +73,7 @@ class T_CTEST_EXPORT_API IcuTestErrorCode {
UErrorCode errorCode;
TestLog &testClass;
const char *const testName;

// It's not possible to use a UnicodeString member directly here because
// that won't work without U_SHOW_CPLUSPLUS_API, but it's also not possible
// to use a std::u16string member because for unknown reasons that leads to
// a crash in the icu4c-windows-cygwin-gcc CI job. As a workaround, the
// UnicodeString class is forward declared to make it possible to use a
// reference here and then heap allocate the object in the constructor.
UnicodeString& scopeMessage;
std::u16string scopeMessage;

void errlog(UBool dataErr, std::u16string_view mainMessage, const char* extraMessage) const;
};
Expand Down