ICU-1262 make US::setToBogus() public and test it

X-SVN-Rev: 6107
This commit is contained in:
Markus Scherer 2001-10-05 23:53:00 +00:00
parent cfd74e2af7
commit 9f61db5f73
2 changed files with 39 additions and 4 deletions

View file

@ -1424,6 +1424,7 @@ public:
/**
* Determine if this string is still valid.
* @return TRUE if the string is valid, FALSE otherwise
* @see setToBogus()
* @draft
*/
inline UBool isBogus(void) const;
@ -1565,6 +1566,29 @@ public:
int32_t buffLength,
int32_t buffCapacity);
/**
* Make this UnicodeString object invalid.
* The string will test TRUE with isBogus().
*
* This is used to indicate that an operation failed, and that
* the result string is "bogus" - which can be tested with isBogus().
* This utility function is used throughout the UnicodeString
* implementation, and may be used in other functions,
* especially but not exclusively when such functions do not
* take a UErrorCode for simplicity.
*
* A "bogus" string is essentially empty, and getBuffer() const
* will return 0.
*
* The string object can be "revived" by assigning (operator=)
* another string, or by using one of the other setToXYZ functions,
* or simply by modifying it (which will work like with an empty string).
*
* @see isBogus()
* @draft ICU 2.0 was private in earlier releases
*/
void setToBogus();
/**
* Set the character at the specified offset to the specified character.
* @param offset A valid offset into the text of the character to set
@ -2603,9 +2627,6 @@ private:
// release the array if owned
inline void releaseArray();
// utility method to get around lack of exception handling
void setToBogus(void);
// Pin start and limit to acceptable values.
inline void pinIndices(UTextOffset& start,
int32_t& length) const;

View file

@ -951,8 +951,10 @@ UnicodeStringTest::TestMiscellaneous()
UnicodeString test2("This is a test");
UnicodeString test3("Me too!");
if (test1.isBogus() || test2.isBogus() || test3.isBogus())
// test isBogus() and setToBogus()
if (test1.isBogus() || test2.isBogus() || test3.isBogus()) {
errln("A string returned TRUE for isBogus()!");
}
test3.setTo(FALSE, (const UChar *)0, -1);
if(!test3.isBogus()) {
@ -962,6 +964,18 @@ UnicodeStringTest::TestMiscellaneous()
if (test1.hashCode() != test2.hashCode() || test1.hashCode() == test3.hashCode())
errln("hashCode() failed");
if(test3.getBuffer()!=0) {
errln("bogus.getBuffer()!=0");
}
test3.append((UChar)0x61);
if(test3.isBogus() || test3.getBuffer()==0) {
errln("Unable to revive a bogus string");
}
test3.setToBogus();
if(!test3.isBogus() || test3.getBuffer()!=0) {
errln("setToBogus() failed to make a string bogus");
}
// test getBuffer(minCapacity) and releaseBuffer()
test1=UnicodeString(); // make sure that it starts with its stackBuffer
UChar *p=test1.getBuffer(20);