diff --git a/icu4c/source/common/unicode/ustring.h b/icu4c/source/common/unicode/ustring.h index 12411ef6d9..a95cb6d83b 100644 --- a/icu4c/source/common/unicode/ustring.h +++ b/icu4c/source/common/unicode/ustring.h @@ -917,6 +917,20 @@ u_memrchr32(const UChar *s, UChar32 c, int32_t count); * return u_strcmp(ustringVar1, ustringVar2); * } * + * + * Note that the macros will NOT consistently work if their argument is another + * #define. The following will not work on all platforms, don't use it. + * + *
+ *     #define GLUCK "Mr. Gluck"
+ *     U_STRING_DECL(var, GLUCK, 9)
+ *     U_STRING_INIT(var, GLUCK, 9)
+ * 
+ * + * Instead, use the string literal "Mr. Gluck" as the argument to both macro + * calls. + * + * * @stable ICU 2.0 */ #if defined(U_DECLARE_UTF16) diff --git a/icu4c/source/test/iotest/stream.cpp b/icu4c/source/test/iotest/stream.cpp index ec1af875d3..b927746f90 100644 --- a/icu4c/source/test/iotest/stream.cpp +++ b/icu4c/source/test/iotest/stream.cpp @@ -204,17 +204,6 @@ testString( } } -#define EOF_TESTCASE_1 "" -#define EOF_TESTCASE_2 "foo" -#define EOF_TESTCASE_3 " " -#define EOF_TESTCASE_4 " bar" -#define EOF_TESTCASE_5 "bar " -#define EOF_TESTCASE_6 " bar " - -#define EOF_RESULT_EXPECTED_A "" -#define EOF_RESULT_EXPECTED_B "foo" -#define EOF_RESULT_EXPECTED_C "unchanged" -#define EOF_RESULT_EXPECTED_D "bar" static void U_CALLCONV TestStreamEOF(void) { @@ -252,30 +241,30 @@ static void U_CALLCONV TestStreamEOF(void) log_verbose("Testing operator >> for UnicodeString...\n"); - /* The test cases needs to be converted to the default codepage. However, the stream operator needs char* so u_austrcpy is called. */ - U_STRING_DECL(testCase1, EOF_TESTCASE_1, 0); - U_STRING_DECL(testCase2, EOF_TESTCASE_2, 3); - U_STRING_DECL(testCase3, EOF_TESTCASE_3, 3); - U_STRING_DECL(testCase4, EOF_TESTCASE_4, 6); - U_STRING_DECL(testCase5, EOF_TESTCASE_5, 6); - U_STRING_DECL(testCase6, EOF_TESTCASE_6, 9); + /* The test cases needs to be converted to the default codepage. However, the stream operator needs char* so U_STRING_* is called. */ + U_STRING_DECL(testCase1, "", 0); + U_STRING_INIT(testCase1, "", 0); + U_STRING_DECL(testCase2, "foo", 3); + U_STRING_INIT(testCase2, "foo", 3); + U_STRING_DECL(testCase3, " ", 3); + U_STRING_INIT(testCase3, " ", 3); + U_STRING_DECL(testCase4, " bar", 6); + U_STRING_INIT(testCase4, " bar", 6); + U_STRING_DECL(testCase5, "bar ", 6); + U_STRING_INIT(testCase5, "bar ", 6); + U_STRING_DECL(testCase6, " bar ", 9); + U_STRING_INIT(testCase6, " bar ", 9); - U_STRING_INIT(testCase1, EOF_TESTCASE_1, 0); - U_STRING_INIT(testCase2, EOF_TESTCASE_2, 3); - U_STRING_INIT(testCase3, EOF_TESTCASE_3, 3); - U_STRING_INIT(testCase4, EOF_TESTCASE_4, 6); - U_STRING_INIT(testCase5, EOF_TESTCASE_5, 6); - U_STRING_INIT(testCase6, EOF_TESTCASE_6, 9); - U_STRING_DECL(expectedResultA, EOF_RESULT_EXPECTED_A, 0); - U_STRING_DECL(expectedResultB, EOF_RESULT_EXPECTED_B, 3); - U_STRING_DECL(expectedResultC, EOF_RESULT_EXPECTED_C, 9); - U_STRING_DECL(expectedResultD, EOF_RESULT_EXPECTED_D, 3); + U_STRING_DECL(expectedResultA, "", 0); + U_STRING_INIT(expectedResultA, "", 0); + U_STRING_DECL(expectedResultB, "foo", 3); + U_STRING_INIT(expectedResultB, "foo", 3); + U_STRING_DECL(expectedResultC, "unchanged", 9); + U_STRING_INIT(expectedResultC, "unchanged", 9); + U_STRING_DECL(expectedResultD, "bar", 3); + U_STRING_INIT(expectedResultD, "bar", 3); - U_STRING_INIT(expectedResultA, EOF_RESULT_EXPECTED_A, 0); - U_STRING_INIT(expectedResultB, EOF_RESULT_EXPECTED_B, 3); - U_STRING_INIT(expectedResultC, EOF_RESULT_EXPECTED_C, 9); - U_STRING_INIT(expectedResultD, EOF_RESULT_EXPECTED_D, 3); UnicodeString UStr; UnicodeString expectedResults;