mirror of
https://github.com/unicode-org/icu.git
synced 2025-04-07 06:25:30 +00:00
ICU-770 Memory cleanup
X-SVN-Rev: 6047
This commit is contained in:
parent
976a799ee9
commit
fefbf9b930
9 changed files with 52 additions and 32 deletions
|
@ -10,10 +10,9 @@
|
|||
|
||||
#include "unicode/name2uni.h"
|
||||
#include "unicode/unifilt.h"
|
||||
#include "unicode/unicode.h"
|
||||
#include "unicode/convert.h"
|
||||
#include "unicode/uchar.h"
|
||||
|
||||
const char* NameUnicodeTransliterator::_ID = "Name-Any";
|
||||
const char NameUnicodeTransliterator::_ID[] = "Name-Any";
|
||||
|
||||
// As of Unicode 3.0.0, the longest name is 83 characters long.
|
||||
#define LONGEST_NAME 83
|
||||
|
@ -95,8 +94,6 @@ void NameUnicodeTransliterator::handleTransliterate(Replaceable& text, UTransPos
|
|||
|
||||
UnicodeString str;
|
||||
|
||||
UnicodeConverter converter; // default converter
|
||||
|
||||
for (; cursor < limit; ++cursor) {
|
||||
UChar c = text.charAt(cursor);
|
||||
|
||||
|
@ -114,7 +111,7 @@ void NameUnicodeTransliterator::handleTransliterate(Replaceable& text, UTransPos
|
|||
// to a single space. If closeDelimiter is found, exit
|
||||
// the loop. If any other character is found, exit the
|
||||
// loop. If the limit is found, exit the loop.
|
||||
if (Unicode::isWhitespace(c)) {
|
||||
if (u_isWhitespace(c)) {
|
||||
// Ignore leading whitespace
|
||||
if (ibuf != 0 && buf[ibuf-1] != (UChar)0x0020) {
|
||||
buf[ibuf++] = (UChar)0x0020 /* */;
|
||||
|
@ -135,11 +132,7 @@ void NameUnicodeTransliterator::handleTransliterate(Replaceable& text, UTransPos
|
|||
UErrorCode status = U_ZERO_ERROR;
|
||||
|
||||
// Convert UChar to char
|
||||
char *out = cbuf;
|
||||
const UChar *in = buf;
|
||||
converter.fromUnicode(out, cbuf+sizeof(cbuf),
|
||||
in, buf+ibuf, NULL, TRUE, status);
|
||||
*out = 0;
|
||||
u_UCharsToChars(buf, cbuf, ibuf+1);
|
||||
|
||||
UChar32 ch = u_charFromName(U_UNICODE_CHAR_NAME, cbuf, &status);
|
||||
if (ch != (UChar32) 0xFFFF && U_SUCCESS(status)) {
|
||||
|
|
|
@ -66,6 +66,6 @@ class U_I18N_API NameUnicodeTransliterator : public Transliterator {
|
|||
|
||||
private:
|
||||
|
||||
static const char* _ID;
|
||||
static const char _ID[];
|
||||
};
|
||||
#endif
|
||||
|
|
|
@ -139,6 +139,9 @@ static void Test_UChar_UTF32_API(void){
|
|||
|
||||
u_strToUTF32(u32Target,u32TargetLength, &u32DestLen, uSrc, uSrcLen,&err);
|
||||
}
|
||||
else {
|
||||
log_err("Should have gotten U_BUFFER_OVERFLOW_ERROR");
|
||||
}
|
||||
failed = FALSE;
|
||||
/*for(i=0; i< u32DestLen; i++){
|
||||
printf("0x%08X, ",uTarget[i]);
|
||||
|
@ -193,7 +196,7 @@ static void Test_UChar_UTF32_API(void){
|
|||
failed = FALSE;
|
||||
|
||||
/* preflight */
|
||||
u_strToUTF32(u32Target,u32TargetLength, &u32DestLen, uSrc, uSrcLen,&err);
|
||||
u_strToUTF32(NULL,u32TargetLength, &u32DestLen, uSrc, uSrcLen,&err);
|
||||
if(err = U_BUFFER_OVERFLOW_ERROR){
|
||||
err = U_ZERO_ERROR;
|
||||
u32Target = (uint32_t*) malloc (sizeof(uint32_t) * (u32DestLen+1));
|
||||
|
@ -201,6 +204,9 @@ static void Test_UChar_UTF32_API(void){
|
|||
|
||||
u_strToUTF32(u32Target,u32TargetLength, &u32DestLen, uSrc, uSrcLen,&err);
|
||||
}
|
||||
else {
|
||||
log_err("Should have gotten U_BUFFER_OVERFLOW_ERROR");
|
||||
}
|
||||
failed = FALSE;
|
||||
|
||||
for(i=0; i< u32SrcLen; i++){
|
||||
|
@ -214,7 +220,7 @@ static void Test_UChar_UTF32_API(void){
|
|||
}
|
||||
|
||||
/* preflight */
|
||||
u_strFromUTF32(uTarget,uTargetLength,&uDestLen,u32Src,u32SrcLen,&err);
|
||||
u_strFromUTF32(NULL,uTargetLength,&uDestLen,u32Src,u32SrcLen,&err);
|
||||
if(err = U_BUFFER_OVERFLOW_ERROR){
|
||||
err = U_ZERO_ERROR;
|
||||
uTarget = (UChar*) malloc( sizeof(UChar) * (uDestLen+1));
|
||||
|
@ -267,6 +273,9 @@ static void Test_UChar_UTF8_API(void){
|
|||
u_strToUTF8(u8Target,u8TargetLength, &u8DestLen, uSrc, uSrcLen,&err);
|
||||
|
||||
}
|
||||
else {
|
||||
log_err("Should have gotten U_BUFFER_OVERFLOW_ERROR");
|
||||
}
|
||||
failed = FALSE;
|
||||
/*for(i=0; i< u8DestLen; i++){
|
||||
printf("0x%04X, ",u8Target[i]);
|
||||
|
@ -295,6 +304,9 @@ static void Test_UChar_UTF8_API(void){
|
|||
|
||||
u_strFromUTF8(uTarget,uTargetLength,&uDestLen,u8Src,u8SrcLen,&err);
|
||||
}
|
||||
else {
|
||||
log_err("Should have gotten U_BUFFER_OVERFLOW_ERROR");
|
||||
}
|
||||
/*for(i=0; i< uDestLen; i++){
|
||||
printf("0x%04X, ",uTarget[i]);
|
||||
if(i%10==0){
|
||||
|
@ -322,7 +334,7 @@ static void Test_UChar_UTF8_API(void){
|
|||
u8TargetLength=0;
|
||||
failed = FALSE;
|
||||
/* preflight */
|
||||
u_strToUTF8(u8Target,u8TargetLength, &u8DestLen, uSrc, uSrcLen,&err);
|
||||
u_strToUTF8(NULL,u8TargetLength, &u8DestLen, uSrc, uSrcLen,&err);
|
||||
if(err == U_BUFFER_OVERFLOW_ERROR){
|
||||
err = U_ZERO_ERROR;
|
||||
u8Target = (uint8_t*) malloc (sizeof(uint8_t) * (u8DestLen+1));
|
||||
|
@ -331,6 +343,9 @@ static void Test_UChar_UTF8_API(void){
|
|||
u_strToUTF8(u8Target,u8TargetLength, &u8DestLen, uSrc, uSrcLen,&err);
|
||||
|
||||
}
|
||||
else {
|
||||
log_err("Should have gotten U_BUFFER_OVERFLOW_ERROR");
|
||||
}
|
||||
failed = FALSE;
|
||||
/*for(i=0; i< u8DestLen; i++){
|
||||
printf("0x%04X, ",u8Target[i]);
|
||||
|
@ -351,7 +366,7 @@ static void Test_UChar_UTF8_API(void){
|
|||
u8SrcLen = u8DestLen;
|
||||
|
||||
/* preflight */
|
||||
u_strFromUTF8(uTarget,uTargetLength,&uDestLen,u8Src,u8SrcLen,&err);
|
||||
u_strFromUTF8(NULL,uTargetLength,&uDestLen,u8Src,u8SrcLen,&err);
|
||||
if(err == U_BUFFER_OVERFLOW_ERROR){
|
||||
err = U_ZERO_ERROR;
|
||||
uTarget = (UChar*) malloc( sizeof(UChar) * (uDestLen+1));
|
||||
|
@ -359,6 +374,9 @@ static void Test_UChar_UTF8_API(void){
|
|||
|
||||
u_strFromUTF8(uTarget,uTargetLength,&uDestLen,u8Src,u8SrcLen,&err);
|
||||
}
|
||||
else {
|
||||
log_err("Should have gotten U_BUFFER_OVERFLOW_ERROR");
|
||||
}
|
||||
/*for(i=0; i< uDestLen; i++){
|
||||
printf("0x%04X, ",uTarget[i]);
|
||||
if(i%10==0){
|
||||
|
|
|
@ -146,12 +146,13 @@ void ConvertTest::TestConvert()
|
|||
errln("Error getting Available names!");
|
||||
return;
|
||||
}
|
||||
logln("Number of available Codepages:\t" + testLong1);
|
||||
while (testLong1--) logln((UnicodeString)"\t\t[" + available_conv[testLong1] + (UnicodeString)"]");
|
||||
logln("Number of available Codepages:%d\t", testLong1);
|
||||
while (testLong1--)
|
||||
logln("\t\t[%s]", available_conv[testLong1]);
|
||||
|
||||
ucnv_flushCache();
|
||||
|
||||
/* Do some tests w/ UnicodeConverter, some w/ UnicodeConverterCPP */
|
||||
/* Do some tests w/ UnicodeConverter, some w/ UnicodeConverter */
|
||||
|
||||
someConverters[0] = new UnicodeConverter("ibm-1123",err);
|
||||
if (U_FAILURE(err)) {
|
||||
|
@ -169,12 +170,12 @@ void ConvertTest::TestConvert()
|
|||
return;
|
||||
}
|
||||
|
||||
someConverters[3] = new UnicodeConverterCPP("ibm-834", err);
|
||||
someConverters[3] = new UnicodeConverter("ibm-834", err);
|
||||
if (U_FAILURE(err)) {
|
||||
errln ((UnicodeString)"FAILURE! " + myErrorName(err));
|
||||
return;
|
||||
}
|
||||
someConverters[4] = new UnicodeConverterCPP("ibm-941", err);
|
||||
someConverters[4] = new UnicodeConverter("ibm-941", err);
|
||||
if (U_FAILURE(err)) {
|
||||
errln ((UnicodeString)"FAILURE! " + myErrorName(err));
|
||||
return;
|
||||
|
|
|
@ -176,12 +176,12 @@ void DateFormatRegressionTest::Test4052408(void)
|
|||
fmt->format(dt, buf, pos);
|
||||
//char[] dst = new char[pos.getEndIndex() - pos.getBeginIndex()];
|
||||
UnicodeString dst;
|
||||
buf.extractBetween(pos.getBeginIndex(), pos.getEndIndex(), dst);
|
||||
buf.extractBetween(pos.getBeginIndex(), pos.getEndIndex(), dst);
|
||||
UnicodeString str(dst);
|
||||
log(i + ": " + fieldNames[i] +
|
||||
", \"" + str + "\", " +
|
||||
pos.getBeginIndex() + ", " +
|
||||
pos.getEndIndex());
|
||||
logln((UnicodeString)"" + i + (UnicodeString)": " + fieldNames[i] +
|
||||
(UnicodeString)", \"" + str + (UnicodeString)"\", " +
|
||||
pos.getBeginIndex() + (UnicodeString)", " +
|
||||
pos.getEndIndex());
|
||||
UnicodeString exp = expected[i];
|
||||
if((exp.length() == 0 && str.length() == 0) || str == exp)
|
||||
logln(" ok");
|
||||
|
@ -189,11 +189,11 @@ void DateFormatRegressionTest::Test4052408(void)
|
|||
logln(UnicodeString(" expected ") + exp);
|
||||
pass = FALSE;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
if( ! pass)
|
||||
errln("Fail: FieldPosition not set right by DateFormat");
|
||||
|
||||
|
||||
delete fmt;
|
||||
}
|
||||
|
||||
|
|
|
@ -1058,6 +1058,8 @@ main(int argc, char* argv[])
|
|||
This is done in the wrong order on purpose.
|
||||
Normally this should happen first */
|
||||
CalendarTimeZoneTest::cleanup();
|
||||
delete _testDirectory;
|
||||
_testDirectory = 0;
|
||||
|
||||
fprintf(stdout, "\n--------------------------------------\n");
|
||||
if (major.getErrors() == 0) {
|
||||
|
|
|
@ -136,12 +136,20 @@ const char* rawData[27][7] = {
|
|||
#define test_dumpLocale(l) { UnicodeString s(l.getName(),""); logln(#l + UnicodeString(" = ") + s); }
|
||||
|
||||
LocaleTest::LocaleTest()
|
||||
: dataTable(NULL)
|
||||
{
|
||||
setUpDataTable();
|
||||
}
|
||||
|
||||
LocaleTest::~LocaleTest()
|
||||
{
|
||||
if (dataTable != 0) {
|
||||
for (int32_t i = 0; i < 27; i++) {
|
||||
delete []dataTable[i];
|
||||
}
|
||||
delete []dataTable;
|
||||
dataTable = 0;
|
||||
}
|
||||
}
|
||||
|
||||
#define CASE(id,test) case id: name = #test; if (exec) { logln(#test "---"); logln((UnicodeString)""); test(); } break;
|
||||
|
@ -697,8 +705,6 @@ void LocaleTest::doTestDisplayNames(Locale& inLocale,
|
|||
// table of valid data
|
||||
//---------------------------------------------------
|
||||
|
||||
UnicodeString** LocaleTest::dataTable = 0;
|
||||
|
||||
|
||||
UChar greekDisplayLanguage[] = { 0x03b5, 0x03bb, 0x03bb, 0x03b7, 0x03bd, 0x03b9, 0x03ba, 0x03ac, 0 };
|
||||
UChar greekDisplayCountry[] = { 0x0395, 0x03bb, 0x03bb, 0x03ac, 0x03b4, 0x03b1, 0 };
|
||||
|
|
|
@ -79,7 +79,7 @@ private:
|
|||
**/
|
||||
void setUpDataTable(void);
|
||||
|
||||
static UnicodeString** dataTable;
|
||||
UnicodeString** dataTable;
|
||||
|
||||
enum {
|
||||
ENGLISH = 0,
|
||||
|
|
|
@ -1194,7 +1194,7 @@ void RBBITest::doMultipleSelectionTest(RuleBasedBreakIterator& iterator,
|
|||
int32_t testOffset;
|
||||
int32_t count = 0;
|
||||
|
||||
logln("doMultipleSelectionTest text of length: "+testText.length());
|
||||
logln("doMultipleSelectionTest text of length: %d", testText.length());
|
||||
|
||||
if (*testIterator != iterator)
|
||||
errln("clone() or operator!= failed: two clones compared unequal");
|
||||
|
|
Loading…
Add table
Reference in a new issue