Skip to content

Commit

Permalink
ICU-20438 BRS64RC Fix Clang compiler warnings in ICU4C samples
Browse files Browse the repository at this point in the history
  • Loading branch information
jefgen committed Feb 23, 2019
1 parent f128f75 commit ca8eb03
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 32 deletions.
4 changes: 2 additions & 2 deletions icu4c/source/samples/datefmt/main.cpp
Expand Up @@ -48,13 +48,13 @@ int main(int argc, char **argv) {
UDate date;

// The languages in which we will display the date
static char* LANGUAGE[] = {
static const char* LANGUAGE[] = {
"en", "de", "fr"
};
static const int32_t N_LANGUAGE = sizeof(LANGUAGE)/sizeof(LANGUAGE[0]);

// The time zones in which we will display the time
static char* TIMEZONE[] = {
static const char* TIMEZONE[] = {
"America/Los_Angeles",
"America/New_York",
"Europe/Paris",
Expand Down
10 changes: 9 additions & 1 deletion icu4c/source/samples/numfmt/util.cpp
Expand Up @@ -8,6 +8,9 @@
* others. All Rights Reserved.
*************************************************************************/

#define __STDC_FORMAT_MACROS 1
#include <inttypes.h>

#include "unicode/unistr.h"
#include "unicode/fmtable.h"
#include <stdio.h>
Expand Down Expand Up @@ -95,10 +98,15 @@ UnicodeString formattableToString(const Formattable& f) {
return UnicodeString(buf, "");
}
case Formattable::kLong:
{
char buf[256];
sprintf(buf, "%" PRId32 "L", f.getLong());
return UnicodeString(buf, "");
}
case Formattable::kInt64:
{
char buf[256];
sprintf(buf, "%ldL", f.getLong());
sprintf(buf, "%" PRId64 "L", f.getInt64());
return UnicodeString(buf, "");
}
case Formattable::kString:
Expand Down
7 changes: 5 additions & 2 deletions icu4c/source/samples/props/props.cpp
Expand Up @@ -23,6 +23,9 @@
* for Unicode character properties.
*/

#define __STDC_FORMAT_MACROS 1
#include <inttypes.h>

#include <stdio.h>
#include "unicode/utypes.h"
#include "unicode/uchar.h"
Expand All @@ -38,13 +41,13 @@ printProps(UChar32 codePoint) {
u_charName(codePoint, U_UNICODE_CHAR_NAME, buffer, sizeof(buffer), &errorCode);

/* print the code point and the character name */
printf("U+%04lx\t%s\n", codePoint, buffer);
printf("U+%04" PRId32 "\t%s\n", codePoint, buffer);

/* print some properties */
printf(" general category (numeric enum value): %u\n", u_charType(codePoint));

/* note: these APIs do not provide the data from SpecialCasing.txt */
printf(" is lowercase: %d uppercase: U+%04lx\n", u_islower(codePoint), u_toupper(codePoint));
printf(" is lowercase: %d uppercase: U+%04" PRId32 "\n", u_islower(codePoint), u_toupper(codePoint));

printf(" is digit: %d decimal digit value: %d\n", u_isdigit(codePoint), u_charDigitValue(codePoint));

Expand Down
15 changes: 2 additions & 13 deletions icu4c/source/samples/udata/writer.c
Expand Up @@ -70,7 +70,7 @@ main(int argc, const char *argv[]) {
uint16_t intValue=2000;

long dataLength;
uint32_t size;
size_t size;
#ifdef WIN32
char *currdir = _getcwd(NULL, 0);
#else
Expand Down Expand Up @@ -107,19 +107,8 @@ main(int argc, const char *argv[]) {


if(dataLength!=(long)size) {
fprintf(stderr, "Error: data length %ld != calculated size %lu\n", dataLength, size);
fprintf(stderr, "Error: data length %ld != calculated size %zu\n", dataLength, size);
exit(U_INTERNAL_PROGRAM_ERROR);
}
return 0;
}











31 changes: 17 additions & 14 deletions icu4c/source/samples/ustring/ustring.cpp
Expand Up @@ -23,6 +23,9 @@
* with ICU.
*/

#define __STDC_FORMAT_MACROS 1
#include <inttypes.h>

#include <stdio.h>
#include "unicode/utypes.h"
#include "unicode/uchar.h"
Expand Down Expand Up @@ -299,63 +302,63 @@ static void demoCaseMapInC() {
if(U_SUCCESS(errorCode)) {
printUString("full-lowercased/en: ", buffer, length);
} else {
printf("error in u_strToLower(en)=%ld error=%s\n", length, u_errorName(errorCode));
printf("error in u_strToLower(en)=%" PRId32 " error=%s\n", length, u_errorName(errorCode));
}
/* lowercase/Turkish */
errorCode=U_ZERO_ERROR;
length=u_strToLower(buffer, UPRV_LENGTHOF(buffer), input, -1, "tr", &errorCode);
if(U_SUCCESS(errorCode)) {
printUString("full-lowercased/tr: ", buffer, length);
} else {
printf("error in u_strToLower(tr)=%ld error=%s\n", length, u_errorName(errorCode));
printf("error in u_strToLower(tr)=%" PRId32 " error=%s\n", length, u_errorName(errorCode));
}
/* uppercase/English */
errorCode=U_ZERO_ERROR;
length=u_strToUpper(buffer, UPRV_LENGTHOF(buffer), input, -1, "en", &errorCode);
if(U_SUCCESS(errorCode)) {
printUString("full-uppercased/en: ", buffer, length);
} else {
printf("error in u_strToUpper(en)=%ld error=%s\n", length, u_errorName(errorCode));
printf("error in u_strToUpper(en)=%" PRId32 " error=%s\n", length, u_errorName(errorCode));
}
/* uppercase/Turkish */
errorCode=U_ZERO_ERROR;
length=u_strToUpper(buffer, UPRV_LENGTHOF(buffer), input, -1, "tr", &errorCode);
if(U_SUCCESS(errorCode)) {
printUString("full-uppercased/tr: ", buffer, length);
} else {
printf("error in u_strToUpper(tr)=%ld error=%s\n", length, u_errorName(errorCode));
printf("error in u_strToUpper(tr)=%" PRId32 " error=%s\n", length, u_errorName(errorCode));
}
/* titlecase/English */
errorCode=U_ZERO_ERROR;
length=u_strToTitle(buffer, UPRV_LENGTHOF(buffer), input, -1, NULL, "en", &errorCode);
if(U_SUCCESS(errorCode)) {
printUString("full-titlecased/en: ", buffer, length);
} else {
printf("error in u_strToTitle(en)=%ld error=%s\n", length, u_errorName(errorCode));
printf("error in u_strToTitle(en)=%" PRId32 " error=%s\n", length, u_errorName(errorCode));
}
/* titlecase/Turkish */
errorCode=U_ZERO_ERROR;
length=u_strToTitle(buffer, UPRV_LENGTHOF(buffer), input, -1, NULL, "tr", &errorCode);
if(U_SUCCESS(errorCode)) {
printUString("full-titlecased/tr: ", buffer, length);
} else {
printf("error in u_strToTitle(tr)=%ld error=%s\n", length, u_errorName(errorCode));
printf("error in u_strToTitle(tr)=%" PRId32 " error=%s\n", length, u_errorName(errorCode));
}
/* case-fold/default */
errorCode=U_ZERO_ERROR;
length=u_strFoldCase(buffer, UPRV_LENGTHOF(buffer), input, -1, U_FOLD_CASE_DEFAULT, &errorCode);
if(U_SUCCESS(errorCode)) {
printUString("full-case-folded/default: ", buffer, length);
} else {
printf("error in u_strFoldCase(default)=%ld error=%s\n", length, u_errorName(errorCode));
printf("error in u_strFoldCase(default)=%" PRId32 " error=%s\n", length, u_errorName(errorCode));
}
/* case-fold/Turkic */
errorCode=U_ZERO_ERROR;
length=u_strFoldCase(buffer, UPRV_LENGTHOF(buffer), input, -1, U_FOLD_CASE_EXCLUDE_SPECIAL_I, &errorCode);
if(U_SUCCESS(errorCode)) {
printUString("full-case-folded/Turkic: ", buffer, length);
} else {
printf("error in u_strFoldCase(Turkic)=%ld error=%s\n", length, u_errorName(errorCode));
printf("error in u_strFoldCase(Turkic)=%" PRId32 " error=%s\n", length, u_errorName(errorCode));
}
}

Expand Down Expand Up @@ -461,7 +464,7 @@ demoUnicodeStringStorage() {
printUnicodeString("readonly-aliasing string after modification: ", three);
// the aliased array is not modified
for(i=0; i<three.length(); ++i) {
printf("readonly buffer[%d] after modifying its string: 0x%lx\n",
printf("readonly buffer[%d] after modifying its string: 0x%" PRId32 "\n",
i, readonly[i]);
}
// setTo() readonly alias
Expand All @@ -483,15 +486,15 @@ demoUnicodeStringStorage() {
// a modification writes through to the buffer
four.setCharAt(1, 0x39);
for(i=0; i<four.length(); ++i) {
printf("writeable-alias backing buffer[%d]=0x%lx "
printf("writeable-alias backing buffer[%d]=0x%" PRId32 " "
"after modification\n", i, writeable[i]);
}
// a copy will not alias any more;
// instead, it will get a copy of the contents into allocated memory
two=four;
two.setCharAt(1, 0x21);
for(i=0; i<two.length(); ++i) {
printf("writeable-alias backing buffer[%d]=0x%lx after "
printf("writeable-alias backing buffer[%d]=0x%" PRId32 " after "
"modification of string copy\n", i, writeable[i]);
}
// setTo() writeable alias, capacity==length
Expand All @@ -503,8 +506,8 @@ demoUnicodeStringStorage() {
one.truncate(one.length()-1);
// we still operate on the copy
one.setCharAt(1, 0x25);
printf("string after growing too much and then shrinking[1]=0x%lx\n"
" backing store for this[1]=0x%lx\n",
printf("string after growing too much and then shrinking[1]=0x%" PRId32 "\n"
" backing store for this[1]=0x%" PRId32 "\n",
one.charAt(1), writeable[1]);
// if we need it in the original buffer, then extract() to it
// extract() does not do anything if the string aliases that same buffer
Expand All @@ -516,7 +519,7 @@ demoUnicodeStringStorage() {
}
one.extract(0, i, writeable);
for(i=0; i<UPRV_LENGTHOF(writeable); ++i) {
printf("writeable-alias backing buffer[%d]=0x%lx after re-extract\n",
printf("writeable-alias backing buffer[%d]=0x%" PRId32 " after re-extract\n",
i, writeable[i]);
}
}
Expand Down

0 comments on commit ca8eb03

Please sign in to comment.