Skip to content

Commit 6ca2885

Browse files
committed
ICU-22936 Replace all ICU4C code that uses UBool as an integer.
1 parent 5b45e5c commit 6ca2885

File tree

15 files changed

+29
-43
lines changed

15 files changed

+29
-43
lines changed

icu4c/source/common/unicode/utf8.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@
124124
* @internal
125125
*/
126126
U_CAPI UChar32 U_EXPORT2
127-
utf8_nextCharSafeBody(const uint8_t *s, int32_t *pi, int32_t length, UChar32 c, UBool strict);
127+
utf8_nextCharSafeBody(const uint8_t *s, int32_t *pi, int32_t length, UChar32 c, int8_t strict);
128128

129129
/**
130130
* Function for handling "append code point" with error-checking.
@@ -148,7 +148,7 @@ utf8_appendCharSafeBody(uint8_t *s, int32_t i, int32_t length, UChar32 c, UBool
148148
* @internal
149149
*/
150150
U_CAPI UChar32 U_EXPORT2
151-
utf8_prevCharSafeBody(const uint8_t *s, int32_t start, int32_t *pi, UChar32 c, UBool strict);
151+
utf8_prevCharSafeBody(const uint8_t *s, int32_t start, int32_t *pi, UChar32 c, int8_t strict);
152152

153153
/**
154154
* Function for handling "skip backward one code point" with error-checking.

icu4c/source/common/usprep.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ compareEntries(const UHashTok p1, const UHashTok p2) {
126126
name2.pointer = b2->name;
127127
path1.pointer = b1->path;
128128
path2.pointer = b2->path;
129-
return uhash_compareChars(name1, name2) & uhash_compareChars(path1, path2);
129+
return uhash_compareChars(name1, name2) && uhash_compareChars(path1, path2);
130130
}
131131

132132
static void

icu4c/source/common/utf_impl.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -124,11 +124,9 @@ errorValue(int32_t count, int8_t strict) {
124124
* >0 Obsolete "strict" behavior of UTF8_NEXT_CHAR_SAFE(..., true):
125125
* Same as the obsolete "safe" behavior, but non-characters are also treated
126126
* like illegal sequences.
127-
*
128-
* Note that a UBool is the same as an int8_t.
129127
*/
130128
U_CAPI UChar32 U_EXPORT2
131-
utf8_nextCharSafeBody(const uint8_t *s, int32_t *pi, int32_t length, UChar32 c, UBool strict) {
129+
utf8_nextCharSafeBody(const uint8_t *s, int32_t *pi, int32_t length, UChar32 c, int8_t strict) {
132130
// *pi is one after byte c.
133131
int32_t i=*pi;
134132
// length can be negative for NUL-terminated strings: Read and validate one byte at a time.
@@ -233,7 +231,7 @@ utf8_appendCharSafeBody(uint8_t *s, int32_t i, int32_t length, UChar32 c, UBool
233231
}
234232

235233
U_CAPI UChar32 U_EXPORT2
236-
utf8_prevCharSafeBody(const uint8_t *s, int32_t start, int32_t *pi, UChar32 c, UBool strict) {
234+
utf8_prevCharSafeBody(const uint8_t *s, int32_t start, int32_t *pi, UChar32 c, int8_t strict) {
237235
// *pi is the index of byte c.
238236
int32_t i=*pi;
239237
if(U8_IS_TRAIL(c) && i>start) {

icu4c/source/i18n/scriptset.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -285,19 +285,19 @@ uhash_equalsScriptSet(const UElement key1, const UElement key2) {
285285
return (*s1 == *s2);
286286
}
287287

288-
U_CAPI int8_t U_EXPORT2
288+
U_CAPI int32_t U_EXPORT2
289289
uhash_compareScriptSet(UElement key0, UElement key1) {
290290
icu::ScriptSet *s0 = static_cast<icu::ScriptSet *>(key0.pointer);
291291
icu::ScriptSet *s1 = static_cast<icu::ScriptSet *>(key1.pointer);
292292
int32_t diff = s0->countMembers() - s1->countMembers();
293-
if (diff != 0) return static_cast<UBool>(diff);
293+
if (diff != 0) return diff;
294294
int32_t i0 = s0->nextSetBit(0);
295295
int32_t i1 = s1->nextSetBit(0);
296296
while ((diff = i0-i1) == 0 && i0 > 0) {
297297
i0 = s0->nextSetBit(i0+1);
298298
i1 = s1->nextSetBit(i1+1);
299299
}
300-
return (int8_t)diff;
300+
return diff;
301301
}
302302

303303
U_CAPI int32_t U_EXPORT2

icu4c/source/i18n/scriptset.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ class U_I18N_API ScriptSet: public UMemory {
7474

7575
U_NAMESPACE_END
7676

77-
U_CAPI UBool U_EXPORT2
77+
U_CAPI int32_t U_EXPORT2
7878
uhash_compareScriptSet(const UElement key1, const UElement key2);
7979

8080
U_CAPI int32_t U_EXPORT2

icu4c/source/test/cintltst/cloctst.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2879,7 +2879,7 @@ static void TestDisplayNameWarning(void) {
28792879
* starts with `prefix' plus an additional element, that is, string ==
28802880
* prefix + '_' + x, then return 1. Otherwise return a value < 0.
28812881
*/
2882-
static UBool _loccmp(const char* string, const char* prefix) {
2882+
static int32_t _loccmp(const char* string, const char* prefix) {
28832883
int32_t slen = (int32_t)uprv_strlen(string),
28842884
plen = (int32_t)uprv_strlen(prefix);
28852885
int32_t c = uprv_strncmp(string, prefix, plen);

icu4c/source/test/cintltst/creststn.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3035,7 +3035,6 @@ tres_getString(const UResourceBundle *resB,
30353035
const char *s8;
30363036
UChar32 c16, c8;
30373037
int32_t length16, length8, i16, i8;
3038-
UBool forceCopy;
30393038

30403039
if(length == NULL) {
30413040
length = &length16;
@@ -3053,7 +3052,7 @@ tres_getString(const UResourceBundle *resB,
30533052
length16 = *length;
30543053

30553054
/* try the UTF-8 variant of ures_getStringXYZ() */
3056-
for(forceCopy = false; forceCopy <= true; ++forceCopy) {
3055+
for (int8_t forceCopy = 0; forceCopy <= 1; ++forceCopy) {
30573056
p8 = buffer8;
30583057
length8 = (int32_t)sizeof(buffer8);
30593058
if(idx >= 0) {

icu4c/source/test/cintltst/cucdtst.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -431,12 +431,12 @@ compareUSets(const USet *a, const USet *b,
431431
const char *a_name, const char *b_name,
432432
UBool diffIsError) {
433433
/*
434-
* Use an arithmetic & not a logical && so that both branches
434+
* Use temporary variables so that both branches
435435
* are always taken and all differences are shown.
436436
*/
437-
return
438-
showAMinusB(a, b, a_name, b_name, diffIsError) &
439-
showAMinusB(b, a, b_name, a_name, diffIsError);
437+
UBool ab = showAMinusB(a, b, a_name, b_name, diffIsError);
438+
UBool ba = showAMinusB(b, a, b_name, a_name, diffIsError);
439+
return ab && ba;
440440
}
441441

442442
/* test isLetter(u_isapha()) and isDigit(u_isdigit()) */

icu4c/source/test/cintltst/udatatst.c

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1139,18 +1139,7 @@ static void TestICUDataName(void)
11391139
switch(U_CHARSET_FAMILY)
11401140
{
11411141
case U_ASCII_FAMILY:
1142-
switch((int)U_IS_BIG_ENDIAN)
1143-
{
1144-
case 1:
1145-
typeChar = 'b';
1146-
break;
1147-
case 0:
1148-
typeChar = 'l';
1149-
break;
1150-
default:
1151-
log_err("Expected 1 or 0 for U_IS_BIG_ENDIAN, got %d!\n", U_IS_BIG_ENDIAN);
1152-
/* return; */
1153-
}
1142+
typeChar = U_IS_BIG_ENDIAN ? 'b' : 'l';
11541143
break;
11551144
case U_EBCDIC_FAMILY:
11561145
typeChar = 'e';

icu4c/source/test/intltest/caltest.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3918,7 +3918,7 @@ void CalendarTest::TestClearMonth() {
39183918
if (failure(status, "Calendar::get(UCAL_MONTH)")) return;
39193919
cal->clear(UCAL_MONTH);
39203920
assertEquals("Calendar::isSet(UCAL_MONTH) after clear(UCAL_MONTH)", false, !!cal->isSet(UCAL_MONTH));
3921-
assertEquals("Calendar::get(UCAL_MONTH after clear(UCAL_MONTH))", UCAL_JANUARY, !!cal->get(UCAL_MONTH, status));
3921+
assertEquals("Calendar::get(UCAL_MONTH after clear(UCAL_MONTH))", UCAL_JANUARY, cal->get(UCAL_MONTH, status));
39223922
if (failure(status, "Calendar::get(UCAL_MONTH)")) return;
39233923

39243924
cal->set(UCAL_ORDINAL_MONTH, 7);

0 commit comments

Comments
 (0)