ICU-6235 UnicodeSet to USet conversions

X-SVN-Rev: 25555
This commit is contained in:
Andy Heninger 2009-03-12 00:38:53 +00:00
parent 2cc78d6fce
commit 72cf0f3d06
2 changed files with 70 additions and 2 deletions

View File

@ -1,6 +1,6 @@
/*
***************************************************************************
* Copyright (C) 1999-2008, International Business Machines Corporation
* Copyright (C) 1999-2009, International Business Machines Corporation
* and others. All Rights Reserved.
***************************************************************************
* Date Name Description
@ -470,6 +470,44 @@ public:
*/
virtual int32_t hashCode(void) const;
/**
* Get a UnicodeSet pointer from a USet
*
* @param uset a USet (the ICU plain C type for UnicodeSet)
* @return the corresponding UnicodeSet pointer.
*
* @draft ICU 4.2
*/
inline static UnicodeSet *fromUSet(USet *uset);
/**
* Get a UnicodeSet pointer from a const USet
*
* @param uset a const USet (the ICU plain C type for UnicodeSet)
* @return the corresponding UnicodeSet pointer.
*
* @draft ICU 4.2
*/
inline static const UnicodeSet *fromUSet(const USet *uset);
/**
* Produce a USet * pointer for this UnicodeSet.
* USet is the plain C type for UnicodeSet
*
* @return a USet pointer for this UnicodeSet
*/
inline USet *toUSet();
/**
* Produce a const USet * pointer for this UnicodeSet.
* USet is the plain C type for UnicodeSet
*
* @return a const USet pointer for this UnicodeSet
*/
inline const USet * toUSet() const;
//----------------------------------------------------------------
// Freezable API
//----------------------------------------------------------------
@ -1537,6 +1575,8 @@ private:
friend class UnicodeSetIterator;
};
inline UBool UnicodeSet::operator!=(const UnicodeSet& o) const {
return !operator==(o);
}
@ -1561,6 +1601,22 @@ inline UBool UnicodeSet::isBogus() const {
return (UBool)(fFlags & kIsBogus);
}
inline UnicodeSet *UnicodeSet::fromUSet(USet *uset) {
return reinterpret_cast<UnicodeSet *>(uset);
}
inline const UnicodeSet *UnicodeSet::fromUSet(const USet *uset) {
return reinterpret_cast<const UnicodeSet *>(uset);
}
inline USet *UnicodeSet::toUSet() {
return reinterpret_cast<USet *>(this);
}
inline const USet *UnicodeSet::toUSet() const {
return reinterpret_cast<const USet *>(this);
}
U_NAMESPACE_END
#endif

View File

@ -1,6 +1,6 @@
/*
********************************************************************************
* Copyright (C) 1999-2008 International Business Machines Corporation and
* Copyright (C) 1999-2009 International Business Machines Corporation and
* others. All Rights Reserved.
********************************************************************************
* Date Name Description
@ -696,6 +696,18 @@ void UnicodeSetTest::TestAPI() {
errln("FAIL: serialize");
return;
}
// Conversions to and from USet
UnicodeSet *uniset = &set;
USet *uset = uniset->toUSet();
TEST_ASSERT((void *)uset == (void *)uniset);
UnicodeSet *setx = UnicodeSet::fromUSet(uset);
TEST_ASSERT((void *)setx == (void *)uset);
const UnicodeSet *constSet = uniset;
const USet *constUSet = constSet->toUSet();
TEST_ASSERT((void *)constUSet == (void *)constSet);
const UnicodeSet *constSetx = UnicodeSet::fromUSet(constUSet);
TEST_ASSERT((void *)constSetx == (void *)constUSet);
}
void UnicodeSetTest::TestIteration() {