Skip to content

Commit

Permalink
ICU-22936 Replace all ICU4C code that uses UBool as an integer.
Browse files Browse the repository at this point in the history
  • Loading branch information
roubert committed Oct 7, 2024
1 parent 5b45e5c commit 6ca2885
Show file tree
Hide file tree
Showing 15 changed files with 29 additions and 43 deletions.
4 changes: 2 additions & 2 deletions icu4c/source/common/unicode/utf8.h
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@
* @internal
*/
U_CAPI UChar32 U_EXPORT2
utf8_nextCharSafeBody(const uint8_t *s, int32_t *pi, int32_t length, UChar32 c, UBool strict);
utf8_nextCharSafeBody(const uint8_t *s, int32_t *pi, int32_t length, UChar32 c, int8_t strict);

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

/**
* Function for handling "skip backward one code point" with error-checking.
Expand Down
2 changes: 1 addition & 1 deletion icu4c/source/common/usprep.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ compareEntries(const UHashTok p1, const UHashTok p2) {
name2.pointer = b2->name;
path1.pointer = b1->path;
path2.pointer = b2->path;
return uhash_compareChars(name1, name2) & uhash_compareChars(path1, path2);
return uhash_compareChars(name1, name2) && uhash_compareChars(path1, path2);
}

static void
Expand Down
6 changes: 2 additions & 4 deletions icu4c/source/common/utf_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,11 +124,9 @@ errorValue(int32_t count, int8_t strict) {
* >0 Obsolete "strict" behavior of UTF8_NEXT_CHAR_SAFE(..., true):
* Same as the obsolete "safe" behavior, but non-characters are also treated
* like illegal sequences.
*
* Note that a UBool is the same as an int8_t.
*/
U_CAPI UChar32 U_EXPORT2
utf8_nextCharSafeBody(const uint8_t *s, int32_t *pi, int32_t length, UChar32 c, UBool strict) {
utf8_nextCharSafeBody(const uint8_t *s, int32_t *pi, int32_t length, UChar32 c, int8_t strict) {
// *pi is one after byte c.
int32_t i=*pi;
// length can be negative for NUL-terminated strings: Read and validate one byte at a time.
Expand Down Expand Up @@ -233,7 +231,7 @@ utf8_appendCharSafeBody(uint8_t *s, int32_t i, int32_t length, UChar32 c, UBool
}

U_CAPI UChar32 U_EXPORT2
utf8_prevCharSafeBody(const uint8_t *s, int32_t start, int32_t *pi, UChar32 c, UBool strict) {
utf8_prevCharSafeBody(const uint8_t *s, int32_t start, int32_t *pi, UChar32 c, int8_t strict) {
// *pi is the index of byte c.
int32_t i=*pi;
if(U8_IS_TRAIL(c) && i>start) {
Expand Down
6 changes: 3 additions & 3 deletions icu4c/source/i18n/scriptset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -285,19 +285,19 @@ uhash_equalsScriptSet(const UElement key1, const UElement key2) {
return (*s1 == *s2);
}

U_CAPI int8_t U_EXPORT2
U_CAPI int32_t U_EXPORT2
uhash_compareScriptSet(UElement key0, UElement key1) {
icu::ScriptSet *s0 = static_cast<icu::ScriptSet *>(key0.pointer);
icu::ScriptSet *s1 = static_cast<icu::ScriptSet *>(key1.pointer);
int32_t diff = s0->countMembers() - s1->countMembers();
if (diff != 0) return static_cast<UBool>(diff);
if (diff != 0) return diff;
int32_t i0 = s0->nextSetBit(0);
int32_t i1 = s1->nextSetBit(0);
while ((diff = i0-i1) == 0 && i0 > 0) {
i0 = s0->nextSetBit(i0+1);
i1 = s1->nextSetBit(i1+1);
}
return (int8_t)diff;
return diff;
}

U_CAPI int32_t U_EXPORT2
Expand Down
2 changes: 1 addition & 1 deletion icu4c/source/i18n/scriptset.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ class U_I18N_API ScriptSet: public UMemory {

U_NAMESPACE_END

U_CAPI UBool U_EXPORT2
U_CAPI int32_t U_EXPORT2
uhash_compareScriptSet(const UElement key1, const UElement key2);

U_CAPI int32_t U_EXPORT2
Expand Down
2 changes: 1 addition & 1 deletion icu4c/source/test/cintltst/cloctst.c
Original file line number Diff line number Diff line change
Expand Up @@ -2879,7 +2879,7 @@ static void TestDisplayNameWarning(void) {
* starts with `prefix' plus an additional element, that is, string ==
* prefix + '_' + x, then return 1. Otherwise return a value < 0.
*/
static UBool _loccmp(const char* string, const char* prefix) {
static int32_t _loccmp(const char* string, const char* prefix) {
int32_t slen = (int32_t)uprv_strlen(string),
plen = (int32_t)uprv_strlen(prefix);
int32_t c = uprv_strncmp(string, prefix, plen);
Expand Down
3 changes: 1 addition & 2 deletions icu4c/source/test/cintltst/creststn.c
Original file line number Diff line number Diff line change
Expand Up @@ -3035,7 +3035,6 @@ tres_getString(const UResourceBundle *resB,
const char *s8;
UChar32 c16, c8;
int32_t length16, length8, i16, i8;
UBool forceCopy;

if(length == NULL) {
length = &length16;
Expand All @@ -3053,7 +3052,7 @@ tres_getString(const UResourceBundle *resB,
length16 = *length;

/* try the UTF-8 variant of ures_getStringXYZ() */
for(forceCopy = false; forceCopy <= true; ++forceCopy) {
for (int8_t forceCopy = 0; forceCopy <= 1; ++forceCopy) {
p8 = buffer8;
length8 = (int32_t)sizeof(buffer8);
if(idx >= 0) {
Expand Down
8 changes: 4 additions & 4 deletions icu4c/source/test/cintltst/cucdtst.c
Original file line number Diff line number Diff line change
Expand Up @@ -431,12 +431,12 @@ compareUSets(const USet *a, const USet *b,
const char *a_name, const char *b_name,
UBool diffIsError) {
/*
* Use an arithmetic & not a logical && so that both branches
* Use temporary variables so that both branches
* are always taken and all differences are shown.
*/
return
showAMinusB(a, b, a_name, b_name, diffIsError) &
showAMinusB(b, a, b_name, a_name, diffIsError);
UBool ab = showAMinusB(a, b, a_name, b_name, diffIsError);
UBool ba = showAMinusB(b, a, b_name, a_name, diffIsError);
return ab && ba;
}

/* test isLetter(u_isapha()) and isDigit(u_isdigit()) */
Expand Down
13 changes: 1 addition & 12 deletions icu4c/source/test/cintltst/udatatst.c
Original file line number Diff line number Diff line change
Expand Up @@ -1139,18 +1139,7 @@ static void TestICUDataName(void)
switch(U_CHARSET_FAMILY)
{
case U_ASCII_FAMILY:
switch((int)U_IS_BIG_ENDIAN)
{
case 1:
typeChar = 'b';
break;
case 0:
typeChar = 'l';
break;
default:
log_err("Expected 1 or 0 for U_IS_BIG_ENDIAN, got %d!\n", U_IS_BIG_ENDIAN);
/* return; */
}
typeChar = U_IS_BIG_ENDIAN ? 'b' : 'l';
break;
case U_EBCDIC_FAMILY:
typeChar = 'e';
Expand Down
2 changes: 1 addition & 1 deletion icu4c/source/test/intltest/caltest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3918,7 +3918,7 @@ void CalendarTest::TestClearMonth() {
if (failure(status, "Calendar::get(UCAL_MONTH)")) return;
cal->clear(UCAL_MONTH);
assertEquals("Calendar::isSet(UCAL_MONTH) after clear(UCAL_MONTH)", false, !!cal->isSet(UCAL_MONTH));
assertEquals("Calendar::get(UCAL_MONTH after clear(UCAL_MONTH))", UCAL_JANUARY, !!cal->get(UCAL_MONTH, status));
assertEquals("Calendar::get(UCAL_MONTH after clear(UCAL_MONTH))", UCAL_JANUARY, cal->get(UCAL_MONTH, status));
if (failure(status, "Calendar::get(UCAL_MONTH)")) return;

cal->set(UCAL_ORDINAL_MONTH, 7);
Expand Down
8 changes: 4 additions & 4 deletions icu4c/source/test/intltest/collationtest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1754,10 +1754,10 @@ UBool CollationTest::checkCompareTwo(const char *norm, const UnicodeString &prev
// sortkey(str1 + "\uFFFE" + str2) == mergeSortkeys(sortkey(str1), sortkey(str2))
// only that those two methods yield the same order.
//
// Use bit-wise OR so that getMergedCollationKey() is always called for both strings.
if((getMergedCollationKey(prevString.getBuffer(), prevString.length(), prevKey, errorCode) |
getMergedCollationKey(s.getBuffer(), s.length(), key, errorCode)) ||
errorCode.isFailure()) {
// Use two variables so that getMergedCollationKey() is always called for both strings.
if (UBool prev = getMergedCollationKey(prevString.getBuffer(), prevString.length(), prevKey, errorCode),
curr = getMergedCollationKey(s.getBuffer(), s.length(), key, errorCode);
prev || curr || errorCode.isFailure()) {
order = prevKey.compareTo(key, errorCode);
if(order != expectedOrder || errorCode.isFailure()) {
infoln(fileTestName);
Expand Down
2 changes: 1 addition & 1 deletion icu4c/source/test/intltest/uvectest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ UVectorTest_compareInt32(UElement key1, UElement key2) {
}

U_CDECL_BEGIN
static int8_t U_CALLCONV
static UBool U_CALLCONV
UVectorTest_compareCstrings(const UElement key1, const UElement key2) {
return !strcmp((const char *)key1.pointer, (const char *)key2.pointer);
}
Expand Down
4 changes: 2 additions & 2 deletions icu4c/source/tools/makeconv/makeconv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -684,7 +684,7 @@ createConverter(ConvData *data, const char *converterName, UErrorCode *pErrorCod

} else if(
data->ucm->ext->mappingsLength>0 &&
!ucm_checkBaseExt(states, data->ucm->base, data->ucm->ext, data->ucm->ext, false)
!ucm_checkBaseExt(states, data->ucm->base, data->ucm->ext, data->ucm->ext, 0)
) {
*pErrorCode=U_INVALID_TABLE_FORMAT;
} else if(data->ucm->base->flagsType&UCM_FLAGS_EXPLICIT) {
Expand Down Expand Up @@ -804,7 +804,7 @@ createConverter(ConvData *data, const char *converterName, UErrorCode *pErrorCod

} else if(
!ucm_checkValidity(data->ucm->ext, baseStates) ||
!ucm_checkBaseExt(baseStates, baseData.ucm->base, data->ucm->ext, data->ucm->ext, false)
!ucm_checkBaseExt(baseStates, baseData.ucm->base, data->ucm->ext, data->ucm->ext, 0)
) {
*pErrorCode=U_INVALID_TABLE_FORMAT;
} else {
Expand Down
8 changes: 4 additions & 4 deletions icu4c/source/tools/toolutil/ucm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ enum {

static uint8_t
checkBaseExtUnicode(UCMStates *baseStates, UCMTable *base, UCMTable *ext,
UBool moveToExt, UBool intersectBase) {
UBool moveToExt, int8_t intersectBase) {
(void)baseStates;

UCMapping *mb, *me, *mbLimit, *meLimit;
Expand Down Expand Up @@ -416,7 +416,7 @@ checkBaseExtUnicode(UCMStates *baseStates, UCMTable *base, UCMTable *ext,

static uint8_t
checkBaseExtBytes(UCMStates *baseStates, UCMTable *base, UCMTable *ext,
UBool moveToExt, UBool intersectBase) {
UBool moveToExt, int8_t intersectBase) {
UCMapping *mb, *me;
int32_t *baseMap, *extMap;
int32_t b, e, bLimit, eLimit, cmp;
Expand Down Expand Up @@ -556,7 +556,7 @@ ucm_checkValidity(UCMTable *table, UCMStates *baseStates) {
U_CAPI UBool U_EXPORT2
ucm_checkBaseExt(UCMStates *baseStates,
UCMTable *base, UCMTable *ext, UCMTable *moveTarget,
UBool intersectBase) {
int8_t intersectBase) {
uint8_t result;

/* if we have an extension table, we must always use precision flags */
Expand Down Expand Up @@ -735,7 +735,7 @@ ucm_separateMappings(UCMFile *ucm, UBool isSISO) {
}
if(needsMove) {
ucm_moveMappings(ucm->base, ucm->ext);
return ucm_checkBaseExt(&ucm->states, ucm->base, ucm->ext, ucm->ext, false);
return ucm_checkBaseExt(&ucm->states, ucm->base, ucm->ext, ucm->ext, 0);
} else {
ucm_sortTable(ucm->base);
return true;
Expand Down
2 changes: 1 addition & 1 deletion icu4c/source/tools/toolutil/ucm.h
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ ucm_checkValidity(UCMTable *ext, UCMStates *baseStates);
*/
U_CAPI UBool U_EXPORT2
ucm_checkBaseExt(UCMStates *baseStates, UCMTable *base, UCMTable *ext,
UCMTable *moveTarget, UBool intersectBase);
UCMTable *moveTarget, int8_t intersectBase);

U_CAPI void U_EXPORT2
ucm_printTable(UCMTable *table, FILE *f, UBool byUnicode);
Expand Down

0 comments on commit 6ca2885

Please sign in to comment.