ICU-21374 Add a CFI build bot for ICU4C

Add the github action bot to build with cfi
Also fix all the known issues which require the change from C style cast to
static_cast inside the i18n and common directory while we are sure about
the object. and use
C++ style dynamic_cast for base-to-derive cast in other code inside i18n
and common and in test code or tool.
Change to use const_cast for casting between const / non-const
This commit is contained in:
Frank Tang 2023-01-13 23:28:06 -08:00 committed by Frank Yung-Fong Tang
parent 87fc840bf7
commit 638acd0c38
81 changed files with 413 additions and 386 deletions

View file

@ -320,6 +320,25 @@ jobs:
env:
CPPFLAGS: -fsanitize=address
LDFLAGS: -fsanitize=address
# Control Flow Integrity.
clang-cfi:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: ICU4C with clang using CFI
run: |
cd icu4c/source;
./runConfigureICU Linux --disable-renaming;
make -j2;
make -j2 check
env:
CC: clang
CXX: clang++
# add -fsanitize=cfi-vcall -fsanitize=cfi-icall later
CXXFLAGS: -flto -fvisibility=hidden -fsanitize=cfi-derived-cast -fno-sanitize-trap=cfi -fno-inline-functions -fno-inline -fno-omit-frame-pointer -O1
# add -fsanitize=cfi-vcall -fsanitize=cfi-icall later
LDFLAGS: -flto -fvisibility=hidden -fuse-ld=gold -fsanitize=cfi-derived-cast -fsanitize=cfi-unrelated-cast -fno-sanitize-trap=cfi -fsanitize-cfi-icall-generalize-pointers
# Clang Linux with thread sanitizer.
clang-tsan:

View file

@ -260,7 +260,7 @@ public:
}
virtual UObject* handleDefault(const ICUServiceKey& key, UnicodeString* /*actualID*/, UErrorCode& status) const override {
LocaleKey& lkey = (LocaleKey&)key;
LocaleKey& lkey = static_cast<LocaleKey&>(const_cast<ICUServiceKey&>(key));
int32_t kind = lkey.kind();
Locale loc;
lkey.currentLocale(loc);

View file

@ -351,13 +351,13 @@ BytesTrieBuilder::BTLinearMatchNode::operator==(const Node &other) const {
if(!LinearMatchNode::operator==(other)) {
return false;
}
const BTLinearMatchNode &o=(const BTLinearMatchNode &)other;
const BTLinearMatchNode &o=static_cast<const BTLinearMatchNode &>(other);
return 0==uprv_memcmp(s, o.s, length);
}
void
BytesTrieBuilder::BTLinearMatchNode::write(StringTrieBuilder &builder) {
BytesTrieBuilder &b=(BytesTrieBuilder &)builder;
BytesTrieBuilder &b=static_cast<BytesTrieBuilder &>(builder);
next->write(builder);
b.write(s, length);
offset=b.write(b.getMinLinearMatch()+length-1);

View file

@ -362,7 +362,7 @@ RuleBasedBreakIterator::operator==(const BreakIterator& that) const {
// and does not implement an equality function that would otherwise be
// checked at this point.
const RuleBasedBreakIterator& that2 = (const RuleBasedBreakIterator&) that;
const RuleBasedBreakIterator& that2 = static_cast<const RuleBasedBreakIterator&>(that);
if (!utext_equals(&fText, &that2.fText)) {
// The two break iterators are operating on different text,

View file

@ -93,7 +93,7 @@ StringCharacterIterator::operator==(const ForwardCharacterIterator& that) const
return false;
}
StringCharacterIterator& realThat = (StringCharacterIterator&)that;
const StringCharacterIterator& realThat = static_cast<const StringCharacterIterator&>(that);
return text == realThat.text
&& pos == realThat.pos

View file

@ -941,7 +941,7 @@ ICUService::acceptsListener(const EventListener& l) const
void
ICUService::notifyListener(EventListener& l) const
{
((ServiceListener&)l).serviceChanged(*this);
(static_cast<ServiceListener&>(l)).serviceChanged(*this);
}
UnicodeString&

View file

@ -47,7 +47,7 @@ LocaleKeyFactory::~LocaleKeyFactory() {
UObject*
LocaleKeyFactory::create(const ICUServiceKey& key, const ICUService* service, UErrorCode& status) const {
if (handlesKey(key, status)) {
const LocaleKey& lkey = (const LocaleKey&)key;
const LocaleKey& lkey = static_cast<const LocaleKey&>(key);
int32_t kind = lkey.kind();
Locale loc;
lkey.currentLocale(loc);

View file

@ -64,7 +64,7 @@ UObject*
SimpleLocaleKeyFactory::create(const ICUServiceKey& key, const ICUService* service, UErrorCode& status) const
{
if (U_SUCCESS(status)) {
const LocaleKey& lkey = (const LocaleKey&)key;
const LocaleKey& lkey = static_cast<const LocaleKey&>(key);
if (_kind == LocaleKey::KIND_ANY || _kind == lkey.kind()) {
UnicodeString keyID;
lkey.currentID(keyID);

View file

@ -404,7 +404,7 @@ StringTrieBuilder::FinalValueNode::operator==(const Node &other) const {
if(!Node::operator==(other)) {
return false;
}
const FinalValueNode &o=(const FinalValueNode &)other;
const FinalValueNode &o=static_cast<const FinalValueNode &>(other);
return value==o.value;
}
@ -421,7 +421,7 @@ StringTrieBuilder::ValueNode::operator==(const Node &other) const {
if(!Node::operator==(other)) {
return false;
}
const ValueNode &o=(const ValueNode &)other;
const ValueNode &o=static_cast<const ValueNode &>(other);
return hasValue==o.hasValue && (!hasValue || value==o.value);
}
@ -433,7 +433,7 @@ StringTrieBuilder::IntermediateValueNode::operator==(const Node &other) const {
if(!ValueNode::operator==(other)) {
return false;
}
const IntermediateValueNode &o=(const IntermediateValueNode &)other;
const IntermediateValueNode &o=static_cast<const IntermediateValueNode &>(other);
return next==o.next;
}
@ -459,7 +459,7 @@ StringTrieBuilder::LinearMatchNode::operator==(const Node &other) const {
if(!ValueNode::operator==(other)) {
return false;
}
const LinearMatchNode &o=(const LinearMatchNode &)other;
const LinearMatchNode &o=static_cast<const LinearMatchNode &>(other);
return length==o.length && next==o.next;
}
@ -479,7 +479,7 @@ StringTrieBuilder::ListBranchNode::operator==(const Node &other) const {
if(!Node::operator==(other)) {
return false;
}
const ListBranchNode &o=(const ListBranchNode &)other;
const ListBranchNode &o=static_cast<const ListBranchNode &>(other);
for(int32_t i=0; i<length; ++i) {
if(units[i]!=o.units[i] || values[i]!=o.values[i] || equal[i]!=o.equal[i]) {
return false;
@ -558,7 +558,7 @@ StringTrieBuilder::SplitBranchNode::operator==(const Node &other) const {
if(!Node::operator==(other)) {
return false;
}
const SplitBranchNode &o=(const SplitBranchNode &)other;
const SplitBranchNode &o=static_cast<const SplitBranchNode &>(other);
return unit==o.unit && lessThan==o.lessThan && greaterOrEqual==o.greaterOrEqual;
}
@ -592,7 +592,7 @@ StringTrieBuilder::BranchHeadNode::operator==(const Node &other) const {
if(!ValueNode::operator==(other)) {
return false;
}
const BranchHeadNode &o=(const BranchHeadNode &)other;
const BranchHeadNode &o=static_cast<const BranchHeadNode &>(other);
return length==o.length && next==o.next;
}

View file

@ -298,7 +298,7 @@ UCharsTrieBuilder::UCTLinearMatchNode::operator==(const Node &other) const {
if(!LinearMatchNode::operator==(other)) {
return false;
}
const UCTLinearMatchNode &o=(const UCTLinearMatchNode &)other;
const UCTLinearMatchNode &o=static_cast<const UCTLinearMatchNode &>(other);
return 0==u_memcmp(s, o.s, length);
}

View file

@ -75,7 +75,7 @@ UCharCharacterIterator::operator==(const ForwardCharacterIterator& that) const {
return false;
}
UCharCharacterIterator& realThat = (UCharCharacterIterator&)that;
const UCharCharacterIterator& realThat = static_cast<const UCharCharacterIterator&>(that);
return text == realThat.text
&& textLength == realThat.textLength

View file

@ -527,7 +527,7 @@ UnicodeString::copyFrom(const UnicodeString &src, UBool fastCopy) {
case kLongString:
// src uses a refCounted string buffer, use that buffer with refCount
// src is const, use a cast - we don't actually change it
((UnicodeString &)src).addRef();
const_cast<UnicodeString &>(src).addRef();
// copy all fields, share the reference-counted buffer
fUnion.fFields.fArray = src.fUnion.fFields.fArray;
fUnion.fFields.fCapacity = src.fUnion.fFields.fCapacity;

View file

@ -449,12 +449,13 @@ protected:
fprintf(stderr, "::create - not a LocaleKey!\n");
}
#endif
const LocaleKey& lkey = (LocaleKey&)key;
const LocaleKey* lkey = dynamic_cast<const LocaleKey*>(&key);
U_ASSERT(lkey != nullptr);
Locale curLoc; // current locale
Locale canLoc; // Canonical locale
lkey.currentLocale(curLoc);
lkey.canonicalLocale(canLoc);
lkey->currentLocale(curLoc);
lkey->canonicalLocale(canLoc);
char keyword[ULOC_FULLNAME_CAPACITY];
UnicodeString str;
@ -494,9 +495,10 @@ protected:
return nullptr;
}
LocaleKey &lkey = (LocaleKey&)key;
const LocaleKey *lkey = dynamic_cast<const LocaleKey*>(&key);
U_ASSERT(lkey != nullptr);
Locale loc;
lkey.currentLocale(loc);
lkey->currentLocale(loc);
UnicodeString *ret = new UnicodeString();
if (ret == nullptr) {
@ -541,7 +543,7 @@ public:
if (U_FAILURE(status)) {
return nullptr;
}
LocaleKey& lkey = (LocaleKey&)key;
LocaleKey& lkey = static_cast<LocaleKey&>(const_cast<ICUServiceKey&>(key));
//int32_t kind = lkey.kind();
Locale loc;

View file

@ -137,7 +137,7 @@ ChoiceFormat::operator==(const Format& that) const
{
if (this == &that) return true;
if (!NumberFormat::operator==(that)) return false;
ChoiceFormat& thatAlias = (ChoiceFormat&)that;
const ChoiceFormat& thatAlias = static_cast<const ChoiceFormat&>(that);
return msgPattern == thatAlias.msgPattern;
}

View file

@ -137,7 +137,7 @@ ICUCollatorFactory::~ICUCollatorFactory() {}
UObject*
ICUCollatorFactory::create(const ICUServiceKey& key, const ICUService* /* service */, UErrorCode& status) const {
if (handlesKey(key, status)) {
const LocaleKey& lkey = (const LocaleKey&)key;
const LocaleKey& lkey = static_cast<const LocaleKey&>(key);
Locale loc;
// make sure the requested locale is correct
// default LocaleFactory uses currentLocale since that's the one vetted by handlesKey
@ -167,7 +167,8 @@ public:
}
virtual UObject* handleDefault(const ICUServiceKey& key, UnicodeString* actualID, UErrorCode& status) const override {
LocaleKey& lkey = (LocaleKey&)key;
const LocaleKey* lkey = dynamic_cast<const LocaleKey*>(&key);
U_ASSERT(lkey != nullptr);
if (actualID) {
// Ugly Hack Alert! We return an empty actualID to signal
// to callers that this is a default object, not a "real"
@ -175,7 +176,7 @@ public:
actualID->truncate(0);
}
Locale loc("");
lkey.canonicalLocale(loc);
lkey->canonicalLocale(loc);
return Collator::makeInstance(loc, status);
}
@ -746,9 +747,10 @@ UObject*
CFactory::create(const ICUServiceKey& key, const ICUService* /* service */, UErrorCode& status) const
{
if (handlesKey(key, status)) {
const LocaleKey& lkey = (const LocaleKey&)key;
const LocaleKey* lkey = dynamic_cast<const LocaleKey*>(&key);
U_ASSERT(lkey != nullptr);
Locale validLoc;
lkey.currentLocale(validLoc);
lkey->currentLocale(validLoc);
return _delegate->createCollator(validLoc);
}
return nullptr;

View file

@ -44,7 +44,11 @@ CurrencyAmount* CurrencyAmount::clone() const {
CurrencyAmount::~CurrencyAmount() {
}
const CurrencyUnit& CurrencyAmount::getCurrency() const {
return static_cast<const CurrencyUnit&>(getUnit());
}
UOBJECT_DEFINE_RTTI_IMPLEMENTATION(CurrencyAmount)
U_NAMESPACE_END

View file

@ -394,11 +394,11 @@ MessageFormat::operator==(const Format& rhs) const
{
if (this == &rhs) return true;
MessageFormat& that = (MessageFormat&)rhs;
// Check class ID before checking MessageFormat members
if (!Format::operator==(rhs) ||
msgPattern != that.msgPattern ||
if (!Format::operator==(rhs)) return false;
const MessageFormat& that = static_cast<const MessageFormat&>(rhs);
if (msgPattern != that.msgPattern ||
fLocale != that.fLocale) {
return false;
}

View file

@ -887,14 +887,15 @@ public:
virtual UObject* create(const ICUServiceKey& key, const ICUService* service, UErrorCode& status) const override
{
if (handlesKey(key, status)) {
const LocaleKey& lkey = (const LocaleKey&)key;
const LocaleKey* lkey = dynamic_cast<const LocaleKey*>(&key);
U_ASSERT(lkey != nullptr);
Locale loc;
lkey.canonicalLocale(loc);
int32_t kind = lkey.kind();
lkey->canonicalLocale(loc);
int32_t kind = lkey->kind();
UObject* result = _delegate->createFormat(loc, (UNumberFormatStyle)kind);
if (result == nullptr) {
result = service->getKey((ICUServiceKey&)key /* cast away const */, nullptr, this, status);
result = service->getKey(const_cast<ICUServiceKey&>(key) /* cast away const */, nullptr, this, status);
}
return result;
}
@ -948,10 +949,11 @@ public:
}
virtual UObject* handleDefault(const ICUServiceKey& key, UnicodeString* /* actualID */, UErrorCode& status) const override {
LocaleKey& lkey = (LocaleKey&)key;
int32_t kind = lkey.kind();
const LocaleKey* lkey = dynamic_cast<const LocaleKey*>(&key);
U_ASSERT(lkey != nullptr);
int32_t kind = lkey->kind();
Locale loc;
lkey.currentLocale(loc);
lkey->currentLocale(loc);
return NumberFormat::makeInstance(loc, (UNumberFormatStyle)kind, status);
}

View file

@ -944,7 +944,7 @@ RuleBasedNumberFormat::operator==(const Format& other) const
}
if (typeid(*this) == typeid(other)) {
const RuleBasedNumberFormat& rhs = (const RuleBasedNumberFormat&)other;
const RuleBasedNumberFormat& rhs = static_cast<const RuleBasedNumberFormat&>(other);
// test for capitalization info equality is adequately handled
// by the NumberFormat test for fCapitalizationContext equality;
// the info here is just derived from that.

View file

@ -526,7 +526,7 @@ RuleBasedTimeZone::hasSameRules(const TimeZone& other) const {
if (typeid(*this) != typeid(other)) {
return false;
}
const RuleBasedTimeZone& that = (const RuleBasedTimeZone&)other;
const RuleBasedTimeZone& that = static_cast<const RuleBasedTimeZone&>(other);
if (*fInitialRule != *(that.fInitialRule)) {
return false;
}
@ -549,8 +549,8 @@ RuleBasedTimeZone::getNextTransition(UDate base, UBool inclusive, TimeZoneTransi
UBool found = findNext(base, inclusive, transitionTime, fromRule, toRule);
if (found) {
result.setTime(transitionTime);
result.setFrom((const TimeZoneRule&)*fromRule);
result.setTo((const TimeZoneRule&)*toRule);
result.setFrom(*fromRule);
result.setTo(*toRule);
return true;
}
return false;
@ -568,8 +568,8 @@ RuleBasedTimeZone::getPreviousTransition(UDate base, UBool inclusive, TimeZoneTr
UBool found = findPrev(base, inclusive, transitionTime, fromRule, toRule);
if (found) {
result.setTime(transitionTime);
result.setFrom((const TimeZoneRule&)*fromRule);
result.setTo((const TimeZoneRule&)*toRule);
result.setFrom(*fromRule);
result.setTo(*toRule);
return true;
}
return false;

View file

@ -172,7 +172,7 @@ SelectFormat::operator==(const Format& other) const {
if (!Format::operator==(other)) {
return false;
}
const SelectFormat& o = (const SelectFormat&)other;
const SelectFormat& o = static_cast<const SelectFormat&>(other);
return msgPattern == o.msgPattern;
}

View file

@ -991,14 +991,14 @@ SimpleTimeZone::getNextTransition(UDate base, UBool inclusive, TimeZoneTransitio
UBool dstAvail = dstRule->getNextStart(base, stdRule->getRawOffset(), stdRule->getDSTSavings(), inclusive, dstDate);
if (stdAvail && (!dstAvail || stdDate < dstDate)) {
result.setTime(stdDate);
result.setFrom((const TimeZoneRule&)*dstRule);
result.setTo((const TimeZoneRule&)*stdRule);
result.setFrom(*dstRule);
result.setTo(*stdRule);
return true;
}
if (dstAvail && (!stdAvail || dstDate < stdDate)) {
result.setTime(dstDate);
result.setFrom((const TimeZoneRule&)*stdRule);
result.setTo((const TimeZoneRule&)*dstRule);
result.setFrom(*stdRule);
result.setTo(*dstRule);
return true;
}
return false;
@ -1025,14 +1025,14 @@ SimpleTimeZone::getPreviousTransition(UDate base, UBool inclusive, TimeZoneTrans
UBool dstAvail = dstRule->getPreviousStart(base, stdRule->getRawOffset(), stdRule->getDSTSavings(), inclusive, dstDate);
if (stdAvail && (!dstAvail || stdDate > dstDate)) {
result.setTime(stdDate);
result.setFrom((const TimeZoneRule&)*dstRule);
result.setTo((const TimeZoneRule&)*stdRule);
result.setFrom(*dstRule);
result.setTo(*stdRule);
return true;
}
if (dstAvail && (!stdAvail || dstDate > stdDate)) {
result.setTime(dstDate);
result.setFrom((const TimeZoneRule&)*stdRule);
result.setTo((const TimeZoneRule&)*dstRule);
result.setFrom(*stdRule);
result.setTo(*dstRule);
return true;
}
return false;

View file

@ -211,9 +211,10 @@ bool StringSearch::operator==(const SearchIterator &that) const
return true;
}
if (SearchIterator::operator ==(that)) {
StringSearch &thatsrch = (StringSearch &)that;
return (this->m_pattern_ == thatsrch.m_pattern_ &&
this->m_strsrch_->collator == thatsrch.m_strsrch_->collator);
const StringSearch *thatsrch = dynamic_cast<const StringSearch *>(&that);
if (thatsrch == nullptr) return false;
return (this->m_pattern_ == thatsrch->m_pattern_ &&
this->m_strsrch_->collator == thatsrch->m_strsrch_->collator);
}
return false;
}

View file

@ -63,7 +63,7 @@ TimeUnitAmount::~TimeUnitAmount() {
const TimeUnit&
TimeUnitAmount::getTimeUnit() const {
return (const TimeUnit&) getUnit();
return static_cast<const TimeUnit&>(getUnit());
}

View file

@ -111,7 +111,7 @@ class U_I18N_API CurrencyAmount: public Measure {
* Return the currency unit object of this object.
* @stable ICU 3.0
*/
inline const CurrencyUnit& getCurrency() const;
const CurrencyUnit& getCurrency() const;
/**
* Return the ISO currency code of this object.
@ -120,10 +120,6 @@ class U_I18N_API CurrencyAmount: public Measure {
inline const char16_t* getISOCurrency() const;
};
inline const CurrencyUnit& CurrencyAmount::getCurrency() const {
return (const CurrencyUnit&) getUnit();
}
inline const char16_t* CurrencyAmount::getISOCurrency() const {
return getCurrency().getISOCurrency();
}

View file

@ -557,7 +557,7 @@ void AlphabeticIndexTest::TestIndexCharactersList() {
void AlphabeticIndexTest::TestHaniFirst() {
UErrorCode status = U_ZERO_ERROR;
LocalPointer<RuleBasedCollator> coll(
static_cast<RuleBasedCollator *>(Collator::createInstance(Locale::getRoot(), status)));
dynamic_cast<RuleBasedCollator *>(Collator::createInstance(Locale::getRoot(), status)));
if (U_FAILURE(status)) {
dataerrln("Failed Collator::createInstance call - %s", u_errorName(status));
@ -587,7 +587,7 @@ void AlphabeticIndexTest::TestHaniFirst() {
void AlphabeticIndexTest::TestPinyinFirst() {
UErrorCode status = U_ZERO_ERROR;
LocalPointer<RuleBasedCollator> coll(
static_cast<RuleBasedCollator *>(Collator::createInstance(Locale::getChinese(), status)));
dynamic_cast<RuleBasedCollator *>(Collator::createInstance(Locale::getChinese(), status)));
if (U_FAILURE(status)) {
dataerrln("Failed Collator::createInstance call - %s", u_errorName(status));
return;
@ -659,7 +659,7 @@ void AlphabeticIndexTest::TestSchSt() {
void AlphabeticIndexTest::TestNoLabels() {
UErrorCode status = U_ZERO_ERROR;
LocalPointer<RuleBasedCollator> coll(
static_cast<RuleBasedCollator *>(Collator::createInstance(Locale::getRoot(), status)));
dynamic_cast<RuleBasedCollator *>(Collator::createInstance(Locale::getRoot(), status)));
TEST_CHECK_STATUS;
AlphabeticIndex index(coll.orphan(), status);
TEST_CHECK_STATUS;

View file

@ -156,8 +156,8 @@ CollationAPITest::TestProperty(/* char* par */)
doAssert((name == UnicodeString("English (United States)")), "getDisplayName failed if this is an English machine");
#endif
delete col; col = 0;
RuleBasedCollator *rcol = (RuleBasedCollator *)Collator::createInstance("da_DK",
success);
RuleBasedCollator *rcol = dynamic_cast<RuleBasedCollator*>(Collator::createInstance("da_DK",
success));
if (U_FAILURE(success)) {
errcheckln(success, "Collator::createInstance(\"da_DK\") failed - %s", u_errorName(success));
return;
@ -201,7 +201,7 @@ CollationAPITest::TestProperty(/* char* par */)
return;
}
doAssert(((RuleBasedCollator *)junk)->getRules().isEmpty(),
doAssert((dynamic_cast<RuleBasedCollator*>(junk))->getRules().isEmpty(),
"The root collation should be returned for an unsupported language.");
Collator *frCol = Collator::createInstance(Locale::getCanadaFrench(), success);
if (U_FAILURE(success))
@ -278,7 +278,7 @@ CollationAPITest::TestRuleBasedColl()
status = U_ZERO_ERROR;
Locale locale("aa", "AA");
col3 = (RuleBasedCollator *)Collator::createInstance(locale, status);
col3 = dynamic_cast<RuleBasedCollator*>(Collator::createInstance(locale, status));
if (U_FAILURE(status)) {
errln("Fallback Collator creation failed.: %s\n");
return;
@ -289,7 +289,7 @@ CollationAPITest::TestRuleBasedColl()
delete col3;
status = U_ZERO_ERROR;
col3 = (RuleBasedCollator *)Collator::createInstance(status);
col3 = dynamic_cast<RuleBasedCollator*>(Collator::createInstance(status));
if (U_FAILURE(status)) {
errln("Default Collator creation failed.: %s\n");
return;
@ -338,7 +338,7 @@ CollationAPITest::TestRules()
UErrorCode status = U_ZERO_ERROR;
UnicodeString rules;
coll = (RuleBasedCollator *)Collator::createInstance(Locale::getEnglish(), status);
coll = dynamic_cast<RuleBasedCollator*>(Collator::createInstance(Locale::getEnglish(), status));
if (U_FAILURE(status)) {
errcheckln(status, "English Collator creation failed. - %s", u_errorName(status));
return;
@ -646,14 +646,14 @@ CollationAPITest::TestElemIter(/* char* par */)
UnicodeString testString1("XFILE What subset of all possible test cases has the highest probability of detecting the most errors?");
UnicodeString testString2("Xf_ile What subset of all possible test cases has the lowest probability of detecting the least errors?");
logln("Constructors and comparison testing....");
CollationElementIterator *iterator1 = ((RuleBasedCollator*)col)->createCollationElementIterator(testString1);
CollationElementIterator *iterator1 = (dynamic_cast<RuleBasedCollator*>(col))->createCollationElementIterator(testString1);
CharacterIterator *chariter=new StringCharacterIterator(testString1);
CollationElementIterator *coliter=((RuleBasedCollator*)col)->createCollationElementIterator(*chariter);
CollationElementIterator *coliter = (dynamic_cast<RuleBasedCollator*>(col))->createCollationElementIterator(*chariter);
// copy ctor
CollationElementIterator *iterator2 = ((RuleBasedCollator*)col)->createCollationElementIterator(testString1);
CollationElementIterator *iterator3 = ((RuleBasedCollator*)col)->createCollationElementIterator(testString2);
CollationElementIterator *iterator2 = (dynamic_cast<RuleBasedCollator*>(col))->createCollationElementIterator(testString1);
CollationElementIterator *iterator3 = (dynamic_cast<RuleBasedCollator*>(col))->createCollationElementIterator(testString2);
int32_t offset = iterator1->getOffset();
if (offset != 0) {
@ -861,13 +861,13 @@ CollationAPITest::TestOperators(/* char* par */)
doAssert((*col3 == *col5), "Cloned collation objects not equal");
doAssert((*col4 != *col5), "Two cloned collations compared equal");
const UnicodeString& defRules = ((RuleBasedCollator*)col3)->getRules();
const UnicodeString& defRules = (dynamic_cast<RuleBasedCollator*>(col3))->getRules();
RuleBasedCollator* col6 = new RuleBasedCollator(defRules, success);
if (U_FAILURE(success)) {
errln("Creating default collation with rules failed.");
return;
}
doAssert((((RuleBasedCollator*)col3)->getRules() == col6->getRules()), "Default collator getRules failed");
doAssert(((dynamic_cast<RuleBasedCollator*>(col3))->getRules() == col6->getRules()), "Default collator getRules failed");
success = U_ZERO_ERROR;
RuleBasedCollator *col7 = new RuleBasedCollator(ruleset2, Collator::TERTIARY, success);
@ -922,13 +922,13 @@ CollationAPITest::TestDuplicate(/* char* par */)
return;
}
doAssert((*col1 != *col3), "Cloned object is equal to some dummy");
*col3 = *((RuleBasedCollator*)col1);
*col3 = *(dynamic_cast<RuleBasedCollator*>(col1));
doAssert((*col1 == *col3), "Copied object is not equal to the original");
UCollationResult res;
UnicodeString first((char16_t)0x0061);
UnicodeString second((char16_t)0x0062);
UnicodeString copiedEnglishRules(((RuleBasedCollator*)col1)->getRules());
UnicodeString copiedEnglishRules((dynamic_cast<RuleBasedCollator*>(col1))->getRules());
delete col1;
@ -937,9 +937,9 @@ CollationAPITest::TestDuplicate(/* char* par */)
if(res != UCOL_LESS) {
errln("a should be less then b after tailoring");
}
if (((RuleBasedCollator*)col2)->getRules() != copiedEnglishRules) {
if ((dynamic_cast<RuleBasedCollator*>(col2))->getRules() != copiedEnglishRules) {
errln(UnicodeString("English rule difference. ")
+ copiedEnglishRules + UnicodeString("\ngetRules=") + ((RuleBasedCollator*)col2)->getRules());
+ copiedEnglishRules + UnicodeString("\ngetRules=") + (dynamic_cast<RuleBasedCollator*>(col2))->getRules());
}
res = col3->compare(first, second, status);
if(res != UCOL_LESS) {
@ -1963,7 +1963,7 @@ void CollationAPITest::TestUClassID()
}
UErrorCode status = U_ZERO_ERROR;
RuleBasedCollator *coll
= (RuleBasedCollator *)Collator::createInstance(status);
= dynamic_cast<RuleBasedCollator*>(Collator::createInstance(status));
if(U_FAILURE(status)) {
delete coll;
errcheckln(status, "Collator creation failed with %s", u_errorName(status));
@ -2322,7 +2322,7 @@ void CollationAPITest::TestNullptrCharTailoring()
void CollationAPITest::TestClone() {
logln("\ninit c0");
UErrorCode status = U_ZERO_ERROR;
RuleBasedCollator* c0 = (RuleBasedCollator*)Collator::createInstance(status);
RuleBasedCollator* c0 = dynamic_cast<RuleBasedCollator*>(Collator::createInstance(status));
if (U_FAILURE(status)) {
errcheckln(status, "Collator::CreateInstance(status) failed with %s", u_errorName(status));
@ -2333,7 +2333,7 @@ void CollationAPITest::TestClone() {
dump("c0", c0, status);
logln("\ninit c1");
RuleBasedCollator* c1 = (RuleBasedCollator*)Collator::createInstance(status);
RuleBasedCollator* c1 = dynamic_cast<RuleBasedCollator*>(Collator::createInstance(status));
c1->setStrength(Collator::TERTIARY);
UColAttributeValue val = c1->getAttribute(UCOL_CASE_FIRST, status);
if(val == UCOL_LOWER_FIRST){

View file

@ -109,7 +109,7 @@ CalendarLimitTest::TestCalendarExtremeLimit()
return;
}
fmt->adoptCalendar(cal);
((SimpleDateFormat*) fmt)->applyPattern("HH:mm:ss.SSS Z, EEEE, MMMM d, yyyy G");
(dynamic_cast<SimpleDateFormat*>(fmt))->applyPattern("HH:mm:ss.SSS Z, EEEE, MMMM d, yyyy G");
// This test used to test the algorithmic limits of the dates that

View file

@ -144,7 +144,7 @@ void
CalendarRegressionTest::test4100311()
{
UErrorCode status = U_ZERO_ERROR;
GregorianCalendar *cal = (GregorianCalendar*)Calendar::createInstance(status);
GregorianCalendar *cal = dynamic_cast<GregorianCalendar*>(Calendar::createInstance(status));
if(U_FAILURE(status)) {
dataerrln("Error creating Calendar: %s", u_errorName(status));
delete cal;
@ -620,7 +620,7 @@ void CalendarRegressionTest::dowTest(UBool lenient)
if(cal->getActualMinimum(Calendar::DAY_OF_WEEK) != min) {
errln("FAIL: actual minimum (Calendar::DAY_OF_WEEK) differs from minimum");
}
if(((Calendar*)cal)->getActualMinimum(UCAL_DAY_OF_WEEK, status) != min) {
if(cal->getActualMinimum(UCAL_DAY_OF_WEEK, status) != min) {
errln("FAIL: actual minimum (UCAL_DAY_OF_WEEK, status) differs from minimum");
}
// NOTE: This function does not exist! jitterbug #3016
@ -971,7 +971,7 @@ void CalendarRegressionTest::test4096539()
void CalendarRegressionTest::test41003112()
{
UErrorCode status = U_ZERO_ERROR;
GregorianCalendar *cal = (GregorianCalendar*)Calendar::createInstance(status);
GregorianCalendar *cal = dynamic_cast<GregorianCalendar*>(Calendar::createInstance(status));
if(U_FAILURE(status)) {
dataerrln("Error creating calendar: %s", u_errorName(status));
delete cal;
@ -995,7 +995,7 @@ void CalendarRegressionTest::test4103271()
SimpleDateFormat sdf(status);
int32_t numYears=40, startYear=1997, numDays=15;
UnicodeString output, testDesc, str, str2;
GregorianCalendar *testCal = (GregorianCalendar*)Calendar::createInstance(status);
GregorianCalendar *testCal = dynamic_cast<GregorianCalendar*>(Calendar::createInstance(status));
if(U_FAILURE(status)) {
dataerrln("Error creating calendar: %s", u_errorName(status));
delete testCal;
@ -1459,7 +1459,7 @@ void CalendarRegressionTest::test4118384()
void CalendarRegressionTest::test4125881()
{
UErrorCode status = U_ZERO_ERROR;
LocalPointer<GregorianCalendar> cal((GregorianCalendar*) Calendar::createInstance(status), status);
LocalPointer<GregorianCalendar> cal(dynamic_cast<GregorianCalendar*>(Calendar::createInstance(status)), status);
if(U_FAILURE(status)) {
dataerrln("Error creating calendar %s", u_errorName(status));
return;
@ -1488,7 +1488,7 @@ void CalendarRegressionTest::test4125881()
*/
void CalendarRegressionTest::test4125892() {
UErrorCode status = U_ZERO_ERROR;
LocalPointer<GregorianCalendar> cal((GregorianCalendar*) Calendar::createInstance(status), status);
LocalPointer<GregorianCalendar> cal(dynamic_cast<GregorianCalendar*>(Calendar::createInstance(status)), status);
if(U_FAILURE(status)) {
dataerrln("Error creating calendar %s", u_errorName(status));
return;
@ -2042,7 +2042,7 @@ void CalendarRegressionTest::Test4197699() {
int32_t DATA_length = UPRV_LENGTHOF(DATA);
UnicodeString str;
DateFormat& dfmt = *(DateFormat*)&fmt;
DateFormat& dfmt = *dynamic_cast<DateFormat*>(&fmt);
for (int32_t i=0; i<DATA_length; ) {
cal.clear();
cal.set(DATA[i], DATA[i+1], DATA[i+2]);
@ -2871,7 +2871,7 @@ void CalendarRegressionTest::TestDeprecates(void)
void CalendarRegressionTest::TestT8057(void) {
// Set the calendar to the last day in a leap year
UErrorCode status = U_ZERO_ERROR;
GregorianCalendar *cal = (GregorianCalendar*)Calendar::createInstance(status);
GregorianCalendar *cal = dynamic_cast<GregorianCalendar*>(Calendar::createInstance(status));
if(U_FAILURE(status)) {
errln("Error creating Calendar: %s", u_errorName(status));
delete cal;
@ -3203,7 +3203,7 @@ void CalendarRegressionTest::VerifyNoAssertWithSetGregorianChange(const char* ti
if (cal->getDynamicClassID() ==
GregorianCalendar::getStaticClassID()) {
GregorianCalendar* gc =
static_cast<GregorianCalendar*>(cal.get());
dynamic_cast<GregorianCalendar*>(cal.get());
// The beginning of ECMAScript time, namely -(2**53)
const double start_of_time = -9007199254740992;
gc->setGregorianChange(start_of_time, status);

View file

@ -447,8 +447,8 @@ CalendarTest::TestGenericAPI()
if (failure(status, "Calendar::createInstance #6")) {
return;
}else {
((Calendar *)cal)->roll(UCAL_HOUR, (int32_t)100, status);
((Calendar *)cal)->clear(UCAL_HOUR);
cal->roll(UCAL_HOUR, (int32_t)100, status);
cal->clear(UCAL_HOUR);
#if !UCONFIG_NO_SERVICE
URegistryKey key = cal->registerFactory(nullptr, status);
cal->unregister(key, status);
@ -3428,10 +3428,10 @@ void CalendarTest::TestIslamicUmAlQura() {
Locale umalquraLoc("ar_SA@calendar=islamic-umalqura");
Locale gregoLoc("ar_SA@calendar=gregorian");
TimeZone* tzSA = TimeZone::createTimeZone(UnicodeString(true, zoneSA, -1));
Calendar* tstCal = Calendar::createInstance(*((const TimeZone *)tzSA), umalquraLoc, status);
Calendar* gregCal = Calendar::createInstance(*((const TimeZone *)tzSA), gregoLoc, status);
Calendar* tstCal = Calendar::createInstance(*tzSA, umalquraLoc, status);
Calendar* gregCal = Calendar::createInstance(*tzSA, gregoLoc, status);
IslamicCalendar* iCal = (IslamicCalendar*)tstCal;
IslamicCalendar* iCal = dynamic_cast<IslamicCalendar*>(tstCal);
if(uprv_strcmp(iCal->getType(), "islamic-umalqura") != 0) {
errln("wrong type of calendar created - %s", iCal->getType());
}

View file

@ -248,8 +248,8 @@ UnicodeString CanonicalIteratorTest::getReadable(const UnicodeString &s) {
U_CFUNC int U_CALLCONV
compareUnicodeStrings(const void *s1, const void *s2) {
UnicodeString **st1 = (UnicodeString **)s1;
UnicodeString **st2 = (UnicodeString **)s2;
UnicodeString **st1 = static_cast<UnicodeString **>(const_cast<void*>(s1));
UnicodeString **st2 = static_cast<UnicodeString **>(const_cast<void*>(s2));
return (*st1)->compare(**st2);
}
@ -270,7 +270,7 @@ UnicodeString CanonicalIteratorTest::collectionToString(Hashtable *col) {
//while (it.hasNext())
while (ne != nullptr) {
//String item = (String) it.next();
UnicodeString *item = (UnicodeString *)(ne->value.pointer);
UnicodeString *item = static_cast<UnicodeString *>(ne->value.pointer);
resArray[i++] = item;
ne = col->nextElement(el);
}

View file

@ -241,7 +241,7 @@ void CharIterTest::TestConstructionAndEquality() {
if (*test1 != *test2 || *test1 == *test5)
errln("setIndex() failed");
*((StringCharacterIterator*)test1) = *((StringCharacterIterator*)test3);
*(test1) = *(dynamic_cast<StringCharacterIterator*>(test3));
if (*test1 != *test3 || *test1 == *test5)
errln("operator= failed");

View file

@ -238,7 +238,7 @@ U_CDECL_BEGIN
static void U_CALLCONV
deleteStringList(void *obj)
{
StringList *strings = (StringList *) obj;
StringList *strings = static_cast<StringList *>(obj);
delete strings;
}
@ -301,7 +301,7 @@ void CEToStringsMap::put(uint32_t ce, UnicodeString *string, UErrorCode &status)
StringList *CEToStringsMap::getStringList(uint32_t ce) const
{
return (StringList *) uhash_iget(map, ce);
return static_cast<StringList *>(uhash_iget(map, ce));
}
void CEToStringsMap::putStringList(uint32_t ce, StringList *stringList, UErrorCode &status)

View file

@ -494,7 +494,7 @@ void CompactDecimalFormatTest::TestBug12975() {
if (assertSuccess("", status, true, __FILE__, __LINE__)) {
UnicodeString resultCdf;
cdf->format(12000, resultCdf);
LocalPointer<DecimalFormat> df((DecimalFormat*) DecimalFormat::createInstance(locale, status));
LocalPointer<DecimalFormat> df(dynamic_cast<DecimalFormat*>(DecimalFormat::createInstance(locale, status)));
UnicodeString resultDefault;
df->format(12000, resultDefault);
assertEquals("CompactDecimalFormat should use default pattern when compact pattern is unavailable",

View file

@ -482,7 +482,7 @@ getUnicodeSetCallback(const void *context,
UConverterCallbackReason reason,
UErrorCode *pErrorCode) {
if(reason<=UCNV_IRREGULAR) {
((UnicodeSet *)context)->remove(codePoint); // the converter cannot convert this code point
static_cast<UnicodeSet *>(const_cast<void*>(context))->remove(codePoint); // the converter cannot convert this code point
*pErrorCode=U_ZERO_ERROR; // skip
} // else ignore the reset, close and clone calls.
}

View file

@ -194,7 +194,7 @@ void CompoundTransliteratorTest::TestGetCount(){
UParseError parseError;
CompoundTransliterator *ct1=new CompoundTransliterator("Halfwidth-Fullwidth;Fullwidth-Halfwidth", parseError, status);
CompoundTransliterator *ct2=new CompoundTransliterator("Any-Hex;Hex-Any;Cyrillic-Latin;Latin-Cyrillic", parseError, status);
CompoundTransliterator *ct3=(CompoundTransliterator*)ct1;
CompoundTransliterator *ct3=ct1;
if (U_FAILURE(status)) {
dataerrln("FAILED: CompoundTransliterator constructor failed - %s", u_errorName(status));
return;
@ -297,7 +297,7 @@ void CompoundTransliteratorTest::TestGetSetAdoptTransliterator(){
}*/
logln("Testing adoptTransliterator() API of CompoundTransliterator");
UnicodeString ID3("Latin-Katakana");
Transliterator **transarray2=(Transliterator **)uprv_malloc(sizeof(Transliterator*)*1);
Transliterator **transarray2=static_cast<Transliterator **>(uprv_malloc(sizeof(Transliterator*)*1));
transarray2[0] = Transliterator::createInstance(ID3,UTRANS_FORWARD,parseError,status);
if (transarray2[0] != 0) {
ct1->adoptTransliterators(transarray2, 1);

View file

@ -82,7 +82,7 @@ void CollationCurrencyTest::currencyTest(/*char *par*/)
uint32_t i, j;
UErrorCode status = U_ZERO_ERROR;
Collator::EComparisonResult expectedResult = Collator::EQUAL;
RuleBasedCollator *c = (RuleBasedCollator *)Collator::createInstance("en_US", status);
RuleBasedCollator *c = dynamic_cast<RuleBasedCollator*>(Collator::createInstance("en_US", status));
if (U_FAILURE(status))
{

View file

@ -80,7 +80,7 @@ void DateFormatRegressionTest::Test4029195(void)
UDate today = Calendar::getNow();
logln((UnicodeString) "today: " + today);
SimpleDateFormat *sdf = (SimpleDateFormat*) DateFormat::createDateInstance();
SimpleDateFormat *sdf = dynamic_cast<SimpleDateFormat*>(DateFormat::createDateInstance());
if (failure(status, "SimpleDateFormat::createDateInstance")) {
return;
}
@ -518,8 +518,8 @@ void DateFormatRegressionTest::Test4071441(void)
}
// {sfb} Is it OK to cast away const here?
Calendar *calA = (Calendar*) fmtA->getCalendar();
Calendar *calB = (Calendar*) fmtB->getCalendar();
Calendar *calA = const_cast<Calendar*>(fmtA->getCalendar());
Calendar *calB = const_cast<Calendar*>(fmtB->getCalendar());
if(!calA || !calB) {
errln("Couldn't get proper calendars, exiting");
delete fmtA;
@ -1140,7 +1140,7 @@ void DateFormatRegressionTest::Test4182066(void) {
actStr.append("null");
} else {
// Yuck: See j25
((DateFormat*)&dispFmt)->format(actual, actStr);
(dynamic_cast<DateFormat*>(&dispFmt))->format(actual, actStr);
}
if (expected == actual) {
@ -1151,7 +1151,7 @@ void DateFormatRegressionTest::Test4182066(void) {
expStr.append("null");
} else {
// Yuck: See j25
((DateFormat*)&dispFmt)->format(expected, expStr);
(dynamic_cast<DateFormat*>(&dispFmt))->format(expected, expStr);
}
out.append("FAIL: " + str + " => " + actStr
+ ", expected " + expStr + "\n");
@ -1175,13 +1175,13 @@ DateFormatRegressionTest::Test4210209(void) {
UnicodeString pattern("MMM d, yyyy");
SimpleDateFormat sfmt(pattern, Locale::getUS(), status);
SimpleDateFormat sdisp("MMM dd yyyy GG", Locale::getUS(), status);
DateFormat& fmt = *(DateFormat*)&sfmt; // Yuck: See j25
DateFormat& disp = *(DateFormat*)&sdisp; // Yuck: See j25
DateFormat& fmt = *dynamic_cast<DateFormat*>(&sfmt); // Yuck: See j25
DateFormat& disp = *dynamic_cast<DateFormat*>(&sdisp); // Yuck: See j25
if (U_FAILURE(status)) {
dataerrln("Couldn't create SimpleDateFormat - %s", u_errorName(status));
return;
}
Calendar* calx = (Calendar*)fmt.getCalendar(); // cast away const!
Calendar* calx = const_cast<Calendar*>(fmt.getCalendar()); // cast away const!
calx->setLenient(false);
UDate d = date(2000-1900, UCAL_FEBRUARY, 29);
UnicodeString s, ss;

View file

@ -297,7 +297,7 @@ void DateFormatRoundTripTest::test(DateFormat *fmt, const Locale &origLocale, UB
}
//logln(UnicodeString("Min date is ") + fullFormat(minDate) + " for " + origLocale.getName());
pat = ((SimpleDateFormat*)fmt)->toPattern(pat);
pat = dynamic_cast<SimpleDateFormat*>(fmt)->toPattern(pat);
// NOTE TO MAINTAINER
// This indexOf check into the pattern needs to be refined to ignore

View file

@ -715,7 +715,7 @@ DateFormatTest::tryPat994(SimpleDateFormat* format, const char* pat, const char*
else
{
UnicodeString f;
((DateFormat*)format)->format(date, f);
(dynamic_cast<DateFormat*>(format))->format(date, f);
logln(UnicodeString(" parse(") + str + ") -> " + dateToString(date));
logln((UnicodeString)" format -> " + f);
if (expected == null ||
@ -753,12 +753,12 @@ DateFormatTest::TestRunTogetherPattern985()
return;
}
UDate date1 = Calendar::getNow();
((DateFormat*)formatter)->format(date1, now);
(dynamic_cast<DateFormat*>(formatter))->format(date1, now);
logln(now);
ParsePosition pos(0);
UDate date2 = formatter->parse(now, pos);
if (date2 == 0) then = UnicodeString("Parse stopped at ") + pos.getIndex();
else ((DateFormat*)formatter)->format(date2, then);
else (dynamic_cast<DateFormat*>(formatter))->format(date2, then);
logln(then);
if (!(date2 == date1)) errln((UnicodeString)"FAIL");
delete formatter;
@ -803,7 +803,7 @@ DateFormatTest::testIt917(SimpleDateFormat* fmt, UnicodeString& str, UDate expec
logln((UnicodeString)"pattern=" + fmt->toPattern(pattern) + " string=" + str);
Formattable o;
//try {
((Format*)fmt)->parseObject(str, o, status);
dynamic_cast<Format*>(fmt)->parseObject(str, o, status);
//}
if (U_FAILURE(status)) return;
//catch(ParseException e) {
@ -812,7 +812,8 @@ DateFormatTest::testIt917(SimpleDateFormat* fmt, UnicodeString& str, UDate expec
//}
logln((UnicodeString)"Parsed object: " + dateToString(o.getDate()));
if (!(o.getDate() == expected)) errln((UnicodeString)"FAIL: Expected " + dateToString(expected));
UnicodeString formatted; ((Format*)fmt)->format(o, formatted, status);
UnicodeString formatted;
fmt->format(o, formatted, status);
logln((UnicodeString)"Formatted string: " + formatted);
if (!(formatted == str)) errln((UnicodeString)"FAIL: Expected " + str);
if (U_FAILURE(status)) errln((UnicodeString)"FAIL: UErrorCode received during test: " + (int32_t)status);
@ -835,7 +836,7 @@ DateFormatTest::TestCzechMonths459()
}
UnicodeString pattern;
logln((UnicodeString)"Pattern " + ((SimpleDateFormat*) fmt)->toPattern(pattern));
logln((UnicodeString)"Pattern " + (dynamic_cast<SimpleDateFormat*>(fmt))->toPattern(pattern));
UDate june = date(97, UCAL_JUNE, 15);
UDate july = date(97, UCAL_JULY, 15);
UnicodeString juneStr; fmt->format(june, juneStr);
@ -911,7 +912,7 @@ DateFormatTest::TestDayOfYearPattern195()
int32_t year,month,day,hour,min,sec; dateToFields(today,year,month,day,hour,min,sec);
UDate expected = date(year, month, day);
logln((UnicodeString)"Test Date: " + dateToString(today));
SimpleDateFormat* sdf = (SimpleDateFormat*)DateFormat::createDateInstance();
SimpleDateFormat* sdf = dynamic_cast<SimpleDateFormat*>(DateFormat::createDateInstance());
if (sdf == nullptr){
dataerrln("Error calling DateFormat::createDateInstance()");
return;
@ -931,13 +932,13 @@ DateFormatTest::tryPattern(SimpleDateFormat& sdf, UDate d, const char* pattern,
if (pattern != 0) sdf.applyPattern(pattern);
UnicodeString thePat;
logln((UnicodeString)"pattern: " + sdf.toPattern(thePat));
UnicodeString formatResult; (*(DateFormat*)&sdf).format(d, formatResult);
UnicodeString formatResult; (*dynamic_cast<DateFormat*>(&sdf)).format(d, formatResult);
logln((UnicodeString)" format -> " + formatResult);
// try {
UDate d2 = sdf.parse(formatResult, status);
logln((UnicodeString)" parse(" + formatResult + ") -> " + dateToString(d2));
if (d2 != expected) errln((UnicodeString)"FAIL: Expected " + dateToString(expected));
UnicodeString format2; (*(DateFormat*)&sdf).format(d2, format2);
UnicodeString format2; (*dynamic_cast<DateFormat*>(&sdf)).format(d2, format2);
logln((UnicodeString)" format -> " + format2);
if (!(formatResult == format2)) errln((UnicodeString)"FAIL: Round trip drift");
//}
@ -963,7 +964,7 @@ DateFormatTest::TestQuotePattern161()
return;
}
UDate currentTime_1 = date(97, UCAL_AUGUST, 13, 10, 42, 28);
UnicodeString dateString; ((DateFormat*)formatter)->format(currentTime_1, dateString);
UnicodeString dateString; (dynamic_cast<DateFormat*>(formatter))->format(currentTime_1, dateString);
UnicodeString exp("08/13/1997 at 10:42:28 AM ");
logln((UnicodeString)"format(" + dateToString(currentTime_1) + ") = " + dateString);
if (0 != dateString.compareBetween(0, exp.length(), exp, 0, exp.length())) errln((UnicodeString)"FAIL: Expected " + exp);
@ -1145,7 +1146,7 @@ DateFormatTest::TestBadInput135a()
}
else {
UnicodeString result;
((DateFormat*)dateParse)->format(date, result);
(dynamic_cast<DateFormat*>(dateParse))->format(date, result);
logln((UnicodeString)"Parsed \"" + s + "\" using \"" + dateParse->toPattern(thePat) + "\" to: " + result);
if (expected == 0)
errln((UnicodeString)"FAIL: Expected parse failure, got " + result);
@ -1196,7 +1197,7 @@ DateFormatTest::parse2DigitYear(DateFormat& fmt, const char* str, UDate expected
//try {
UDate d = fmt.parse(str, status);
UnicodeString thePat;
logln(UnicodeString("Parsing \"") + str + "\" with " + ((SimpleDateFormat*)&fmt)->toPattern(thePat) +
logln(UnicodeString("Parsing \"") + str + "\" with " + (dynamic_cast<SimpleDateFormat*>(&fmt))->toPattern(thePat) +
" => " + dateToString(d));
if (d != expected) errln((UnicodeString)"FAIL: Expected " + expected);
//}
@ -4475,7 +4476,7 @@ void DateFormatTest::TestFormatsWithNumberSystems()
dataerrln("Calendar::setTime fails for locale %s, date %.1f, status %s", itemPtr->localeID, date, u_errorName(status));
continue;
}
LocalPointer<SimpleDateFormat> sdfmt(static_cast<SimpleDateFormat *>(DateFormat::createDateInstance(itemPtr->style, locale)));
LocalPointer<SimpleDateFormat> sdfmt(dynamic_cast<SimpleDateFormat *>(DateFormat::createDateInstance(itemPtr->style, locale)));
if (sdfmt.isNull()) {
dataerrln("DateFormat::createDateInstance fails for locale %s", itemPtr->localeID);
continue;
@ -4558,7 +4559,7 @@ UBool DateFormatTest::showParse(DateFormat &format, const UnicodeString &formatt
UDate parsed = format.parse(formattedString, parsePosition);
UBool ok = TEST_DATE == parsed && parsePosition.getIndex() == formattedString.length();
UnicodeString pattern;
static_cast<SimpleDateFormat &>(format).toPattern(pattern);
dynamic_cast<SimpleDateFormat &>(format).toPattern(pattern);
if (ok) {
logln(pattern + " parsed: " + formattedString);
} else {
@ -4705,7 +4706,7 @@ void DateFormatTest::TestParseMultiPatternMatch() {
for (itemPtr = items; itemPtr->parseString != "--end--"; itemPtr++ ) {
status = U_ZERO_ERROR;
ParsePosition pos(0);
((SimpleDateFormat*) sdmft)->applyPattern(itemPtr->pattern);
(dynamic_cast<SimpleDateFormat*>(sdmft))->applyPattern(itemPtr->pattern);
if (U_FAILURE(status)) {
dataerrln("Unable to create SimpleDateFormat - %s", u_errorName(status));
continue;
@ -5053,7 +5054,7 @@ void DateFormatTest::TestPatternFromSkeleton() {
return;
}
UnicodeString pattern;
static_cast<const SimpleDateFormat*>(fmt.getAlias())->toPattern(pattern);
dynamic_cast<const SimpleDateFormat*>(fmt.getAlias())->toPattern(pattern);
assertEquals("Format pattern", TESTDATA[i].pattern, pattern);
}
}

View file

@ -327,7 +327,7 @@ void DateIntervalFormatTest::testAPI() {
Formattable fmttable;
status = U_ZERO_ERROR;
// TODO: why do I need cast?
((Format*)dtitvfmt)->parseObject(res, fmttable, status);
(dynamic_cast<Format*>(dtitvfmt))->parseObject(res, fmttable, status);
if ( status != U_INVALID_FORMAT_ERROR ) {
dataerrln("ERROR: parse should set U_INVALID_FORMAT_ERROR - exiting");
return;
@ -1775,7 +1775,7 @@ void DateIntervalFormatTest::testTicket11985() {
return;
}
UnicodeString pattern;
static_cast<const SimpleDateFormat*>(fmt->getDateFormat())->toPattern(pattern);
dynamic_cast<const SimpleDateFormat*>(fmt->getDateFormat())->toPattern(pattern);
assertEquals("Format pattern", u"h:mm\u202Fa", pattern);
}

View file

@ -539,8 +539,8 @@ void IntlTestDateTimePatternGeneratorAPI::testAPI(/*char *par*/)
delete format;
// get a pattern and modify it
format = (SimpleDateFormat *)DateFormat::createDateTimeInstance(DateFormat::kFull, DateFormat::kFull,
deLocale);
format = dynamic_cast<SimpleDateFormat*>(DateFormat::createDateTimeInstance(DateFormat::kFull, DateFormat::kFull,
deLocale));
format->setTimeZone(*zone);
UnicodeString pattern;
pattern = format->toPattern(pattern);
@ -751,8 +751,8 @@ void IntlTestDateTimePatternGeneratorAPI::testAPI(/*char *par*/)
delete patGen;
return;
}
SimpleDateFormat *enFormat = (SimpleDateFormat *)DateFormat::createDateTimeInstance(DateFormat::kFull,
DateFormat::kFull, Locale::getEnglish());
SimpleDateFormat *enFormat = dynamic_cast<SimpleDateFormat*>(DateFormat::createDateTimeInstance(DateFormat::kFull,
DateFormat::kFull, Locale::getEnglish()));
enFormat->setTimeZone(*enZone);
while (patternTests2[dataIndex].length() > 0) {
logln(patternTests2[dataIndex]);
@ -844,7 +844,7 @@ void IntlTestDateTimePatternGeneratorAPI::testAPI(/*char *par*/)
ptrSkeletonEnum->reset(status);
count=ptrSkeletonEnum->count(status);
for (i=0; i<count; ++i) {
ptrSkeleton = (UnicodeString *)ptrSkeletonEnum->snext(status);
ptrSkeleton = const_cast<UnicodeString *>(ptrSkeletonEnum->snext(status));
returnPattern = test->getPatternForSkeleton(*ptrSkeleton);
if ( returnPattern != testSkeletonsResults[i] ) {
errln(UnicodeString("ERROR: Unexpected result from getSkeletons and getPatternForSkeleton\nGot: ") + returnPattern
@ -858,7 +858,7 @@ void IntlTestDateTimePatternGeneratorAPI::testAPI(/*char *par*/)
}
count=ptrBaseSkeletonEnum->count(status);
for (i=0; i<count; ++i) {
ptrSkeleton = (UnicodeString *)ptrBaseSkeletonEnum->snext(status);
ptrSkeleton = const_cast<UnicodeString *>(ptrBaseSkeletonEnum->snext(status));
if ( *ptrSkeleton != testBaseSkeletonsResults[i] ) {
errln("ERROR: Unexpected result from getBaseSkeletons() !\n");
}

View file

@ -111,7 +111,7 @@ void G7CollationTest::TestG7Locales(/* char* par */)
continue;
}
const UnicodeString &rules = ((RuleBasedCollator*)myCollation.getAlias())->getRules();
const UnicodeString &rules = (dynamic_cast<RuleBasedCollator*>(myCollation.getAlias()))->getRules();
if (rules.isEmpty() &&
(locale == Locale::getCanadaFrench() || locale == Locale::getJapanese())) {
dataerrln("%s Collator missing rule string", locale.getName());
@ -156,7 +156,7 @@ void G7CollationTest::TestDemo1(/* char* par */)
errcheckln(status, "Couldn't instantiate collator. Error: %s", u_errorName(status));
return;
}
const UnicodeString baseRules = ((RuleBasedCollator*)col)->getRules();
const UnicodeString baseRules = (dynamic_cast<RuleBasedCollator*>(col))->getRules();
UnicodeString newRules(" & Z < p, P");
newRules.insert(0, baseRules);
RuleBasedCollator *myCollation = new RuleBasedCollator(newRules, status);
@ -190,7 +190,7 @@ void G7CollationTest::TestDemo2(/* char* par */)
errcheckln(status, "Couldn't instantiate collator. Error: %s", u_errorName(status));
return;
}
const UnicodeString baseRules = ((RuleBasedCollator*)col)->getRules();
const UnicodeString baseRules = (dynamic_cast<RuleBasedCollator*>(col))->getRules();
UnicodeString newRules("& C < ch , cH, Ch, CH");
newRules.insert(0, baseRules);
RuleBasedCollator *myCollation = new RuleBasedCollator(newRules, status);
@ -224,7 +224,7 @@ void G7CollationTest::TestDemo3(/* char* par */)
delete col;
return;
}
const UnicodeString baseRules = ((RuleBasedCollator*)col)->getRules();
const UnicodeString baseRules = (dynamic_cast<RuleBasedCollator*>(col))->getRules();
UnicodeString newRules = "& Question'-'mark ; '?' & Hash'-'mark ; '#' & Ampersand ; '&'";
newRules.insert(0, baseRules);
RuleBasedCollator *myCollation = new RuleBasedCollator(newRules, status);
@ -259,7 +259,7 @@ void G7CollationTest::TestDemo4(/* char* par */)
return;
}
const UnicodeString baseRules = ((RuleBasedCollator*)col)->getRules();
const UnicodeString baseRules = (dynamic_cast<RuleBasedCollator*>(col))->getRules();
UnicodeString newRules = " & aa ; a'-' & ee ; e'-' & ii ; i'-' & oo ; o'-' & uu ; u'-' ";
newRules.insert(0, baseRules);
RuleBasedCollator *myCollation = new RuleBasedCollator(newRules, status);

View file

@ -89,7 +89,7 @@ class Integer : public UObject {
virtual bool operator==(const UObject& other) const
{
return typeid(*this) == typeid(other) &&
_val == ((Integer&)other)._val;
_val == (dynamic_cast<Integer&>(const_cast<UObject&>(other)))._val;
}
public:
@ -127,7 +127,7 @@ class TestIntegerService : public ICUService {
}
virtual UObject* cloneInstance(UObject* instance) const override {
return instance ? new Integer(*(Integer*)instance) : nullptr;
return instance ? new Integer(*dynamic_cast<Integer*>(instance)) : nullptr;
}
};
@ -315,7 +315,7 @@ void
ICUServiceTest::msgstr(const UnicodeString& message, UObject* obj, UBool err)
{
if (obj) {
UnicodeString* str = (UnicodeString*)obj;
UnicodeString* str = dynamic_cast<UnicodeString*>(obj);
logln(message + *str);
delete str;
} else if (err) {
@ -337,7 +337,7 @@ ICUServiceTest::testAPI_One()
service.registerInstance(singleton0, "en_US", status);
{
UErrorCode status = U_ZERO_ERROR;
Integer* result = (Integer*)service.get("en_US_FOO", status);
Integer* result = dynamic_cast<Integer*>(service.get("en_US_FOO", status));
confirmEqual("1) en_US_FOO -> en_US", result, singleton0);
delete result;
}
@ -349,7 +349,7 @@ ICUServiceTest::testAPI_One()
service.registerInstance(singleton1, "en_US_FOO", status);
{
UErrorCode status = U_ZERO_ERROR;
Integer* result = (Integer*)service.get("en_US_FOO", status);
Integer* result = dynamic_cast<Integer*>(service.get("en_US_FOO", status));
confirmEqual("2) en_US_FOO -> en_US_FOO", result, singleton1);
delete result;
}
@ -357,7 +357,7 @@ ICUServiceTest::testAPI_One()
// search for an object that falls back to the first registered locale
{
UErrorCode status = U_ZERO_ERROR;
Integer* result = (Integer*)service.get("en_US_BAR", status);
Integer* result = dynamic_cast<Integer*>(service.get("en_US_BAR", status));
confirmEqual("3) en_US_BAR -> en_US", result, singleton0);
delete result;
}
@ -379,7 +379,7 @@ ICUServiceTest::testAPI_One()
// search for en_US should still find en_US object
{
UErrorCode status = U_ZERO_ERROR;
Integer* result = (Integer*)service.get("en_US_BAR", status);
Integer* result = dynamic_cast<Integer*>(service.get("en_US_BAR", status));
confirmEqual("6) en_US_BAR -> en_US", result, singleton0);
delete result;
}
@ -394,7 +394,7 @@ ICUServiceTest::testAPI_One()
// should get data from that new factory
{
UErrorCode status = U_ZERO_ERROR;
Integer* result = (Integer*)service.get("en_US_BAR", status);
Integer* result = dynamic_cast<Integer*>(service.get("en_US_BAR", status));
confirmEqual("10) en_US_BAR -> (3)", result, singleton3);
delete result;
}
@ -411,7 +411,7 @@ ICUServiceTest::testAPI_One()
// should get original data again after remove factory
{
UErrorCode status = U_ZERO_ERROR;
Integer* result = (Integer*)service.get("en_US_BAR", status);
Integer* result = dynamic_cast<Integer*>(service.get("en_US_BAR", status));
confirmEqual("12) en_US_BAR -> (3)", result, singleton0);
delete result;
}
@ -419,7 +419,7 @@ ICUServiceTest::testAPI_One()
// shouldn't find unregistered ids
{
UErrorCode status = U_ZERO_ERROR;
Integer* result = (Integer*)service.get("foo", status);
Integer* result = dynamic_cast<Integer*>(service.get("foo", status));
confirmIdentical("13) foo -> null", result, nullptr);
delete result;
}
@ -428,7 +428,7 @@ ICUServiceTest::testAPI_One()
{
UnicodeString resultID;
UErrorCode status = U_ZERO_ERROR;
Integer* result = (Integer*)service.get("EN_us_fOo", &resultID, status);
Integer* result = dynamic_cast<Integer*>(service.get("EN_us_fOo", &resultID, status));
confirmEqual("14a) find-non-canonical", result, singleton1);
confirmStringsEqual("14b) find non-canonical", resultID, "en_US_FOO");
delete result;
@ -440,7 +440,7 @@ ICUServiceTest::testAPI_One()
{
UnicodeString resultID;
UErrorCode status = U_ZERO_ERROR;
Integer* result = (Integer*)service.get("En_Ca_DuDe", &resultID, status);
Integer* result = dynamic_cast<Integer*>(service.get("En_Ca_DuDe", &resultID, status));
confirmEqual("15a) find-non-canonical", result, singleton4);
confirmStringsEqual("15b) register non-canonical", resultID, "en_CA_DUDE");
delete result;
@ -453,7 +453,7 @@ ICUServiceTest::testAPI_One()
service.registerInstance(singleton5, "en_US_BAR", false, status);
{
UErrorCode status = U_ZERO_ERROR;
Integer* result = (Integer*)service.get("en_US_BAR", status);
Integer* result = dynamic_cast<Integer*>(service.get("en_US_BAR", status));
confirmEqual("17) get invisible", result, singleton5);
delete result;
}
@ -491,7 +491,7 @@ public:
}
virtual UObject* cloneInstance(UObject* instance) const override {
return instance ? new UnicodeString(*(UnicodeString*)instance) : nullptr;
return instance ? new UnicodeString(*dynamic_cast<UnicodeString*>(instance)) : nullptr;
}
};
@ -511,7 +511,7 @@ class TestStringService : public ICUService {
}
virtual UObject* cloneInstance(UObject* instance) const override {
return instance ? new UnicodeString(*(UnicodeString*)instance) : nullptr;
return instance ? new UnicodeString(*dynamic_cast<UnicodeString*>(instance)) : nullptr;
}
};
@ -584,7 +584,7 @@ class TestMultipleKeyStringFactory : public ICUServiceFactory {
void updateVisibleIDs(Hashtable& result, UErrorCode& status) const override {
if (U_SUCCESS(_status)) {
for (int32_t i = 0; i < _ids.size(); ++i) {
result.put(*(UnicodeString*)_ids[i], (void*)this, status);
result.put(*static_cast<UnicodeString*>(_ids[i]), (void*)this, status);
}
}
}
@ -633,7 +633,7 @@ ICUServiceTest::testAPI_Two()
{
UErrorCode status = U_ZERO_ERROR;
const UnicodeString en_US = "en_US";
UnicodeString* result = (UnicodeString*)service.get(en_US, status);
UnicodeString* result = dynamic_cast<UnicodeString*>(service.get(en_US, status));
confirmEqual("21) locale", result, &en_US);
delete result;
}
@ -643,7 +643,7 @@ ICUServiceTest::testAPI_Two()
UErrorCode status = U_ZERO_ERROR;
const UnicodeString en_US_BAR = "en_US_BAR";
UnicodeString resultID;
UnicodeString* result = (UnicodeString*)service.get("EN_us_bar", &resultID, status);
UnicodeString* result = dynamic_cast<UnicodeString*>(service.get("EN_us_bar", &resultID, status));
confirmEqual("22) locale", &resultID, &en_US_BAR);
delete result;
}
@ -653,7 +653,7 @@ ICUServiceTest::testAPI_Two()
service.registerInstance(singleton0, "en_US_BAR", status);
{
UErrorCode status = U_ZERO_ERROR;
UnicodeString* result = (UnicodeString*)service.get("en_US_BAR", status);
UnicodeString* result = dynamic_cast<UnicodeString*>(service.get("en_US_BAR", status));
confirmEqual("23) override super", result, singleton0);
delete result;
}
@ -662,7 +662,7 @@ ICUServiceTest::testAPI_Two()
service.reset();
{
UErrorCode status = U_ZERO_ERROR;
UnicodeString* result = (UnicodeString*)service.get("en_US", status);
UnicodeString* result = dynamic_cast<UnicodeString*>(service.get("en_US", status));
confirmIdentical("24) empty", result, nullptr);
}
@ -686,8 +686,8 @@ ICUServiceTest::testAPI_Two()
UVector ids(uprv_deleteUObject, uhash_compareUnicodeString, 0, status);
service.getVisibleIDs(ids, status);
for (int i = 0; i < ids.size(); ++i) {
const UnicodeString* id = (const UnicodeString*)ids[i];
UnicodeString* result = (UnicodeString*)service.get(*id, status);
const UnicodeString* id = static_cast<const UnicodeString*>(const_cast<const void*>(ids[i]));
UnicodeString* result = dynamic_cast<UnicodeString*>(service.get(*id, status));
if (result) {
logln(" " + *id + " --> " + *result);
delete result;
@ -705,7 +705,7 @@ ICUServiceTest::testAPI_Two()
UVector names(status);
service.getDisplayNames(names, status);
for (int i = 0; i < names.size(); ++i) {
const StringPair* pair = (const StringPair*)names[i];
const StringPair* pair = static_cast<const StringPair*>(names[i]);
logln(" " + pair->displayName + " --> " + pair->id);
}
confirmIdentical("26) display names", names.size(), 4);
@ -745,7 +745,7 @@ ICUServiceTest::testAPI_Two()
UVector names(status);
service.getDisplayNames(names, Locale("es"), status);
for (int i = 0; i < names.size(); ++i) {
const StringPair* pair = (const StringPair*)names[i];
const StringPair* pair = static_cast<const StringPair*>(names[i]);
logln(" " + pair->displayName + " --> " + pair->id);
}
confirmIdentical("29) display names", names.size(), 7);
@ -757,7 +757,7 @@ ICUServiceTest::testAPI_Two()
UErrorCode status = U_ZERO_ERROR;
UnicodeString actualID;
UnicodeString id = "en_us_surfer_gal";
UnicodeString* gal = (UnicodeString*)service.get(id, &actualID, status);
UnicodeString* gal = dynamic_cast<UnicodeString*>(service.get(id, &actualID, status));
if (gal != nullptr) {
UnicodeString displayName;
logln("actual id: " + actualID);
@ -780,7 +780,7 @@ ICUServiceTest::testAPI_Two()
UErrorCode status = U_ZERO_ERROR;
UnicodeString actualID;
UnicodeString id = "en_US_SURFER_BOZO";
UnicodeString* bozo = (UnicodeString*)service.get(id, &actualID, status);
UnicodeString* bozo = dynamic_cast<UnicodeString*>(service.get(id, &actualID, status));
if (bozo != nullptr) {
UnicodeString displayName;
service.getDisplayName(actualID, displayName, Locale::getEnglish());
@ -807,7 +807,7 @@ ICUServiceTest::testAPI_Two()
UVector ids(uprv_deleteUObject, uhash_compareUnicodeString, 0, status);
service.getVisibleIDs(ids, status);
for (int i = 0; i < ids.size(); ++i) {
const UnicodeString* id = (const UnicodeString*)ids[i];
const UnicodeString* id = static_cast<const UnicodeString*>(const_cast<const void*>(ids[i]));
msgstr(*id + "? ", service.get(*id, status));
}
@ -904,7 +904,7 @@ ICUServiceTest::testRBF()
service.getVisibleIDs(ids, status);
logln("all visible ids:");
for (int i = 0; i < ids.size(); ++i) {
const UnicodeString* id = (const UnicodeString*)ids[i];
const UnicodeString* id = static_cast<const UnicodeString*>(const_cast<const void*>(ids[i]));
logln(*id);
}
}
@ -917,7 +917,7 @@ ICUServiceTest::testRBF()
service.getDisplayNames(names, Locale::getGermany(), status);
logln("service display names for de_DE");
for (int i = 0; i < names.size(); ++i) {
const StringPair* pair = (const StringPair*)names[i];
const StringPair* pair = static_cast<const StringPair*>(names[i]);
logln(" " + pair->displayName + " --> " + pair->id);
}
}
@ -942,7 +942,7 @@ ICUServiceTest::testRBF()
UVector names(status);
service.getDisplayNames(names, idNames[i], status);
for (int i = 0; i < names.size(); ++i) {
const StringPair* pair = (const StringPair*)names[i];
const StringPair* pair = static_cast<const StringPair*>(names[i]);
logln(" " + pair->displayName + " --> " + pair->id);
}
}
@ -986,7 +986,7 @@ ICUServiceTest::testNotification()
logln("registering bar... ");
ls.registerInstance(new UnicodeString("Bar"), "en_BAR", status);
logln("getting foo...");
UnicodeString* result = (UnicodeString*)ls.get("en_FOO", status);
UnicodeString* result = dynamic_cast<UnicodeString*>(ls.get("en_FOO", status));
logln(*result);
delete result;
@ -1031,7 +1031,7 @@ public void serviceChanged(ICUService s) {
class TestStringLocaleService : public ICULocaleService {
public:
virtual UObject* cloneInstance(UObject* instance) const override {
return instance ? new UnicodeString(*(UnicodeString*)instance) : nullptr;
return instance ? new UnicodeString(*dynamic_cast<UnicodeString*>(instance)) : nullptr;
}
};
@ -1053,21 +1053,21 @@ void ICUServiceTest::testLocale() {
{
UErrorCode status = U_ZERO_ERROR;
UnicodeString* target = (UnicodeString*)service.get("de_US", status);
UnicodeString* target = dynamic_cast<UnicodeString*>(service.get("de_US", status));
confirmEqual("test de_US", german, target);
delete target;
}
{
UErrorCode status = U_ZERO_ERROR;
UnicodeString* target = (UnicodeString*)service.get("de_US", LocaleKey::KIND_ANY, status);
UnicodeString* target = dynamic_cast<UnicodeString*>(service.get("de_US", LocaleKey::KIND_ANY, status));
confirmEqual("test de_US 2", german, target);
delete target;
}
{
UErrorCode status = U_ZERO_ERROR;
UnicodeString* target = (UnicodeString*)service.get("de_US", 1234, status);
UnicodeString* target = dynamic_cast<UnicodeString*>(service.get("de_US", 1234, status));
confirmEqual("test de_US 3", german, target);
delete target;
}
@ -1075,7 +1075,7 @@ void ICUServiceTest::testLocale() {
{
UErrorCode status = U_ZERO_ERROR;
Locale actualReturn;
UnicodeString* target = (UnicodeString*)service.get("de_US", &actualReturn, status);
UnicodeString* target = dynamic_cast<UnicodeString*>(service.get("de_US", &actualReturn, status));
confirmEqual("test de_US 5", german, target);
confirmEqual("test de_US 6", &actualReturn, &Locale::getGerman());
delete target;
@ -1084,7 +1084,7 @@ void ICUServiceTest::testLocale() {
{
UErrorCode status = U_ZERO_ERROR;
Locale actualReturn;
UnicodeString* target = (UnicodeString*)service.get("de_US", LocaleKey::KIND_ANY, &actualReturn, status);
UnicodeString* target = dynamic_cast<UnicodeString*>(service.get("de_US", LocaleKey::KIND_ANY, &actualReturn, status));
confirmEqual("test de_US 7", &actualReturn, &Locale::getGerman());
delete target;
}
@ -1092,7 +1092,7 @@ void ICUServiceTest::testLocale() {
{
UErrorCode status = U_ZERO_ERROR;
Locale actualReturn;
UnicodeString* target = (UnicodeString*)service.get("de_US", 1234, &actualReturn, status);
UnicodeString* target = dynamic_cast<UnicodeString*>(service.get("de_US", 1234, &actualReturn, status));
confirmEqual("test de_US 8", german, target);
confirmEqual("test de_US 9", &actualReturn, &Locale::getGerman());
delete target;
@ -1106,21 +1106,21 @@ void ICUServiceTest::testLocale() {
{
UErrorCode status = U_ZERO_ERROR;
UnicodeString* target = (UnicodeString*)service.get("de_US", 1, status);
UnicodeString* target = dynamic_cast<UnicodeString*>(service.get("de_US", 1, status));
confirmEqual("test de_US kind 1", one, target);
delete target;
}
{
UErrorCode status = U_ZERO_ERROR;
UnicodeString* target = (UnicodeString*)service.get("de_US", 2, status);
UnicodeString* target = dynamic_cast<UnicodeString*>(service.get("de_US", 2, status));
confirmEqual("test de_US kind 2", two, target);
delete target;
}
{
UErrorCode status = U_ZERO_ERROR;
UnicodeString* target = (UnicodeString*)service.get("de_US", status);
UnicodeString* target = dynamic_cast<UnicodeString*>(service.get("de_US", status));
confirmEqual("test de_US kind 3", german, target);
delete target;
}
@ -1150,7 +1150,7 @@ void ICUServiceTest::testLocale() {
{
UErrorCode status = U_ZERO_ERROR;
UnicodeString* target = (UnicodeString*)service.get("za_PPP", status);
UnicodeString* target = dynamic_cast<UnicodeString*>(service.get("za_PPP", status));
confirmEqual("test zappp", root, target);
delete target;
}
@ -1159,7 +1159,7 @@ void ICUServiceTest::testLocale() {
Locale::setDefault(Locale::getJapanese(), status);
{
UErrorCode status = U_ZERO_ERROR;
UnicodeString* target = (UnicodeString*)service.get("za_PPP", status);
UnicodeString* target = dynamic_cast<UnicodeString*>(service.get("za_PPP", status));
confirmEqual("test with ja locale", japanese, target);
delete target;
}
@ -1170,7 +1170,7 @@ void ICUServiceTest::testLocale() {
service.getVisibleIDs(ids, status);
logln("all visible ids:");
for (int i = 0; i < ids.size(); ++i) {
const UnicodeString* id = (const UnicodeString*)ids[i];
const UnicodeString* id = static_cast<const UnicodeString*>(const_cast<const void*>(ids[i]));
logln(*id);
}
}
@ -1182,14 +1182,14 @@ void ICUServiceTest::testLocale() {
service.getVisibleIDs(ids, status);
logln("all visible ids:");
for (int i = 0; i < ids.size(); ++i) {
const UnicodeString* id = (const UnicodeString*)ids[i];
const UnicodeString* id = static_cast<const UnicodeString*>(const_cast<const void*>(ids[i]));
logln(*id);
}
}
{
UErrorCode status = U_ZERO_ERROR;
UnicodeString* target = (UnicodeString*)service.get("za_PPP", status);
UnicodeString* target = dynamic_cast<UnicodeString*>(service.get("za_PPP", status));
confirmEqual("test with en locale", root, target);
delete target;
}
@ -1232,7 +1232,7 @@ class WrapFactory : public ICUServiceFactory {
if (U_SUCCESS(status)) {
UnicodeString temp;
if (key.currentID(temp).compare(getGreetingID()) == 0) {
UnicodeString* previous = (UnicodeString*)service->getKey((ICUServiceKey&)key, nullptr, this, status);
UnicodeString* previous = dynamic_cast<UnicodeString*>(service->getKey(const_cast<ICUServiceKey&>(key), nullptr, this, status));
if (previous) {
previous->insert(0, "A different greeting: \"");
previous->append("\"");
@ -1286,7 +1286,7 @@ ICUServiceTest::testWrapFactory()
{
UErrorCode status = U_ZERO_ERROR;
UnicodeString* result = (UnicodeString*)service.get(greetingID, status);
UnicodeString* result = dynamic_cast<UnicodeString*>(service.get(greetingID, status));
if (result) {
logln("test one: " + *result);
delete result;
@ -1296,7 +1296,7 @@ ICUServiceTest::testWrapFactory()
service.registerFactory(new WrapFactory(), status);
{
UErrorCode status = U_ZERO_ERROR;
UnicodeString* result = (UnicodeString*)service.get(greetingID, status);
UnicodeString* result = dynamic_cast<UnicodeString*>(service.get(greetingID, status));
UnicodeString target = "A different greeting: \"Hello There\"";
confirmEqual("wrap test: ", result, &target);
delete result;
@ -1342,7 +1342,7 @@ void ICUServiceTest::testCoverage()
service.registerFactory(sf, status);
{
UnicodeString* result = (UnicodeString*)service.get("object", status);
UnicodeString* result = dynamic_cast<UnicodeString*>(service.get("object", status));
if (result) {
logln("object is: " + *result);
delete result;
@ -1361,7 +1361,7 @@ void ICUServiceTest::testCoverage()
TestStringSimpleKeyService service;
service.registerInstance(howdy, "Greetings", status);
{
UnicodeString* result = (UnicodeString*)service.get("Greetings", status);
UnicodeString* result = dynamic_cast<UnicodeString*>(service.get("Greetings", status));
if (result) {
logln("object is: " + *result);
delete result;

View file

@ -26,7 +26,7 @@ CollationIteratorTest::CollationIteratorTest()
: test1("What subset of all possible test cases?", ""),
test2("has the highest probability of detecting", "")
{
en_us = (RuleBasedCollator *)Collator::createInstance(Locale::getUS(), status);
en_us = dynamic_cast<RuleBasedCollator*>(Collator::createInstance(Locale::getUS(), status));
if(U_FAILURE(status)) {
delete en_us;
en_us = 0;
@ -150,7 +150,7 @@ void CollationIteratorTest::TestPrevious(/* char* par */)
if(U_FAILURE(status)){
errln("Couldn't create a collator");
}
iter = ((RuleBasedCollator*)c4)->createCollationElementIterator(source);
iter = (dynamic_cast<RuleBasedCollator*>(c4))->createCollationElementIterator(source);
backAndForth(*iter);
delete iter;
delete c4;
@ -158,7 +158,7 @@ void CollationIteratorTest::TestPrevious(/* char* par */)
source= CharsToUnicodeString("\\u0061\\u30CF\\u3099\\u30FC");
Collator *c5 = Collator::createInstance(Locale("ja", "JP", ""), status);
iter = ((RuleBasedCollator*)c5)->createCollationElementIterator(source);
iter = (dynamic_cast<RuleBasedCollator*>(c5))->createCollationElementIterator(source);
if(U_FAILURE(status)){
errln("Couldn't create Japanese collator\n");
}
@ -332,7 +332,7 @@ void CollationIteratorTest::TestSetText(/* char* par */)
|| iter1->next(status) != (int32_t)CollationElementIterator::NULLORDER) {
errln("Empty string should have no CEs.");
}
((StringCharacterIterator *)chariter)->setText(empty);
(dynamic_cast<StringCharacterIterator*>(chariter))->setText(empty);
iter1->setText(*chariter, status);
if (U_FAILURE(status)
|| iter1->next(status) != (int32_t)CollationElementIterator::NULLORDER) {
@ -459,7 +459,7 @@ void CollationIteratorTest::TestAssignment()
{
UErrorCode status = U_ZERO_ERROR;
RuleBasedCollator *coll =
(RuleBasedCollator *)Collator::createInstance(status);
dynamic_cast<RuleBasedCollator*>(Collator::createInstance(status));
if (coll == nullptr || U_FAILURE(status))
{
@ -539,7 +539,7 @@ void CollationIteratorTest::TestConstructors()
{
UErrorCode status = U_ZERO_ERROR;
RuleBasedCollator *coll =
(RuleBasedCollator *)Collator::createInstance(status);
dynamic_cast<RuleBasedCollator*>(Collator::createInstance(status));
if (coll == nullptr || U_FAILURE(status))
{
errln("Couldn't create a default collator.");
@ -596,7 +596,7 @@ void CollationIteratorTest::TestStrengthOrder()
UErrorCode status = U_ZERO_ERROR;
RuleBasedCollator *coll =
(RuleBasedCollator *)Collator::createInstance(status);
dynamic_cast<RuleBasedCollator*>(Collator::createInstance(status));
if (coll == nullptr || U_FAILURE(status))
{
errln("Couldn't create a default collator.");

View file

@ -1192,8 +1192,8 @@ void
LocaleTest::TestThaiCurrencyFormat()
{
UErrorCode status = U_ZERO_ERROR;
DecimalFormat *thaiCurrency = (DecimalFormat*)NumberFormat::createCurrencyInstance(
Locale("th", "TH"), status);
DecimalFormat *thaiCurrency = dynamic_cast<DecimalFormat*>(NumberFormat::createCurrencyInstance(
Locale("th", "TH"), status));
UnicodeString posPrefix(u"\u0E3F");
UnicodeString temp;

View file

@ -4315,7 +4315,7 @@ void MeasureFormatTest::Test10219FractionalPlurals() {
for (int j = 0; j < UPRV_LENGTHOF(values); j++) {
for (int i = 0; i < UPRV_LENGTHOF(expected[j]); i++) {
DecimalFormat *df =
(DecimalFormat *) NumberFormat::createInstance(en, status);
dynamic_cast<DecimalFormat *>(NumberFormat::createInstance(en, status));
if (U_FAILURE(status)) {
dataerrln("Error creating Number format - %s", u_errorName(status));
return;

View file

@ -220,7 +220,7 @@ void CollationMonkeyTest::TestRules(/* char* par */){
logln("Demo Test 1 : Create a new table collation with rules \"& z < 0x00e4\"");
UErrorCode status = U_ZERO_ERROR;
Collator *col = Collator::createInstance("en_US", status);
const UnicodeString baseRules = ((RuleBasedCollator*)col)->getRules();
const UnicodeString baseRules = (dynamic_cast<RuleBasedCollator*>(col))->getRules();
UnicodeString newRules(" & z < ");
newRules.append((char16_t)0x00e4);
newRules.insert(0, baseRules);

View file

@ -421,7 +421,7 @@ NumberFormatTest::TestPatterns(void)
errln((UnicodeString)"FAIL: Pattern " + pat[i] + " should transmute to " + newpat[i] +
"; " + newp + " seen instead");
UnicodeString s; (*(NumberFormat*)&fmt).format((int32_t)0, s);
UnicodeString s; (*dynamic_cast<NumberFormat*>(&fmt)).format((int32_t)0, s);
if (!(s == num[i]))
{
errln((UnicodeString)"FAIL: Pattern " + pat[i] + " should format zero as " + num[i] +
@ -576,7 +576,7 @@ NumberFormatTest::TestExponential(void)
int32_t v;
for (v=0; v<val_length; ++v)
{
UnicodeString s; (*(NumberFormat*)&fmt).format(val[v], s);
UnicodeString s; (*dynamic_cast<NumberFormat*>(&fmt)).format(val[v], s);
logln((UnicodeString)" " + val[v] + " -format-> " + s);
if (s != valFormat[v+ival])
errln((UnicodeString)"FAIL: Expected " + valFormat[v+ival]);
@ -625,7 +625,7 @@ NumberFormatTest::TestExponential(void)
for (v=0; v<lval_length; ++v)
{
UnicodeString s;
(*(NumberFormat*)&fmt).format(lval[v], s);
(*dynamic_cast<NumberFormat*>(&fmt)).format(lval[v], s);
logln((UnicodeString)" " + lval[v] + "L -format-> " + s);
if (s != lvalFormat[v+ilval])
errln((UnicodeString)"ERROR: Expected " + lvalFormat[v+ilval] + " Got: " + s);
@ -660,7 +660,7 @@ void
NumberFormatTest::TestScientific2() {
// jb 2552
UErrorCode status = U_ZERO_ERROR;
DecimalFormat* fmt = (DecimalFormat*)NumberFormat::createCurrencyInstance("en_US", status);
DecimalFormat* fmt = dynamic_cast<DecimalFormat*>(NumberFormat::createCurrencyInstance("en_US", status));
if (U_SUCCESS(status)) {
double num = 12.34;
expect(*fmt, num, "$12.34");
@ -809,7 +809,7 @@ NumberFormatTest::TestQuotes(void)
pat = new UnicodeString("a'fo''o'b#");
DecimalFormat *fmt = new DecimalFormat(*pat, *sym, status);
UnicodeString s;
((NumberFormat*)fmt)->format((int32_t)123, s);
(dynamic_cast<NumberFormat*>(fmt))->format((int32_t)123, s);
logln((UnicodeString)"Pattern \"" + *pat + "\"");
logln((UnicodeString)" Format 123 -> " + escape(s));
if (!(s=="afo'ob123"))
@ -821,7 +821,7 @@ NumberFormatTest::TestQuotes(void)
pat = new UnicodeString("a''b#");
fmt = new DecimalFormat(*pat, *sym, status);
((NumberFormat*)fmt)->format((int32_t)123, s);
(dynamic_cast<NumberFormat*>(fmt))->format((int32_t)123, s);
logln((UnicodeString)"Pattern \"" + *pat + "\"");
logln((UnicodeString)" Format 123 -> " + escape(s));
if (!(s=="a'b123"))
@ -850,13 +850,13 @@ NumberFormatTest::TestCurrencySign(void)
pat.append(currency).append("#,##0.00;-").
append(currency).append("#,##0.00");
DecimalFormat *fmt = new DecimalFormat(pat, *sym, status);
UnicodeString s; ((NumberFormat*)fmt)->format(1234.56, s);
UnicodeString s; (dynamic_cast<NumberFormat*>(fmt))->format(1234.56, s);
pat.truncate(0);
logln((UnicodeString)"Pattern \"" + fmt->toPattern(pat) + "\"");
logln((UnicodeString)" Format " + 1234.56 + " -> " + escape(s));
if (s != "$1,234.56") dataerrln((UnicodeString)"FAIL: Expected $1,234.56");
s.truncate(0);
((NumberFormat*)fmt)->format(- 1234.56, s);
(dynamic_cast<NumberFormat*>(fmt))->format(- 1234.56, s);
logln((UnicodeString)" Format " + (-1234.56) + " -> " + escape(s));
if (s != "-$1,234.56") dataerrln((UnicodeString)"FAIL: Expected -$1,234.56");
delete fmt;
@ -868,12 +868,12 @@ NumberFormatTest::TestCurrencySign(void)
append(" -#,##0.00");
fmt = new DecimalFormat(pat, *sym, status);
s.truncate(0);
((NumberFormat*)fmt)->format(1234.56, s);
(dynamic_cast<NumberFormat*>(fmt))->format(1234.56, s);
logln((UnicodeString)"Pattern \"" + fmt->toPattern(pat) + "\"");
logln((UnicodeString)" Format " + 1234.56 + " -> " + escape(s));
if (s != "USD 1,234.56") dataerrln((UnicodeString)"FAIL: Expected USD 1,234.56");
s.truncate(0);
((NumberFormat*)fmt)->format(-1234.56, s);
(dynamic_cast<NumberFormat*>(fmt))->format(-1234.56, s);
logln((UnicodeString)" Format " + (-1234.56) + " -> " + escape(s));
if (s != "USD -1,234.56") dataerrln((UnicodeString)"FAIL: Expected USD -1,234.56");
delete fmt;
@ -2872,7 +2872,7 @@ void NumberFormatTest::expect(NumberFormat& fmt, const UnicodeString& str, const
return;
}
UnicodeString pat;
((DecimalFormat*) &fmt)->toPattern(pat);
(dynamic_cast<DecimalFormat*>(&fmt))->toPattern(pat);
if (equalValue(num, n)) {
logln(UnicodeString("Ok \"") + str + "\" x " +
pat + " = " +
@ -2945,7 +2945,7 @@ void NumberFormatTest::expect(NumberFormat& fmt, const Formattable& n,
fmt.format(n, saw, pos, status);
CHECK(status, "NumberFormat::format");
UnicodeString pat;
((DecimalFormat*) &fmt)->toPattern(pat);
(dynamic_cast<DecimalFormat*>(&fmt))->toPattern(pat);
if (saw == exp) {
logln(UnicodeString("Ok ") + toString(n) + " x " +
escape(pat) + " = \"" +
@ -2989,7 +2989,7 @@ void NumberFormatTest::expect(NumberFormat* fmt, const Formattable& n,
void NumberFormatTest::expectCurrency(NumberFormat& nf, const Locale& locale,
double value, const UnicodeString& string) {
UErrorCode ec = U_ZERO_ERROR;
DecimalFormat& fmt = * (DecimalFormat*) &nf;
DecimalFormat& fmt = * dynamic_cast<DecimalFormat*>(&nf);
const char16_t DEFAULT_CURR[] = {45/*-*/,0};
char16_t curr[4];
u_strcpy(curr, DEFAULT_CURR);
@ -3294,7 +3294,7 @@ void NumberFormatTest::TestCurrencyFormat()
/* Port of ICU4J rounding test. */
void NumberFormatTest::TestRounding() {
UErrorCode status = U_ZERO_ERROR;
DecimalFormat *df = (DecimalFormat*)NumberFormat::createCurrencyInstance(Locale::getEnglish(), status);
DecimalFormat *df = dynamic_cast<DecimalFormat*>(NumberFormat::createCurrencyInstance(Locale::getEnglish(), status));
if (U_FAILURE(status)) {
dataerrln("Unable to create decimal formatter. - %s", u_errorName(status));
@ -3332,7 +3332,7 @@ void NumberFormatTest::TestRoundingPattern() {
int32_t numOfTests = UPRV_LENGTHOF(tests);
UnicodeString result;
DecimalFormat *df = (DecimalFormat*)NumberFormat::createCurrencyInstance(Locale::getEnglish(), status);
DecimalFormat *df = dynamic_cast<DecimalFormat*>(NumberFormat::createCurrencyInstance(Locale::getEnglish(), status));
if (U_FAILURE(status)) {
dataerrln("Unable to create decimal formatter. - %s", u_errorName(status));
return;
@ -3662,7 +3662,7 @@ NumberFormatTest::TestMultiCurrencySign() {
continue;
}
UnicodeString s;
((NumberFormat*) fmt)->format(numberToBeFormat, s);
(dynamic_cast<NumberFormat*>(fmt))->format(numberToBeFormat, s);
// DATA[i][3] is the currency format result using a
// single currency sign.
// DATA[i][4] is the currency format result using
@ -6706,7 +6706,7 @@ void NumberFormatTest::TestFieldPositionIterator() {
FieldPositionIterator iter2;
FieldPosition pos;
DecimalFormat *decFmt = (DecimalFormat *) NumberFormat::createInstance(status);
DecimalFormat *decFmt = dynamic_cast<DecimalFormat *>(NumberFormat::createInstance(status));
if (failure(status, "NumberFormat::createInstance", true)) return;
double num = 1234.56;
@ -6736,7 +6736,7 @@ void NumberFormatTest::TestFieldPositionIterator() {
void NumberFormatTest::TestFormatAttributes() {
Locale locale("en_US");
UErrorCode status = U_ZERO_ERROR;
DecimalFormat *decFmt = (DecimalFormat *) NumberFormat::createInstance(locale, UNUM_CURRENCY, status);
DecimalFormat *decFmt = dynamic_cast<DecimalFormat *>(NumberFormat::createInstance(locale, UNUM_CURRENCY, status));
if (failure(status, "NumberFormat::createInstance", true)) return;
double val = 12345.67;
@ -6769,7 +6769,7 @@ void NumberFormatTest::TestFormatAttributes() {
}
delete decFmt;
decFmt = (DecimalFormat *) NumberFormat::createInstance(locale, UNUM_SCIENTIFIC, status);
decFmt = dynamic_cast<DecimalFormat *>(NumberFormat::createInstance(locale, UNUM_SCIENTIFIC, status));
val = -0.0000123;
{
int32_t expected[] = {
@ -7555,7 +7555,7 @@ void NumberFormatTest::TestSignificantDigits(void) {
UErrorCode status = U_ZERO_ERROR;
Locale locale("en_US");
LocalPointer<DecimalFormat> numberFormat(static_cast<DecimalFormat*>(
LocalPointer<DecimalFormat> numberFormat(dynamic_cast<DecimalFormat*>(
NumberFormat::createInstance(locale, status)));
CHECK_DATA(status,"NumberFormat::createInstance");
@ -7608,7 +7608,7 @@ void NumberFormatTest::TestSignificantDigits(void) {
void NumberFormatTest::TestShowZero() {
UErrorCode status = U_ZERO_ERROR;
Locale locale("en_US");
LocalPointer<DecimalFormat> numberFormat(static_cast<DecimalFormat*>(
LocalPointer<DecimalFormat> numberFormat(dynamic_cast<DecimalFormat*>(
NumberFormat::createInstance(locale, status)));
CHECK_DATA(status, "NumberFormat::createInstance");
@ -7625,7 +7625,7 @@ void NumberFormatTest::TestShowZero() {
void NumberFormatTest::TestBug9936() {
UErrorCode status = U_ZERO_ERROR;
Locale locale("en_US");
LocalPointer<DecimalFormat> numberFormat(static_cast<DecimalFormat*>(
LocalPointer<DecimalFormat> numberFormat(dynamic_cast<DecimalFormat*>(
NumberFormat::createInstance(locale, status)));
if (U_FAILURE(status)) {
dataerrln("File %s, Line %d: status = %s.\n", __FILE__, __LINE__, u_errorName(status));
@ -7660,7 +7660,7 @@ void NumberFormatTest::TestBug9936() {
void NumberFormatTest::TestParseNegativeWithFaLocale() {
UErrorCode status = U_ZERO_ERROR;
DecimalFormat *test = (DecimalFormat *) NumberFormat::createInstance("fa", status);
DecimalFormat *test = dynamic_cast<DecimalFormat *>(NumberFormat::createInstance("fa", status));
CHECK_DATA(status, "NumberFormat::createInstance");
test->setLenient(true);
Formattable af;
@ -7676,7 +7676,7 @@ void NumberFormatTest::TestParseNegativeWithFaLocale() {
void NumberFormatTest::TestParseNegativeWithAlternateMinusSign() {
UErrorCode status = U_ZERO_ERROR;
DecimalFormat *test = (DecimalFormat *) NumberFormat::createInstance("en", status);
DecimalFormat *test = dynamic_cast<DecimalFormat *>( NumberFormat::createInstance("en", status));
CHECK_DATA(status, "NumberFormat::createInstance");
test->setLenient(true);
Formattable af;
@ -7841,7 +7841,7 @@ void NumberFormatTest::Test10419RoundingWith0FractionDigits() {
{ DecimalFormat::kRoundUp, 1.5, "2"},
};
UErrorCode status = U_ZERO_ERROR;
LocalPointer<DecimalFormat> decfmt((DecimalFormat *) NumberFormat::createInstance(Locale("en_US"), status));
LocalPointer<DecimalFormat> decfmt(dynamic_cast<DecimalFormat *>( NumberFormat::createInstance(Locale("en_US"), status)));
if (U_FAILURE(status)) {
dataerrln("Failure creating DecimalFormat %s", u_errorName(status));
return;
@ -8185,7 +8185,7 @@ void NumberFormatTest::TestCurrencyUsage() {
for(int i=0; i<2; i++){
status = U_ZERO_ERROR;
if(i == 0){
fmt = (DecimalFormat *) NumberFormat::createInstance(enUS_ISK, UNUM_CURRENCY, status);
fmt = dynamic_cast<DecimalFormat *>( NumberFormat::createInstance(enUS_ISK, UNUM_CURRENCY, status));
if (assertSuccess("en_US@currency=ISK/CURRENCY", status, true) == false) {
continue;
}
@ -8200,7 +8200,7 @@ void NumberFormatTest::TestCurrencyUsage() {
fmt->setCurrencyUsage(UCURR_USAGE_CASH, &status);
}else{
fmt = (DecimalFormat *) NumberFormat::createInstance(enUS_ISK, UNUM_CASH_CURRENCY, status);
fmt = dynamic_cast<DecimalFormat *>( NumberFormat::createInstance(enUS_ISK, UNUM_CASH_CURRENCY, status));
if (assertSuccess("en_US@currency=ISK/CASH", status, true) == false) {
continue;
}
@ -8222,7 +8222,7 @@ void NumberFormatTest::TestCurrencyUsage() {
for(int i=0; i<2; i++){
status = U_ZERO_ERROR;
if(i == 0){
fmt = (DecimalFormat *) NumberFormat::createInstance(enUS_CAD, UNUM_CURRENCY, status);
fmt = dynamic_cast<DecimalFormat *>( NumberFormat::createInstance(enUS_CAD, UNUM_CURRENCY, status));
if (assertSuccess("en_US@currency=CAD/CURRENCY", status, true) == false) {
continue;
}
@ -8232,7 +8232,7 @@ void NumberFormatTest::TestCurrencyUsage() {
assertEquals("Test Currency Usage 3", u"CA$123.57", original_rounding);
fmt->setCurrencyUsage(UCURR_USAGE_CASH, &status);
}else{
fmt = (DecimalFormat *) NumberFormat::createInstance(enUS_CAD, UNUM_CASH_CURRENCY, status);
fmt = dynamic_cast<DecimalFormat *>( NumberFormat::createInstance(enUS_CAD, UNUM_CASH_CURRENCY, status));
if (assertSuccess("en_US@currency=CAD/CASH", status, true) == false) {
continue;
}
@ -8250,13 +8250,13 @@ void NumberFormatTest::TestCurrencyUsage() {
for(int i=0; i<2; i++){
status = U_ZERO_ERROR;
if(i == 0){
fmt = (DecimalFormat *) NumberFormat::createInstance(enUS_CAD, UNUM_CURRENCY, status);
fmt = dynamic_cast<DecimalFormat *>( NumberFormat::createInstance(enUS_CAD, UNUM_CURRENCY, status));
if (assertSuccess("en_US@currency=CAD/CURRENCY", status, true) == false) {
continue;
}
fmt->setCurrencyUsage(UCURR_USAGE_CASH, &status);
}else{
fmt = (DecimalFormat *) NumberFormat::createInstance(enUS_CAD, UNUM_CASH_CURRENCY, status);
fmt = dynamic_cast<DecimalFormat *>( NumberFormat::createInstance(enUS_CAD, UNUM_CASH_CURRENCY, status));
if (assertSuccess("en_US@currency=CAD/CASH", status, true) == false) {
continue;
}
@ -8562,7 +8562,7 @@ void NumberFormatTest::Test11739_ParseLongCurrency() {
IcuTestErrorCode status(*this, "Test11739_ParseLongCurrency");
LocalPointer<NumberFormat> nf(NumberFormat::createCurrencyInstance("sr_BA", status));
if (status.errDataIfFailureAndReset()) { return; }
((DecimalFormat*) nf.getAlias())->applyPattern(u"#,##0.0 ¤¤¤", status);
(dynamic_cast<DecimalFormat*>(nf.getAlias()))->applyPattern(u"#,##0.0 ¤¤¤", status);
ParsePosition ppos(0);
LocalPointer<CurrencyAmount> result(nf->parseCurrency(u"1.500 амерички долар", ppos));
assertEquals("Should parse to 1500 USD", -1, ppos.getErrorIndex());
@ -8609,7 +8609,7 @@ void NumberFormatTest::Test11376_getAndSetPositivePrefix() {
if (!assertSuccess("", status)) {
return;
}
DecimalFormat *dfmt = (DecimalFormat *) fmt.getAlias();
DecimalFormat *dfmt = dynamic_cast<DecimalFormat *>( fmt.getAlias());
dfmt->setCurrency(USD);
UnicodeString result;
@ -8629,7 +8629,7 @@ void NumberFormatTest::Test11376_getAndSetPositivePrefix() {
if (!assertSuccess("", status)) {
return;
}
DecimalFormat *dfmt = (DecimalFormat *) fmt.getAlias();
DecimalFormat *dfmt = dynamic_cast<DecimalFormat *>( fmt.getAlias());
UnicodeString result;
assertEquals("", u" (unknown currency)", dfmt->getPositiveSuffix(result));
dfmt->setCurrency(USD);
@ -8791,7 +8791,7 @@ void NumberFormatTest::Test13391_chakmaParsing() {
const char16_t* expectedScientific = u"\U00011137.\U00011139E\U00011138";
UnicodeString actualScientific;
df.adoptInstead(static_cast<DecimalFormat*>(
df.adoptInstead(dynamic_cast<DecimalFormat*>(
NumberFormat::createScientificInstance(Locale("ccp"), status)));
df->format(130, actualScientific, status);
assertSuccess("Should not fail when formatting scientific in ccp", status);
@ -8882,8 +8882,8 @@ void NumberFormatTest::Test11318_DoubleConversion() {
void NumberFormatTest::TestParsePercentRegression() {
IcuTestErrorCode status(*this, "TestParsePercentRegression");
LocalPointer<DecimalFormat> df1((DecimalFormat*) NumberFormat::createInstance("en", status), status);
LocalPointer<DecimalFormat> df2((DecimalFormat*) NumberFormat::createPercentInstance("en", status), status);
LocalPointer<DecimalFormat> df1(dynamic_cast<DecimalFormat*>( NumberFormat::createInstance("en", status)), status);
LocalPointer<DecimalFormat> df2(dynamic_cast<DecimalFormat*>( NumberFormat::createPercentInstance("en", status)), status);
if (status.isFailure()) {return; }
df1->setLenient(true);
df2->setLenient(true);
@ -9229,7 +9229,7 @@ void NumberFormatTest::Test10354() {
void NumberFormatTest::Test11645_ApplyPatternEquality() {
IcuTestErrorCode status(*this, "Test11645_ApplyPatternEquality");
const char16_t* pattern = u"#,##0.0#";
LocalPointer<DecimalFormat> fmt((DecimalFormat*) NumberFormat::createInstance(status), status);
LocalPointer<DecimalFormat> fmt(dynamic_cast<DecimalFormat*>(NumberFormat::createInstance(status)), status);
if (!assertSuccess("", status, true, __FILE__, __LINE__)) { return; }
fmt->applyPattern(pattern, status);
LocalPointer<DecimalFormat> fmtCopy;
@ -9274,10 +9274,10 @@ void NumberFormatTest::Test11645_ApplyPatternEquality() {
void NumberFormatTest::Test12567() {
IcuTestErrorCode errorCode(*this, "Test12567");
// Ticket #12567: DecimalFormat.equals() may not be symmetric
LocalPointer<DecimalFormat> df1((DecimalFormat *)
NumberFormat::createInstance(Locale::getUS(), UNUM_CURRENCY, errorCode));
LocalPointer<DecimalFormat> df2((DecimalFormat *)
NumberFormat::createInstance(Locale::getUS(), UNUM_DECIMAL, errorCode));
LocalPointer<DecimalFormat> df1(dynamic_cast<DecimalFormat *>(
NumberFormat::createInstance(Locale::getUS(), UNUM_CURRENCY, errorCode)));
LocalPointer<DecimalFormat> df2(dynamic_cast<DecimalFormat *>(
NumberFormat::createInstance(Locale::getUS(), UNUM_DECIMAL, errorCode)));
if (!assertSuccess("", errorCode, true, __FILE__, __LINE__)) { return; }
// NOTE: CurrencyPluralInfo equality not tested in C++ because its operator== is not defined.
df1->applyPattern(u"0.00", errorCode);
@ -9399,7 +9399,7 @@ void NumberFormatTest::Test11649_DecFmtCurrencies() {
void NumberFormatTest::Test13148_ParseGroupingSeparators() {
IcuTestErrorCode status(*this, "Test13148");
LocalPointer<DecimalFormat> fmt(
(DecimalFormat*)NumberFormat::createInstance("en-ZA", status), status);
dynamic_cast<DecimalFormat*>(NumberFormat::createInstance("en-ZA", status)), status);
if (!assertSuccess("", status, true, __FILE__, __LINE__)) { return; }
DecimalFormatSymbols symbols = *fmt->getDecimalFormatSymbols();
@ -9707,7 +9707,7 @@ void NumberFormatTest::Test13850_EmptyStringCurrency() {
void NumberFormatTest::Test20348_CurrencyPrefixOverride() {
IcuTestErrorCode status(*this, "Test20348_CurrencyPrefixOverride");
LocalPointer<DecimalFormat> fmt(static_cast<DecimalFormat*>(
LocalPointer<DecimalFormat> fmt(dynamic_cast<DecimalFormat*>(
NumberFormat::createCurrencyInstance("en", status)));
if (status.errIfFailureAndReset()) { return; }
UnicodeString result;
@ -9743,7 +9743,7 @@ void NumberFormatTest::Test20348_CurrencyPrefixOverride() {
void NumberFormatTest::Test20956_MonetarySymbolGetters() {
IcuTestErrorCode status(*this, "Test20956_MonetarySymbolGetters");
LocalPointer<DecimalFormat> decimalFormat(static_cast<DecimalFormat*>(
LocalPointer<DecimalFormat> decimalFormat(dynamic_cast<DecimalFormat*>(
NumberFormat::createCurrencyInstance("et", status)));
if (status.errDataIfFailureAndReset()) {
return;
@ -9775,7 +9775,7 @@ void NumberFormatTest::Test20956_MonetarySymbolGetters() {
void NumberFormatTest::Test20358_GroupingInPattern() {
IcuTestErrorCode status(*this, "Test20358_GroupingInPattern");
LocalPointer<DecimalFormat> fmt(static_cast<DecimalFormat*>(
LocalPointer<DecimalFormat> fmt(dynamic_cast<DecimalFormat*>(
NumberFormat::createInstance("en", status)));
if (status.errIfFailureAndReset()) { return; }
UnicodeString result;
@ -9890,7 +9890,7 @@ void NumberFormatTest::Test13734_StrictFlexibleWhitespace() {
void NumberFormatTest::Test20961_CurrencyPluralPattern() {
IcuTestErrorCode status(*this, "Test20961_CurrencyPluralPattern");
{
LocalPointer<DecimalFormat> decimalFormat(static_cast<DecimalFormat*>(
LocalPointer<DecimalFormat> decimalFormat(dynamic_cast<DecimalFormat*>(
NumberFormat::createInstance("en-US", UNUM_CURRENCY_PLURAL, status)));
if (status.errDataIfFailureAndReset()) {
return;
@ -9934,7 +9934,7 @@ void NumberFormatTest::Test21134_ToNumberFormatter() {
}
{
// Case 3: currency plural info (different code path)
LocalPointer<DecimalFormat> inner(static_cast<DecimalFormat*>(
LocalPointer<DecimalFormat> inner(dynamic_cast<DecimalFormat*>(
DecimalFormat::createInstance("en-US", UNUM_CURRENCY_PLURAL, status)));
if (auto ptr = inner->toNumberFormatter(status)) {
// Copy constructor
@ -10133,7 +10133,7 @@ void NumberFormatTest::Test21556_CurrencyAsDecimal() {
{
LocalPointer<NumberFormat> nf(NumberFormat::createCurrencyInstance("en-GB", status));
DecimalFormat* df = static_cast<DecimalFormat*>(nf.getAlias());
DecimalFormat* df = dynamic_cast<DecimalFormat*>(nf.getAlias());
df->applyPattern(u"a0¤00b", status);
UnicodeString result;
FieldPosition fp(UNUM_CURRENCY_FIELD);

View file

@ -1947,7 +1947,7 @@ void NumberFormatRegressionTest::Test4145457() {
return;
}
DecimalFormatSymbols *sym = (DecimalFormatSymbols*) nf->getDecimalFormatSymbols();
DecimalFormatSymbols *sym = const_cast<DecimalFormatSymbols*>(nf->getDecimalFormatSymbols());
sym->setSymbol(DecimalFormatSymbols::kDecimalSeparatorSymbol, (char16_t)/*'\''*/0x0027);
nf->setDecimalFormatSymbols(*sym);
double pi = 3.14159;
@ -2443,7 +2443,7 @@ void NumberFormatRegressionTest::Test4212072(void) {
if (U_FAILURE(status)) {
continue;
}
DecimalFormat *df = (DecimalFormat*) nf;
DecimalFormat *df = dynamic_cast<DecimalFormat*>(nf);
// Test toPattern/applyPattern round trip
UnicodeString pat;
@ -2509,7 +2509,7 @@ void NumberFormatRegressionTest::Test4212072(void) {
*/
void NumberFormatRegressionTest::Test4216742(void) {
UErrorCode status = U_ZERO_ERROR;
DecimalFormat *fmt = (DecimalFormat*) NumberFormat::createInstance(Locale::getUS(), status);
DecimalFormat *fmt = dynamic_cast<DecimalFormat*>(NumberFormat::createInstance(Locale::getUS(), status));
if (failure(status, "createInstance", Locale::getUS(), true)){
delete fmt;
return;
@ -2584,7 +2584,7 @@ void NumberFormatRegressionTest::Test4161100(void) {
nf->format(a, s);
UnicodeString pat;
logln(UnicodeString() + a + " x " +
((DecimalFormat*) nf)->toPattern(pat) + " = " + s);
(dynamic_cast<DecimalFormat*>(nf))->toPattern(pat) + " = " + s);
if (s != UnicodeString("-0.1")) {
errln("FAIL");
}

View file

@ -240,8 +240,8 @@ void PluralFormatTest::pluralFormatUnitTest(/*char *par*/)
errln("ERROR: PluralFormat failed to apply pattern- "+patternTestData[i]);
continue;
}
numberFormatTest(&plFmt, numFmt.getAlias(), 1, 10, (UnicodeString *)&patternOddTestResult[i],
(UnicodeString *)&patternEvenTestResult[i], overwrite[i], &message);
numberFormatTest(&plFmt, numFmt.getAlias(), 1, 10, dynamic_cast<UnicodeString *>(&patternOddTestResult[i]),
dynamic_cast<UnicodeString *>(&patternEvenTestResult[i]), overwrite[i], &message);
}
// ======= Test set locale

View file

@ -50,10 +50,10 @@ void RBBIAPITest::TestCloneEquals()
{
UErrorCode status=U_ZERO_ERROR;
RuleBasedBreakIterator* bi1 = (RuleBasedBreakIterator*)RuleBasedBreakIterator::createCharacterInstance(Locale::getDefault(), status);
RuleBasedBreakIterator* biequal = (RuleBasedBreakIterator*)RuleBasedBreakIterator::createCharacterInstance(Locale::getDefault(), status);
RuleBasedBreakIterator* bi3 = (RuleBasedBreakIterator*)RuleBasedBreakIterator::createCharacterInstance(Locale::getDefault(), status);
RuleBasedBreakIterator* bi2 = (RuleBasedBreakIterator*)RuleBasedBreakIterator::createWordInstance(Locale::getDefault(), status);
RuleBasedBreakIterator* bi1 = dynamic_cast<RuleBasedBreakIterator*>(RuleBasedBreakIterator::createCharacterInstance(Locale::getDefault(), status));
RuleBasedBreakIterator* biequal = dynamic_cast<RuleBasedBreakIterator*>(RuleBasedBreakIterator::createCharacterInstance(Locale::getDefault(), status));
RuleBasedBreakIterator* bi3 = dynamic_cast<RuleBasedBreakIterator*>(RuleBasedBreakIterator::createCharacterInstance(Locale::getDefault(), status));
RuleBasedBreakIterator* bi2 = dynamic_cast<RuleBasedBreakIterator*>(RuleBasedBreakIterator::createWordInstance(Locale::getDefault(), status));
if(U_FAILURE(status)){
errcheckln(status, "Fail : in construction - %s", u_errorName(status));
return;
@ -88,7 +88,7 @@ void RBBIAPITest::TestCloneEquals()
// source and dest iterator produce the same next() after assignment.
// deleting one doesn't disable the other.
logln("Testing assignment");
RuleBasedBreakIterator *bix = (RuleBasedBreakIterator *)BreakIterator::createLineInstance(Locale::getDefault(), status);
RuleBasedBreakIterator *bix = dynamic_cast<RuleBasedBreakIterator *>(BreakIterator::createLineInstance(Locale::getDefault(), status));
if(U_FAILURE(status)){
errcheckln(status, "Fail : in construction - %s", u_errorName(status));
return;
@ -190,9 +190,9 @@ void RBBIAPITest::TestgetRules()
UErrorCode status=U_ZERO_ERROR;
LocalPointer<RuleBasedBreakIterator> bi1(
(RuleBasedBreakIterator*)RuleBasedBreakIterator::createCharacterInstance(Locale::getDefault(), status), status);
dynamic_cast<RuleBasedBreakIterator*>(RuleBasedBreakIterator::createCharacterInstance(Locale::getDefault(), status)), status);
LocalPointer<RuleBasedBreakIterator> bi2(
(RuleBasedBreakIterator*)RuleBasedBreakIterator::createWordInstance(Locale::getDefault(), status), status);
dynamic_cast<RuleBasedBreakIterator*>(RuleBasedBreakIterator::createWordInstance(Locale::getDefault(), status)), status);
if(U_FAILURE(status)){
errcheckln(status, "%s:%d, FAIL: in construction - %s", __FILE__, __LINE__, u_errorName(status));
return;
@ -220,9 +220,9 @@ void RBBIAPITest::TestgetRules()
void RBBIAPITest::TestHashCode()
{
UErrorCode status=U_ZERO_ERROR;
RuleBasedBreakIterator* bi1 = (RuleBasedBreakIterator*)RuleBasedBreakIterator::createCharacterInstance(Locale::getDefault(), status);
RuleBasedBreakIterator* bi3 = (RuleBasedBreakIterator*)RuleBasedBreakIterator::createCharacterInstance(Locale::getDefault(), status);
RuleBasedBreakIterator* bi2 = (RuleBasedBreakIterator*)RuleBasedBreakIterator::createWordInstance(Locale::getDefault(), status);
RuleBasedBreakIterator* bi1 = dynamic_cast<RuleBasedBreakIterator*>(RuleBasedBreakIterator::createCharacterInstance(Locale::getDefault(), status));
RuleBasedBreakIterator* bi3 = dynamic_cast<RuleBasedBreakIterator*>(RuleBasedBreakIterator::createCharacterInstance(Locale::getDefault(), status));
RuleBasedBreakIterator* bi2 = dynamic_cast<RuleBasedBreakIterator*>(RuleBasedBreakIterator::createWordInstance(Locale::getDefault(), status));
if(U_FAILURE(status)){
errcheckln(status, "Fail : in construction - %s", u_errorName(status));
delete bi1;
@ -262,8 +262,8 @@ void RBBIAPITest::TestGetSetAdoptText()
IcuTestErrorCode status(*this, "TestGetSetAdoptText");
UnicodeString str1="first string.";
UnicodeString str2="Second string.";
LocalPointer<RuleBasedBreakIterator> charIter1((RuleBasedBreakIterator*)RuleBasedBreakIterator::createCharacterInstance(Locale::getDefault(), status));
LocalPointer<RuleBasedBreakIterator> wordIter1((RuleBasedBreakIterator*)RuleBasedBreakIterator::createWordInstance(Locale::getDefault(), status));
LocalPointer<RuleBasedBreakIterator> charIter1(dynamic_cast<RuleBasedBreakIterator*>(RuleBasedBreakIterator::createCharacterInstance(Locale::getDefault(), status)));
LocalPointer<RuleBasedBreakIterator> wordIter1(dynamic_cast<RuleBasedBreakIterator*>(RuleBasedBreakIterator::createWordInstance(Locale::getDefault(), status)));
if(status.isFailure()){
errcheckln(status, "Fail : in construction - %s", status.errorName());
return;
@ -385,42 +385,42 @@ void RBBIAPITest::TestIteration()
// Testing for correct operation of the break rules happens elsewhere.
UErrorCode status=U_ZERO_ERROR;
RuleBasedBreakIterator* bi = (RuleBasedBreakIterator*)RuleBasedBreakIterator::createCharacterInstance(Locale::getDefault(), status);
RuleBasedBreakIterator* bi = dynamic_cast<RuleBasedBreakIterator*>(RuleBasedBreakIterator::createCharacterInstance(Locale::getDefault(), status));
if (U_FAILURE(status) || bi == nullptr) {
errcheckln(status, "Failure creating character break iterator. Status = %s", u_errorName(status));
}
delete bi;
status=U_ZERO_ERROR;
bi = (RuleBasedBreakIterator*)RuleBasedBreakIterator::createWordInstance(Locale::getDefault(), status);
bi = dynamic_cast<RuleBasedBreakIterator*>(RuleBasedBreakIterator::createWordInstance(Locale::getDefault(), status));
if (U_FAILURE(status) || bi == nullptr) {
errcheckln(status, "Failure creating Word break iterator. Status = %s", u_errorName(status));
}
delete bi;
status=U_ZERO_ERROR;
bi = (RuleBasedBreakIterator*)RuleBasedBreakIterator::createLineInstance(Locale::getDefault(), status);
bi = dynamic_cast<RuleBasedBreakIterator*>(RuleBasedBreakIterator::createLineInstance(Locale::getDefault(), status));
if (U_FAILURE(status) || bi == nullptr) {
errcheckln(status, "Failure creating Line break iterator. Status = %s", u_errorName(status));
}
delete bi;
status=U_ZERO_ERROR;
bi = (RuleBasedBreakIterator*)RuleBasedBreakIterator::createSentenceInstance(Locale::getDefault(), status);
bi = dynamic_cast<RuleBasedBreakIterator*>(RuleBasedBreakIterator::createSentenceInstance(Locale::getDefault(), status));
if (U_FAILURE(status) || bi == nullptr) {
errcheckln(status, "Failure creating Sentence break iterator. Status = %s", u_errorName(status));
}
delete bi;
status=U_ZERO_ERROR;
bi = (RuleBasedBreakIterator*)RuleBasedBreakIterator::createTitleInstance(Locale::getDefault(), status);
bi = dynamic_cast<RuleBasedBreakIterator*>(RuleBasedBreakIterator::createTitleInstance(Locale::getDefault(), status));
if (U_FAILURE(status) || bi == nullptr) {
errcheckln(status, "Failure creating Title break iterator. Status = %s", u_errorName(status));
}
delete bi;
status=U_ZERO_ERROR;
bi = (RuleBasedBreakIterator*)RuleBasedBreakIterator::createCharacterInstance(Locale::getDefault(), status);
bi = dynamic_cast<RuleBasedBreakIterator*>(RuleBasedBreakIterator::createCharacterInstance(Locale::getDefault(), status));
if (U_FAILURE(status) || bi == nullptr) {
errcheckln(status, "Failure creating character break iterator. Status = %s", u_errorName(status));
return; // Skip the rest of these tests.
@ -1130,7 +1130,7 @@ void RBBIAPITest::TestRefreshInputText() {
UErrorCode status = U_ZERO_ERROR;
UText ut1 = UTEXT_INITIALIZER;
UText ut2 = UTEXT_INITIALIZER;
RuleBasedBreakIterator *bi = (RuleBasedBreakIterator *)BreakIterator::createLineInstance(Locale::getEnglish(), status);
RuleBasedBreakIterator *bi = dynamic_cast<RuleBasedBreakIterator *>(BreakIterator::createLineInstance(Locale::getEnglish(), status));
TEST_ASSERT_SUCCESS(status);
utext_openUChars(&ut1, testStr, -1, &status);

View file

@ -1206,28 +1206,28 @@ void RBBITest::TestUnicodeFiles() {
RuleBasedBreakIterator *bi;
UErrorCode status = U_ZERO_ERROR;
bi = (RuleBasedBreakIterator *)BreakIterator::createCharacterInstance(Locale::getEnglish(), status);
bi = dynamic_cast<RuleBasedBreakIterator*>(BreakIterator::createCharacterInstance(Locale::getEnglish(), status));
TEST_ASSERT_SUCCESS(status);
if (U_SUCCESS(status)) {
runUnicodeTestData("GraphemeBreakTest.txt", bi);
}
delete bi;
bi = (RuleBasedBreakIterator *)BreakIterator::createWordInstance(Locale::getEnglish(), status);
bi = dynamic_cast<RuleBasedBreakIterator*>(BreakIterator::createWordInstance(Locale::getEnglish(), status));
TEST_ASSERT_SUCCESS(status);
if (U_SUCCESS(status)) {
runUnicodeTestData("WordBreakTest.txt", bi);
}
delete bi;
bi = (RuleBasedBreakIterator *)BreakIterator::createSentenceInstance(Locale::getEnglish(), status);
bi = dynamic_cast<RuleBasedBreakIterator*>(BreakIterator::createSentenceInstance(Locale::getEnglish(), status));
TEST_ASSERT_SUCCESS(status);
if (U_SUCCESS(status)) {
runUnicodeTestData("SentenceBreakTest.txt", bi);
}
delete bi;
bi = (RuleBasedBreakIterator *)BreakIterator::createLineInstance(Locale::getEnglish(), status);
bi = dynamic_cast<RuleBasedBreakIterator*>(BreakIterator::createLineInstance(Locale::getEnglish(), status));
TEST_ASSERT_SUCCESS(status);
if (U_SUCCESS(status)) {
runUnicodeTestData("LineBreakTest.txt", bi);
@ -1562,7 +1562,7 @@ std::string RBBIMonkeyKind::getAppliedRule(int32_t position){
std::string RBBIMonkeyKind::classNameFromCodepoint(const UChar32 c) {
// Simply iterate through charClasses to find character's class
for (int aClassNum = 0; aClassNum < charClasses()->size(); aClassNum++) {
UnicodeSet *classSet = (UnicodeSet *)charClasses()->elementAt(aClassNum);
UnicodeSet *classSet = static_cast<UnicodeSet *>(charClasses()->elementAt(aClassNum));
if (classSet->contains(c)) {
return classNames[aClassNum];
}
@ -3993,7 +3993,7 @@ void RBBITest::RunMonkey(BreakIterator *bi, RBBIMonkeyKind &mk, const char *name
// Verify that the character classes all have at least one member.
for (i=0; i<numCharClasses; i++) {
UnicodeSet *s = (UnicodeSet *)chClasses->elementAt(i);
UnicodeSet *s = static_cast<UnicodeSet *>(chClasses->elementAt(i));
if (s == nullptr || s->size() == 0) {
errln("Character Class #%d is null or of zero size.", i);
return;
@ -4316,10 +4316,10 @@ void RBBITest::TestBug9983(void) {
"\\u0000").unescape();
UErrorCode status = U_ZERO_ERROR;
LocalPointer<RuleBasedBreakIterator> brkiter(static_cast<RuleBasedBreakIterator *>(
LocalPointer<RuleBasedBreakIterator> brkiter(dynamic_cast<RuleBasedBreakIterator *>(
BreakIterator::createWordInstance(Locale::getRoot(), status)));
TEST_ASSERT_SUCCESS(status);
LocalPointer<RuleBasedBreakIterator> brkiterPOSIX(static_cast<RuleBasedBreakIterator *>(
LocalPointer<RuleBasedBreakIterator> brkiterPOSIX(dynamic_cast<RuleBasedBreakIterator *>(
BreakIterator::createWordInstance(Locale::createFromName("en_US_POSIX"), status)));
TEST_ASSERT_SUCCESS(status);
if (U_FAILURE(status)) {
@ -4521,8 +4521,8 @@ void RBBITest::TestEmoji() {
void RBBITest::TestBug12519() {
UErrorCode status = U_ZERO_ERROR;
LocalPointer<RuleBasedBreakIterator> biEn((RuleBasedBreakIterator *)BreakIterator::createWordInstance(Locale::getEnglish(), status));
LocalPointer<RuleBasedBreakIterator> biFr((RuleBasedBreakIterator *)BreakIterator::createWordInstance(Locale::getFrance(), status));
LocalPointer<RuleBasedBreakIterator> biEn(dynamic_cast<RuleBasedBreakIterator*>(BreakIterator::createWordInstance(Locale::getEnglish(), status)));
LocalPointer<RuleBasedBreakIterator> biFr(dynamic_cast<RuleBasedBreakIterator*>(BreakIterator::createWordInstance(Locale::getFrance(), status)));
if (!assertSuccess(WHERE, status)) {
dataerrln("%s %d status = %s", __FILE__, __LINE__, u_errorName(status));
return;
@ -4540,7 +4540,7 @@ void RBBITest::TestBug12519() {
assertTrue(WHERE, *biFr == *cloneFr);
assertTrue(WHERE, Locale::getFrench() == cloneFr->getLocale(ULOC_VALID_LOCALE, status));
LocalPointer<RuleBasedBreakIterator>biDe((RuleBasedBreakIterator *)BreakIterator::createLineInstance(Locale::getGerman(), status));
LocalPointer<RuleBasedBreakIterator>biDe(dynamic_cast<RuleBasedBreakIterator*>(BreakIterator::createLineInstance(Locale::getGerman(), status)));
UnicodeString text("Hallo Welt");
biDe->setText(text);
assertTrue(WHERE "before assignment of \"biDe = biFr\", they should be different, but are equal.", *biFr != *biDe);
@ -4570,7 +4570,7 @@ void RBBITest::TestTableRedundancies() {
UErrorCode status = U_ZERO_ERROR;
LocalPointer<RuleBasedBreakIterator> bi (
(RuleBasedBreakIterator *)BreakIterator::createLineInstance(Locale::getEnglish(), status));
dynamic_cast<RuleBasedBreakIterator*>(BreakIterator::createLineInstance(Locale::getEnglish(), status)));
assertSuccess(WHERE, status);
if (U_FAILURE(status)) return;
@ -4586,7 +4586,7 @@ void RBBITest::TestTableRedundancies() {
for (int32_t column = 0; column < numCharClasses; column++) {
UnicodeString s;
for (int32_t r = 1; r < (int32_t)fwtbl->fNumStates; r++) {
RBBIStateTableRow *row = (RBBIStateTableRow *) (fwtbl->fTableData + (fwtbl->fRowLen * r));
RBBIStateTableRow *row = reinterpret_cast<RBBIStateTableRow *>(const_cast<char*>(fwtbl->fTableData + (fwtbl->fRowLen * r)));
s.append(in8Bits ? row->r8.fNextState[column] : row->r16.fNextState[column]);
}
columns.push_back(s);
@ -4607,7 +4607,7 @@ void RBBITest::TestTableRedundancies() {
std::vector<UnicodeString> rows;
for (int32_t r=0; r < (int32_t)fwtbl->fNumStates; r++) {
UnicodeString s;
RBBIStateTableRow *row = (RBBIStateTableRow *) (fwtbl->fTableData + (fwtbl->fRowLen * r));
RBBIStateTableRow *row = reinterpret_cast<RBBIStateTableRow *>(const_cast<char*>((fwtbl->fTableData + (fwtbl->fRowLen * r))));
if (in8Bits) {
s.append(row->r8.fAccepting);
s.append(row->r8.fLookAhead);
@ -4641,7 +4641,7 @@ void RBBITest::TestTableRedundancies() {
void RBBITest::TestBug13447() {
UErrorCode status = U_ZERO_ERROR;
LocalPointer<RuleBasedBreakIterator> bi(
(RuleBasedBreakIterator *)BreakIterator::createWordInstance(Locale::getEnglish(), status));
dynamic_cast<RuleBasedBreakIterator*>(BreakIterator::createWordInstance(Locale::getEnglish(), status)));
assertSuccess(WHERE, status);
if (U_FAILURE(status)) return;
UnicodeString data(u"1234");
@ -4665,20 +4665,20 @@ void RBBITest::TestBug13447() {
void RBBITest::TestReverse() {
UErrorCode status = U_ZERO_ERROR;
TestReverse(std::unique_ptr<RuleBasedBreakIterator>((RuleBasedBreakIterator *)
BreakIterator::createCharacterInstance(Locale::getEnglish(), status)));
TestReverse(std::unique_ptr<RuleBasedBreakIterator>(dynamic_cast<RuleBasedBreakIterator*>(
BreakIterator::createCharacterInstance(Locale::getEnglish(), status))));
assertSuccess(WHERE, status, true);
status = U_ZERO_ERROR;
TestReverse(std::unique_ptr<RuleBasedBreakIterator>((RuleBasedBreakIterator *)
BreakIterator::createWordInstance(Locale::getEnglish(), status)));
TestReverse(std::unique_ptr<RuleBasedBreakIterator>(dynamic_cast<RuleBasedBreakIterator*>(
BreakIterator::createWordInstance(Locale::getEnglish(), status))));
assertSuccess(WHERE, status, true);
status = U_ZERO_ERROR;
TestReverse(std::unique_ptr<RuleBasedBreakIterator>((RuleBasedBreakIterator *)
BreakIterator::createLineInstance(Locale::getEnglish(), status)));
TestReverse(std::unique_ptr<RuleBasedBreakIterator>(dynamic_cast<RuleBasedBreakIterator*>(
BreakIterator::createLineInstance(Locale::getEnglish(), status))));
assertSuccess(WHERE, status, true);
status = U_ZERO_ERROR;
TestReverse(std::unique_ptr<RuleBasedBreakIterator>((RuleBasedBreakIterator *)
BreakIterator::createSentenceInstance(Locale::getEnglish(), status)));
TestReverse(std::unique_ptr<RuleBasedBreakIterator>(dynamic_cast<RuleBasedBreakIterator*>(
BreakIterator::createSentenceInstance(Locale::getEnglish(), status))));
assertSuccess(WHERE, status, true);
}
@ -4743,8 +4743,8 @@ void RBBITest::TestReverse(std::unique_ptr<RuleBasedBreakIterator>bi) {
void RBBITest::TestBug13692() {
UErrorCode status = U_ZERO_ERROR;
LocalPointer<RuleBasedBreakIterator> bi ((RuleBasedBreakIterator *)
BreakIterator::createWordInstance(Locale::getEnglish(), status), status);
LocalPointer<RuleBasedBreakIterator> bi (dynamic_cast<RuleBasedBreakIterator*>(
BreakIterator::createWordInstance(Locale::getEnglish(), status)), status);
if (!assertSuccess(WHERE, status, true)) {
return;
}
@ -4778,8 +4778,8 @@ void RBBITest::TestProperties() {
//
void RBBITest::TestDebug(void) {
UErrorCode status = U_ZERO_ERROR;
LocalPointer<RuleBasedBreakIterator> bi ((RuleBasedBreakIterator *)
BreakIterator::createCharacterInstance(Locale::getEnglish(), status), status);
LocalPointer<RuleBasedBreakIterator> bi (dynamic_cast<RuleBasedBreakIterator*>(
BreakIterator::createCharacterInstance(Locale::getEnglish(), status)), status);
if (!assertSuccess(WHERE, status, true)) {
return;
}
@ -5495,7 +5495,7 @@ void RBBITest::TestRandomAccess() {
UErrorCode status = U_ZERO_ERROR;
LocalPointer<RuleBasedBreakIterator> bi(
(RuleBasedBreakIterator *)BreakIterator::createLineInstance(Locale::getEnglish(), status),
dynamic_cast<RuleBasedBreakIterator*>(BreakIterator::createLineInstance(Locale::getEnglish(), status)),
status);
if (!assertSuccess(WHERE, status)) { return; };

View file

@ -24,7 +24,7 @@ CollationRegressionTest::CollationRegressionTest()
{
UErrorCode status = U_ZERO_ERROR;
en_us = (RuleBasedCollator *)Collator::createInstance(Locale::getUS(), status);
en_us = dynamic_cast<RuleBasedCollator*>(Collator::createInstance(Locale::getUS(), status));
if(U_FAILURE(status)) {
delete en_us;
en_us = 0;
@ -370,7 +370,7 @@ void CollationRegressionTest::Test4062418(/* char* par */)
RuleBasedCollator *c = nullptr;
c = (RuleBasedCollator *) Collator::createInstance(Locale::getCanadaFrench(), status);
c = dynamic_cast<RuleBasedCollator*>(Collator::createInstance(Locale::getCanadaFrench(), status));
if (c == nullptr || U_FAILURE(status))
{
@ -450,7 +450,7 @@ void CollationRegressionTest::Test4066696(/* char* par */)
UErrorCode status = U_ZERO_ERROR;
RuleBasedCollator *c = nullptr;
c = (RuleBasedCollator *)Collator::createInstance(Locale::getCanadaFrench(), status);
c = dynamic_cast<RuleBasedCollator*>(Collator::createInstance(Locale::getCanadaFrench(), status));
if (c == nullptr || U_FAILURE(status))
{
@ -599,7 +599,7 @@ void CollationRegressionTest::Test4087241(/* char* par */)
Locale da_DK("da", "DK");
RuleBasedCollator *c = nullptr;
c = (RuleBasedCollator *) Collator::createInstance(da_DK, status);
c = dynamic_cast<RuleBasedCollator*>(Collator::createInstance(da_DK, status));
if (c == nullptr || U_FAILURE(status))
{

View file

@ -2030,7 +2030,7 @@ void RegexTest::API_Match_UTF8() {
//const char str_0123456789[] = { 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x00 }; /* 0123456789 */
// Test shallow-clone API
int64_t group_len;
result = matcher->group((UText *)nullptr, group_len, status);
result = matcher->group(nullptr, group_len, status);
REGEX_CHECK_STATUS;
REGEX_ASSERT_UTEXT_UTF8(str_0123456789, result);
utext_close(result);
@ -4697,7 +4697,7 @@ struct callBackContext {
U_CDECL_BEGIN
static UBool U_CALLCONV
testCallBackFn(const void *context, int32_t steps) {
callBackContext *info = (callBackContext *)context;
callBackContext *info = static_cast<callBackContext *>(const_cast<void*>(context));
if (info->lastSteps+1 != steps) {
info->test->errln("incorrect steps in callback. Expected %d, got %d\n", info->lastSteps+1, steps);
}

View file

@ -117,7 +117,7 @@ void ScientificNumberFormatterTest::TestFarsi() {
void ScientificNumberFormatterTest::TestPlusSignInExponentMarkup() {
UErrorCode status = U_ZERO_ERROR;
LocalPointer<DecimalFormat> decfmt((DecimalFormat *) NumberFormat::createScientificInstance("en", status));
LocalPointer<DecimalFormat> decfmt(dynamic_cast<DecimalFormat*>(NumberFormat::createScientificInstance("en", status)));
if (U_FAILURE(status)) {
dataerrln("Failed call NumberFormat::createScientificInstance(\"en\", status) - %s", u_errorName(status));
return;
@ -144,7 +144,7 @@ void ScientificNumberFormatterTest::TestPlusSignInExponentMarkup() {
void ScientificNumberFormatterTest::TestPlusSignInExponentSuperscript() {
UErrorCode status = U_ZERO_ERROR;
LocalPointer<DecimalFormat> decfmt((DecimalFormat *) NumberFormat::createScientificInstance("en", status));
LocalPointer<DecimalFormat> decfmt(dynamic_cast<DecimalFormat*>(NumberFormat::createScientificInstance("en", status)));
if (U_FAILURE(status)) {
dataerrln("Failed call NumberFormat::createScientificInstance(\"en\", status) - %s", u_errorName(status));
return;
@ -171,7 +171,7 @@ void ScientificNumberFormatterTest::TestPlusSignInExponentSuperscript() {
void ScientificNumberFormatterTest::TestFixedDecimalMarkup() {
UErrorCode status = U_ZERO_ERROR;
LocalPointer<DecimalFormat> decfmt((DecimalFormat *) NumberFormat::createInstance("en", status));
LocalPointer<DecimalFormat> decfmt(dynamic_cast<DecimalFormat*>(NumberFormat::createInstance("en", status)));
if (assertSuccess("NumberFormat::createInstance", status, true) == false) {
return;
}
@ -193,7 +193,7 @@ void ScientificNumberFormatterTest::TestFixedDecimalMarkup() {
void ScientificNumberFormatterTest::TestFixedDecimalSuperscript() {
UErrorCode status = U_ZERO_ERROR;
LocalPointer<DecimalFormat> decfmt((DecimalFormat *) NumberFormat::createInstance("en", status));
LocalPointer<DecimalFormat> decfmt(dynamic_cast<DecimalFormat*>(NumberFormat::createInstance("en", status)));
if (assertSuccess("NumberFormat::createInstance", status, true) == false) {
return;
}

View file

@ -48,10 +48,10 @@ StringSearchTest::StringSearchTest()
#if !UCONFIG_NO_BREAK_ITERATION
UErrorCode status = U_ZERO_ERROR;
m_en_us_ = (RuleBasedCollator *)Collator::createInstance("en_US", status);
m_fr_fr_ = (RuleBasedCollator *)Collator::createInstance("fr_FR", status);
m_de_ = (RuleBasedCollator *)Collator::createInstance("de_DE", status);
m_es_ = (RuleBasedCollator *)Collator::createInstance("es_ES", status);
m_en_us_ = dynamic_cast<RuleBasedCollator*>(Collator::createInstance("en_US", status));
m_fr_fr_ = dynamic_cast<RuleBasedCollator*>(Collator::createInstance("fr_FR", status));
m_de_ = dynamic_cast<RuleBasedCollator*>(Collator::createInstance("de_DE", status));
m_es_ = dynamic_cast<RuleBasedCollator*>(Collator::createInstance("es_ES", status));
if(U_FAILURE(status)) {
delete m_en_us_;
delete m_fr_fr_;
@ -67,7 +67,7 @@ StringSearchTest::StringSearchTest()
UnicodeString rules;
rules.setTo(((RuleBasedCollator *)m_de_)->getRules());
rules.setTo(m_de_->getRules());
char16_t extrarules[128];
u_unescape(EXTRACOLLATIONRULE, extrarules, 128);
rules.append(extrarules, u_strlen(extrarules));
@ -75,7 +75,7 @@ StringSearchTest::StringSearchTest()
m_de_ = new RuleBasedCollator(rules, status);
rules.setTo(((RuleBasedCollator *)m_es_)->getRules());
rules.setTo(m_es_->getRules());
rules.append(extrarules, u_strlen(extrarules));
delete m_es_;
@ -487,7 +487,7 @@ UBool StringSearchTest::assertEqual(const SearchData *search)
}
#endif
collator->setStrength(getECollationStrength(search->strength));
strsrch = new StringSearch(pattern, text, (RuleBasedCollator *)collator,
strsrch = new StringSearch(pattern, text, dynamic_cast<RuleBasedCollator*>(collator),
breaker, status);
if (U_FAILURE(status)) {
errln("Error opening string search %s", u_errorName(status));
@ -547,7 +547,7 @@ UBool StringSearchTest::assertCanonicalEqual(const SearchData *search)
#endif
collator->setStrength(getECollationStrength(search->strength));
collator->setAttribute(UCOL_NORMALIZATION_MODE, UCOL_ON, status);
strsrch = new StringSearch(pattern, text, (RuleBasedCollator *)collator,
strsrch = new StringSearch(pattern, text, dynamic_cast<RuleBasedCollator*>(collator),
breaker, status);
strsrch->setAttribute(USEARCH_CANONICAL_MATCH, USEARCH_ON, status);
if (U_FAILURE(status)) {
@ -599,7 +599,7 @@ UBool StringSearchTest::assertEqualWithAttribute(const SearchData *search,
}
#endif
collator->setStrength(getECollationStrength(search->strength));
strsrch = new StringSearch(pattern, text, (RuleBasedCollator *)collator,
strsrch = new StringSearch(pattern, text, dynamic_cast<RuleBasedCollator*>(collator),
breaker, status);
strsrch->setAttribute(USEARCH_CANONICAL_MATCH, canonical, status);
strsrch->setAttribute(USEARCH_OVERLAP, overlap, status);

View file

@ -626,7 +626,7 @@ void SSearchTest::offsetTest()
int32_t testCount = UPRV_LENGTHOF(test);
UErrorCode status = U_ZERO_ERROR;
RuleBasedCollator *col = (RuleBasedCollator *) Collator::createInstance(Locale::getEnglish(), status);
RuleBasedCollator *col = dynamic_cast<RuleBasedCollator*>(Collator::createInstance(Locale::getEnglish(), status));
if (U_FAILURE(status)) {
errcheckln(status, "Failed to create collator in offsetTest! - %s", u_errorName(status));
return;

View file

@ -440,7 +440,7 @@ StringCaseTest::TestCasingImpl(const UnicodeString &input,
#if !UCONFIG_NO_BREAK_ITERATION
case TEST_TITLE:
name="toTitle";
result.toTitle((BreakIterator *)iter, locale, options);
result.toTitle(static_cast<BreakIterator *>(iter), locale, options);
break;
#endif
case TEST_FOLD:
@ -458,7 +458,7 @@ StringCaseTest::TestCasingImpl(const UnicodeString &input,
#if !UCONFIG_NO_BREAK_ITERATION
if(whichCase==TEST_TITLE && options==0) {
result=input;
result.toTitle((BreakIterator *)iter, locale);
result.toTitle(static_cast<BreakIterator *>(iter), locale);
if(result!=output) {
dataerrln("error: UnicodeString.toTitle(options=0) got a wrong result for a test case from casing.res");
}
@ -475,7 +475,7 @@ StringCaseTest::TestCasingImpl(const UnicodeString &input,
#if !UCONFIG_NO_BREAK_ITERATION
if(iter!=nullptr) {
// Clone the break iterator so that the UCaseMap can safely adopt it.
UBreakIterator *clone=ubrk_safeClone((UBreakIterator *)iter, nullptr, nullptr, errorCode);
UBreakIterator *clone=ubrk_safeClone(static_cast<UBreakIterator *>(iter), nullptr, nullptr, errorCode);
ucasemap_setBreakIterator(csm.getAlias(), clone, errorCode);
}
#endif

View file

@ -241,7 +241,7 @@ CollatorInfo::~CollatorInfo() {
UnicodeString&
CollatorInfo::getDisplayName(const Locale& displayLocale, UnicodeString& name) const {
if (displayNames) {
UnicodeString* val = (UnicodeString*)displayNames->get(displayLocale.getName());
UnicodeString* val = static_cast<UnicodeString*>(displayNames->get(displayLocale.getName()));
if (val) {
name = *val;
return name;

View file

@ -87,7 +87,7 @@ void test_FieldPosition_example( void )
int32_t dNumSize = UPRV_LENGTHOF(doubleNum);
UErrorCode status = U_ZERO_ERROR;
DecimalFormat* fmt = (DecimalFormat*) NumberFormat::createInstance(status);
DecimalFormat* fmt = dynamic_cast<DecimalFormat*>(NumberFormat::createInstance(status));
if (U_FAILURE(status)) {
it_dataerrln("NumberFormat::createInstance() error");
return;

View file

@ -377,7 +377,7 @@ void CollationThaiTest::TestInvalidThai(void) {
return;
}
CollationElementIterator* c = ((RuleBasedCollator *)coll)->createCollationElementIterator( iteratorText );
CollationElementIterator* c = (dynamic_cast<RuleBasedCollator*>(coll))->createCollationElementIterator( iteratorText );
for(i = 0; i < UPRV_LENGTHOF(tests); i++) {
len = u_unescape(tests[i], strings[i], 20);

View file

@ -139,7 +139,7 @@ void TestMessageFormat::testBug3()
logln(locale[i].getDisplayName(buffer));
UErrorCode success = U_ZERO_ERROR;
// form = (DecimalFormat*)NumberFormat::createCurrencyInstance(locale[i], success);
form = (DecimalFormat*)NumberFormat::createInstance(locale[i], success);
form = dynamic_cast<DecimalFormat*>(NumberFormat::createInstance(locale[i], success));
if (U_FAILURE(success)) {
errln("Err: Number Format ");
logln("Number format creation failed.");

View file

@ -807,7 +807,7 @@ void TransliteratorAPITest::TestGetAdoptFilter(){
doTest(message, got, exp);
logln("Testing round trip");
t->adoptFilter((UnicodeFilter*)u);
t->adoptFilter(const_cast<UnicodeFilter*>(u));
if(t->getFilter() == nullptr)
logln("OK: adoptFilter and getFilter round trip worked");
else

View file

@ -544,7 +544,7 @@ void RTTest::test2(UBool quickRt, int32_t density) {
TransliteratorPointer sourceToTarget(
Transliterator::createInstance(transliteratorID, UTRANS_FORWARD, parseError,
status));
if ((Transliterator *)sourceToTarget == nullptr) {
if (sourceToTarget == nullptr) {
parent->dataerrln("FAIL: createInstance(" + transliteratorID +
") returned nullptr. Error: " + u_errorName(status)
+ "\n\tpreContext : " + prettify(parseError.preContext)
@ -553,7 +553,7 @@ void RTTest::test2(UBool quickRt, int32_t density) {
return;
}
TransliteratorPointer targetToSource(sourceToTarget->createInverse(status));
if ((Transliterator *)targetToSource == nullptr) {
if (targetToSource == nullptr) {
parent->errln("FAIL: " + transliteratorID +
".createInverse() returned nullptr. Error:" + u_errorName(status)
+ "\n\tpreContext : " + prettify(parseError.preContext)
@ -1332,7 +1332,7 @@ void TransliteratorRoundTripTest::TestDevanagariLatin() {
UErrorCode status = U_ZERO_ERROR;
UParseError parseError;
TransliteratorPointer t1(Transliterator::createInstance("[\\u0964-\\u0965\\u0981-\\u0983\\u0985-\\u098C\\u098F-\\u0990\\u0993-\\u09A8\\u09AA-\\u09B0\\u09B2\\u09B6-\\u09B9\\u09BC\\u09BE-\\u09C4\\u09C7-\\u09C8\\u09CB-\\u09CD\\u09D7\\u09DC-\\u09DD\\u09DF-\\u09E3\\u09E6-\\u09FA];NFD;Bengali-InterIndic;InterIndic-Gujarati;NFC;",UTRANS_FORWARD, parseError, status));
if((Transliterator *)t1 != nullptr){
if(t1 != nullptr){
TransliteratorPointer t2(t1->createInverse(status));
if(U_FAILURE(status)){
errln("FAIL: could not create the Inverse:-( \n");

View file

@ -254,7 +254,7 @@ IntlTestCollator::doTest(Collator* col, const UnicodeString &source, const Unico
}
UErrorCode status = U_ZERO_ERROR;
LocalPointer<CollationElementIterator> c(((RuleBasedCollator *)col)->createCollationElementIterator(source));
LocalPointer<CollationElementIterator> c((dynamic_cast<RuleBasedCollator *>(col))->createCollationElementIterator(source));
logln("Testing iterating source: "+source);
backAndForth(*c);
c->setText(target, status);

View file

@ -140,7 +140,7 @@ void
IntlTestDateFormat::describeTest()
{
// Assume it's a SimpleDateFormat and get some info
SimpleDateFormat *s = (SimpleDateFormat*)fFormat;
SimpleDateFormat *s = dynamic_cast<SimpleDateFormat*>(fFormat);
UnicodeString str;
logln(fTestName + " Pattern " + s->toPattern(str));
}

View file

@ -1088,7 +1088,7 @@ static std::condition_variable *gCTConditionVar = nullptr;
template<> U_EXPORT
const UCTMultiThreadItem *LocaleCacheKey<UCTMultiThreadItem>::createObject(
const void *context, UErrorCode &status) const {
const UnifiedCache *cacheContext = (const UnifiedCache *) context;
const UnifiedCache *cacheContext = static_cast<const UnifiedCache*>(context);
if (uprv_strcmp(fLoc.getLanguage(), fLoc.getName()) != 0) {
const UCTMultiThreadItem *result = nullptr;

View file

@ -178,7 +178,7 @@ IntlTestNumberFormat::testFormat(/* char* par */)
UnicodeString str;
// Assume it's a DecimalFormat and get some info
DecimalFormat *s = (DecimalFormat*)fFormat;
DecimalFormat *s = dynamic_cast<DecimalFormat*>(fFormat);
logln((UnicodeString)" Pattern " + s->toPattern(str));
#if U_PF_OS390 <= U_PLATFORM && U_PLATFORM <= U_PF_OS400
@ -422,7 +422,7 @@ void IntlTestNumberFormat::monsterTest(/* char* par */)
const char *SEP = "============================================================\n";
int32_t count;
const Locale* allLocales = NumberFormat::getAvailableLocales(count);
Locale* locales = (Locale*)allLocales;
Locale* locales = const_cast<Locale*>(allLocales);
Locale quickLocales[6];
if (allLocales && count)
{

View file

@ -134,7 +134,7 @@ void TimeUnitTest::testBasic() {
UnicodeString formatted;
Formattable formattable;
formattable.adoptObject(source);
formatted = ((Format*)formats[style])->format(formattable, formatted, status);
formatted = (dynamic_cast<Format*>(formats[style]))->format(formattable, formatted, status);
if (!assertSuccess("format()", status)) return;
#ifdef TUFMTTS_DEBUG
char formatResult[1000];
@ -142,16 +142,16 @@ void TimeUnitTest::testBasic() {
std::cout << "format result: " << formatResult << "\n";
#endif
Formattable result;
((Format*)formats[style])->parseObject(formatted, result, status);
(dynamic_cast<Format*>(formats[style]))->parseObject(formatted, result, status);
if (!assertSuccess("parseObject()", status)) return;
if (!tmaEqual(*((TimeUnitAmount *)result.getObject()), *((TimeUnitAmount *) formattable.getObject()))) {
if (!tmaEqual(*(dynamic_cast<const TimeUnitAmount*>(result.getObject())), *(dynamic_cast<const TimeUnitAmount*>(formattable.getObject())))) {
dataerrln("No round trip: ");
}
// other style parsing
Formattable result_1;
((Format*)formats[1-style])->parseObject(formatted, result_1, status);
(dynamic_cast<Format*>(formats[1-style]))->parseObject(formatted, result_1, status);
if (!assertSuccess("parseObject()", status)) return;
if (!tmaEqual(*((TimeUnitAmount *)result_1.getObject()), *((TimeUnitAmount *) formattable.getObject()))) {
if (!tmaEqual(*(dynamic_cast<const TimeUnitAmount*>(result_1.getObject())), *(dynamic_cast<const TimeUnitAmount*>(formattable.getObject())))) {
dataerrln("No round trip: ");
}
}
@ -410,7 +410,7 @@ void TimeUnitTest::testGreekWithFallback() {
UnicodeString str;
fmt.adoptObject(tamt.orphan());
str = ((Format *)tfmt.getAlias())->format(fmt, str, status);
str = (dynamic_cast<Format*>(tfmt.getAlias()))->format(fmt, str, status);
if (!assertSuccess("formatting relative time failed", status)) {
#ifdef TUFMTTS_DEBUG
std::cout << "Failed to format" << "\n";
@ -469,7 +469,7 @@ void TimeUnitTest::test10219Plurals() {
dataerrln("generating TimeUnitFormat Object failed: %s", u_errorName(status));
return;
}
LocalPointer<DecimalFormat> nf((DecimalFormat *) NumberFormat::createInstance(usLocale, status));
LocalPointer<DecimalFormat> nf(dynamic_cast<DecimalFormat*>(NumberFormat::createInstance(usLocale, status)));
if (U_FAILURE(status)) {
dataerrln("generating NumberFormat Object failed: %s", u_errorName(status));
return;

View file

@ -275,7 +275,7 @@ TimeZoneFormatTest::TestTimeZoneRoundTrip(void) {
status = U_ZERO_ERROR;
} else if (outtzid != canonical) {
// Canonical ID did not match - check the rules
if (!((BasicTimeZone*)&outtz)->hasEquivalentTransitions((BasicTimeZone&)*tz, low, high, true, status)) {
if (!(dynamic_cast<const BasicTimeZone*>(&outtz))->hasEquivalentTransitions(dynamic_cast<BasicTimeZone&>(*tz), low, high, true, status)) {
if (canonical.indexOf((char16_t)0x27 /*'/'*/) == -1) {
// Exceptional cases, such as CET, EET, MET and WET
logln((UnicodeString)"Canonical round trip failed (as expected); tz=" + *tzid
@ -613,7 +613,7 @@ void TimeZoneFormatTest::RunTimeRoundTripTests(int32_t threadNumber) {
continue;
}
BasicTimeZone *tz = (BasicTimeZone*) TimeZone::createTimeZone(*tzid);
BasicTimeZone *tz = dynamic_cast<BasicTimeZone*>(TimeZone::createTimeZone(*tzid));
sdf->setTimeZone(*tz);
UDate t = gLocaleData->START_TIME;

View file

@ -131,7 +131,7 @@ TimeZoneOffsetLocalTest::TestGetOffsetAroundTransition() {
// Set up TimeZone objects - OlsonTimeZone, SimpleTimeZone and RuleBasedTimeZone
BasicTimeZone *TESTZONES[NUM_TIMEZONES];
TESTZONES[0] = (BasicTimeZone*)TimeZone::createTimeZone("America/Los_Angeles");
TESTZONES[0] = dynamic_cast<BasicTimeZone*>(TimeZone::createTimeZone("America/Los_Angeles"));
TESTZONES[1] = new SimpleTimeZone(-8*HOUR, "Simple Pacific Time",
UCAL_APRIL, 1, UCAL_SUNDAY, 2*HOUR,
UCAL_OCTOBER, -1, UCAL_SUNDAY, 2*HOUR, status);

View file

@ -316,7 +316,7 @@ void TimeZoneRegressionTest:: Test4096952() {
*/
void TimeZoneRegressionTest:: Test4109314() {
UErrorCode status = U_ZERO_ERROR;
GregorianCalendar *testCal = (GregorianCalendar*)Calendar::createInstance(status);
GregorianCalendar *testCal = dynamic_cast<GregorianCalendar*>(Calendar::createInstance(status));
if(U_FAILURE(status)) {
dataerrln("Error creating calendar %s", u_errorName(status));
delete testCal;
@ -911,7 +911,7 @@ TimeZoneRegressionTest::Test4162593()
}
for(int32_t j = 0; j < 3; j++) {
TimeZone *tz = (TimeZone*)DATA_TZ[j];
TimeZone *tz = DATA_TZ[j];
TimeZone::setDefault(*tz);
fmt->setTimeZone(*tz);

View file

@ -428,7 +428,7 @@ TimeZoneRuleTest::TestHistoricalRuleBasedTimeZone(void) {
UErrorCode status = U_ZERO_ERROR;
// Compare to America/New_York with equivalent RBTZ
BasicTimeZone *ny = (BasicTimeZone*)TimeZone::createTimeZone("America/New_York");
BasicTimeZone *ny = dynamic_cast<BasicTimeZone*>(TimeZone::createTimeZone("America/New_York"));
//RBTZ
InitialTimeZoneRule *ir = new InitialTimeZoneRule("EST", -5*HOUR, 0);
@ -617,7 +617,7 @@ TimeZoneRuleTest::TestOlsonTransition(void) {
errln("FAIL: error returned while enumerating timezone IDs.");
break;
}
BasicTimeZone *tz = (BasicTimeZone*)TimeZone::createTimeZone(*tzid);
BasicTimeZone *tz = dynamic_cast<BasicTimeZone*>(TimeZone::createTimeZone(*tzid));
for (int32_t i = 0; TESTYEARS[i][0] != 0 || TESTYEARS[i][1] != 0; i++) {
UDate lo = getUTCMillis(TESTYEARS[i][0], UCAL_JANUARY, 1);
UDate hi = getUTCMillis(TESTYEARS[i][1], UCAL_JANUARY, 1);
@ -652,7 +652,7 @@ TimeZoneRuleTest::TestRBTZTransition(void) {
errln("FAIL: error returned while enumerating timezone IDs.");
break;
}
BasicTimeZone *tz = (BasicTimeZone*)TimeZone::createTimeZone(*tzid);
BasicTimeZone *tz = dynamic_cast<BasicTimeZone*>(TimeZone::createTimeZone(*tzid));
int32_t ruleCount = tz->countTransitionRules(status);
const InitialTimeZoneRule *initial;
@ -701,9 +701,9 @@ TimeZoneRuleTest::TestHasEquivalentTransitions(void) {
// America/New_York and America/Indiana/Indianapolis are equivalent
// since 2006
UErrorCode status = U_ZERO_ERROR;
BasicTimeZone *newyork = (BasicTimeZone*)TimeZone::createTimeZone("America/New_York");
BasicTimeZone *indianapolis = (BasicTimeZone*)TimeZone::createTimeZone("America/Indiana/Indianapolis");
BasicTimeZone *gmt_5 = (BasicTimeZone*)TimeZone::createTimeZone("Etc/GMT+5");
BasicTimeZone *newyork = dynamic_cast<BasicTimeZone*>(TimeZone::createTimeZone("America/New_York"));
BasicTimeZone *indianapolis = dynamic_cast<BasicTimeZone*>(TimeZone::createTimeZone("America/Indiana/Indianapolis"));
BasicTimeZone *gmt_5 = dynamic_cast<BasicTimeZone*>(TimeZone::createTimeZone("Etc/GMT+5"));
UDate jan1_1971 = getUTCMillis(1971, UCAL_JANUARY, 1);
UDate jan1_2005 = getUTCMillis(2005, UCAL_JANUARY, 1);
@ -754,7 +754,7 @@ TimeZoneRuleTest::TestHasEquivalentTransitions(void) {
// America/New_York and America/Los_Angeles has same DST start rules, but
// raw offsets are different
BasicTimeZone *losangeles = (BasicTimeZone*)TimeZone::createTimeZone("America/Los_Angeles");
BasicTimeZone *losangeles = dynamic_cast<BasicTimeZone*>(TimeZone::createTimeZone("America/Los_Angeles"));
if (newyork->hasEquivalentTransitions(*losangeles, jan1_2006, jan1_2011, true, status)) {
dataerrln("FAIL: New_York is not equivalent to Los Angeles, but returned true");
}
@ -789,7 +789,7 @@ TimeZoneRuleTest::TestVTimeZoneRoundTrip(void) {
errln("FAIL: error returned while enumerating timezone IDs.");
break;
}
BasicTimeZone *tz = (BasicTimeZone*)TimeZone::createTimeZone(*tzid);
BasicTimeZone *tz = dynamic_cast<BasicTimeZone*>(TimeZone::createTimeZone(*tzid));
VTimeZone *vtz_org = VTimeZone::createVTimeZoneByID(*tzid);
vtz_org->setTZURL("http://source.icu-project.org/timezone");
vtz_org->setLastModified(Calendar::getNow());
@ -889,7 +889,7 @@ TimeZoneRuleTest::TestVTimeZoneRoundTripPartial(void) {
errln("FAIL: error returned while enumerating timezone IDs.");
break;
}
BasicTimeZone *tz = (BasicTimeZone*)TimeZone::createTimeZone(*tzid);
BasicTimeZone *tz = dynamic_cast<BasicTimeZone*>(TimeZone::createTimeZone(*tzid));
VTimeZone *vtz_org = VTimeZone::createVTimeZoneByID(*tzid);
VTimeZone *vtz_new = nullptr;
UnicodeString vtzdata;
@ -1125,7 +1125,7 @@ TimeZoneRuleTest::TestGetSimpleRules(void) {
errln("FAIL: error returned while enumerating timezone IDs.");
break;
}
BasicTimeZone *tz = (BasicTimeZone*)TimeZone::createTimeZone(*tzid);
BasicTimeZone *tz = dynamic_cast<BasicTimeZone*>(TimeZone::createTimeZone(*tzid));
initial = nullptr;
std = dst = nullptr;
tz->getSimpleRulesNear(testTimes[i], initial, std, dst, status);
@ -1618,7 +1618,7 @@ TimeZoneRuleTest::TestVTimeZoneCoverage(void) {
UErrorCode status = U_ZERO_ERROR;
UnicodeString TZID("Europe/Moscow");
BasicTimeZone *otz = (BasicTimeZone*)TimeZone::createTimeZone(TZID);
BasicTimeZone *otz = dynamic_cast<BasicTimeZone*>(TimeZone::createTimeZone(TZID));
VTimeZone *vtz = VTimeZone::createVTimeZoneByID(TZID);
// getOffset(era, year, month, day, dayOfWeek, milliseconds, ec)

View file

@ -110,7 +110,7 @@ TimeZoneTest::TestGenericAPI()
SimpleTimeZone copy(*zone);
if (!(copy == *zone)) errln("FAIL: copy constructor or operator== failed");
copy = *(SimpleTimeZone*)zoneclone;
copy = *dynamic_cast<SimpleTimeZone*>(zoneclone);
if (!(copy == *zoneclone)) errln("FAIL: assignment operator or operator== failed");
TimeZone* saveDefault = TimeZone::createDefault();

View file

@ -29,7 +29,7 @@ rbUCA(nullptr),
testFile(nullptr),
status(U_ZERO_ERROR)
{
UCA = (RuleBasedCollator *)Collator::createInstance(Locale::getRoot(), status);
UCA = dynamic_cast<RuleBasedCollator*>(Collator::createInstance(Locale::getRoot(), status));
if(U_FAILURE(status)) {
dataerrln("Error - UCAConformanceTest: Unable to open UCA collator! - %s", u_errorName(status));
}

View file

@ -172,7 +172,7 @@ derivedPropsLineFn(void *context,
char *fields[][2], int32_t /* fieldCount */,
UErrorCode *pErrorCode)
{
UnicodeTest *me=(UnicodeTest *)context;
UnicodeTest *me=static_cast<UnicodeTest*>(context);
uint32_t start, end;
int32_t i;

View file

@ -34,7 +34,7 @@ U_NAMESPACE_BEGIN
template<> U_EXPORT
const UCTItem *LocaleCacheKey<UCTItem>::createObject(
const void *context, UErrorCode &status) const {
const UnifiedCache *cacheContext = (const UnifiedCache *) context;
const UnifiedCache *cacheContext = static_cast<const UnifiedCache *>(context);
if (uprv_strcmp(fLoc.getName(), "zh") == 0) {
status = U_MISSING_RESOURCE_ERROR;
return nullptr;

View file

@ -439,7 +439,7 @@ void unitsTestDataLineFn(void *context, char *fields[][2], int32_t fieldCount, U
if (U_FAILURE(*pErrorCode)) {
return;
}
UnitsTestContext *ctx = (UnitsTestContext *)context;
UnitsTestContext *ctx = static_cast<UnitsTestContext *>(context);
UnitsTest *unitsTest = ctx->unitsTest;
(void)fieldCount; // unused UParseLineFn variable
IcuTestErrorCode status(*unitsTest, "unitsTestDatalineFn");
@ -902,7 +902,7 @@ void checkOutput(UnitsTest *unitsTest, const char *msg, ExpectedOutput expected,
void unitPreferencesTestDataLineFn(void *context, char *fields[][2], int32_t fieldCount,
UErrorCode *pErrorCode) {
if (U_FAILURE(*pErrorCode)) return;
UnitsTest *unitsTest = (UnitsTest *)context;
UnitsTest *unitsTest = static_cast<UnitsTest *>(context);
IcuTestErrorCode status(*unitsTest, "unitPreferencesTestDatalineFn");
if (!unitsTest->assertTrue(u"unitPreferencesTestDataLineFn expects 9 fields for simple and 11 "

View file

@ -1635,7 +1635,7 @@ public:
* SymbolTable API
*/
virtual const UnicodeString* lookup(const UnicodeString& s) const override {
return (const UnicodeString*) contents.get(s);
return static_cast<const UnicodeString*>(contents.get(s));
}
/**

View file

@ -1264,7 +1264,7 @@ void UTextTest::FreezeTest() {
TEST_ASSERT(status == U_NO_WRITE_PERMISSION);
status = U_ZERO_ERROR;
ut = utext_openConstUnicodeString(ut, (const UnicodeString *)&ustr, &status);
ut = utext_openConstUnicodeString(ut, &ustr, &status);
TEST_SUCCESS(status);
writable = utext_isWritable(ut);
TEST_ASSERT(writable == false);
@ -1311,8 +1311,8 @@ void UTextTest::FreezeTest() {
U_CDECL_BEGIN
static UBool U_CALLCONV
fragTextAccess(UText *ut, int64_t index, UBool forward) {
const UnicodeString *us = (const UnicodeString *)ut->context;
char16_t c;
const UnicodeString *us = static_cast<const UnicodeString *>(ut->context);
char16_t c;
int32_t length = us->length();
if (forward && index>=0 && index<length) {
c = us->charAt((int32_t)index);
@ -1362,7 +1362,7 @@ cloneFragmentedUnicodeString(UText *dest, const UText *src, UBool deep, UErrorCo
*status = U_UNSUPPORTED_ERROR;
return nullptr;
}
dest = utext_openUnicodeString(dest, (UnicodeString *)src->context, status);
dest = utext_openUnicodeString(dest, static_cast<UnicodeString *>(const_cast<void*>(src->context)), status);
utext_setNativeIndex(dest, utext_getNativeIndex(src));
return dest;
}