From 499a3e2ac35e28ed553e2a2bd57b0712b58b3738 Mon Sep 17 00:00:00 2001 From: Markus Scherer Date: Sat, 17 Mar 2001 23:36:26 +0000 Subject: [PATCH] ICU-890 use improved fillOuput function from cpputils X-SVN-Rev: 4173 --- icu4c/source/i18n/ucal.cpp | 5 +--- icu4c/source/i18n/ucol.cpp | 4 +--- icu4c/source/i18n/ucol_bld.cpp | 2 +- icu4c/source/i18n/udat.cpp | 42 ++++++++++++---------------------- icu4c/source/i18n/umsg.cpp | 4 +--- icu4c/source/i18n/unum.cpp | 23 ++++--------------- icu4c/source/i18n/utrans.cpp | 10 ++++++-- 7 files changed, 31 insertions(+), 59 deletions(-) diff --git a/icu4c/source/i18n/ucal.cpp b/icu4c/source/i18n/ucal.cpp index c772b98886..8b2bdad1e6 100644 --- a/icu4c/source/i18n/ucal.cpp +++ b/icu4c/source/i18n/ucal.cpp @@ -132,8 +132,6 @@ ucal_getTimeZoneDisplayName(const UCalendar* cal, { if(U_FAILURE(*status)) return -1; - int32_t actLen; - const TimeZone& tz = ((Calendar*)cal)->getTimeZone(); UnicodeString id(result, 0, resultLength); @@ -155,8 +153,7 @@ ucal_getTimeZoneDisplayName(const UCalendar* cal, break; } - T_fillOutputParams(&id, result, resultLength, &actLen, status); - return actLen; + return uprv_fillOutputString(id, result, resultLength, status); } U_CAPI UBool diff --git a/icu4c/source/i18n/ucol.cpp b/icu4c/source/i18n/ucol.cpp index cf00a21900..bc78687cf0 100644 --- a/icu4c/source/i18n/ucol.cpp +++ b/icu4c/source/i18n/ucol.cpp @@ -2567,9 +2567,7 @@ ucol_getDisplayName( const char *objLoc, if(U_FAILURE(*status)) return -1; UnicodeString dst(result, resultLength, resultLength); Collator::getDisplayName(Locale(objLoc), Locale(dispLoc), dst); - int32_t actLen; - T_fillOutputParams(&dst, result, resultLength, &actLen, status); - return actLen; + return uprv_fillOutputString(dst, result, resultLength, status); } U_CAPI const char* diff --git a/icu4c/source/i18n/ucol_bld.cpp b/icu4c/source/i18n/ucol_bld.cpp index 788c1765a6..51b25ab769 100644 --- a/icu4c/source/i18n/ucol_bld.cpp +++ b/icu4c/source/i18n/ucol_bld.cpp @@ -620,7 +620,7 @@ int32_t uprv_ucol_decompose (UChar curChar, UChar *result) { /*hangul ? Normalizer::IGNORE_HANGUL : 0,*/ Normalizer::IGNORE_HANGUL, res, status); - T_fillOutputParams(&res, result, 356, &resSize, &status); + resSize = uprv_fillOutputString(res, result, 356, &status); } else { const UChar *source = (const UChar*)&(DecompData::contents); diff --git a/icu4c/source/i18n/udat.cpp b/icu4c/source/i18n/udat.cpp index 9c4442b37b..dfad714008 100644 --- a/icu4c/source/i18n/udat.cpp +++ b/icu4c/source/i18n/udat.cpp @@ -119,8 +119,6 @@ udat_format( const UDateFormat* format, { if(U_FAILURE(*status)) return -1; - int32_t actLen; - UnicodeString res(result, 0, resultLength); FieldPosition fp; @@ -128,14 +126,13 @@ udat_format( const UDateFormat* format, fp.setField(position->field); ((DateFormat*)format)->format(dateToFormat, res, fp); - T_fillOutputParams(&res, result, resultLength, &actLen, status); if(position != 0) { position->beginIndex = fp.getBeginIndex(); position->endIndex = fp.getEndIndex(); } - return actLen; + return uprv_fillOutputString(res, result, resultLength, status); } U_CAPI UDate @@ -246,8 +243,6 @@ udat_toPattern( const UDateFormat *fmt, { if(U_FAILURE(*status)) return -1; - int32_t actLen; - UnicodeString res(result, 0, resultLength); if(localized) @@ -255,8 +250,7 @@ udat_toPattern( const UDateFormat *fmt, else ((SimpleDateFormat*)fmt)->toPattern(res); - T_fillOutputParams(&res, result, resultLength, &actLen, status); - return actLen; + return uprv_fillOutputString(res, result, resultLength, status); } // TBD: should this take an UErrorCode? @@ -286,71 +280,63 @@ udat_getSymbols(const UDateFormat *fmt, { if(U_FAILURE(*status)) return -1; - int32_t actLen = 0; - const DateFormatSymbols *syms = ((SimpleDateFormat*)fmt)->getDateFormatSymbols(); int32_t count; const UnicodeString *res; - UnicodeString res1(result, 0, resultLength); - switch(type) { case UDAT_ERAS: res = syms->getEras(count); if(index < count) { - T_fillOutputParams(&res[index], result, resultLength, - &actLen, status); + return uprv_fillOutputString(res[index], result, resultLength, status); } break; case UDAT_MONTHS: res = syms->getMonths(count); if(index < count) { - T_fillOutputParams(&res[index], result, resultLength, - &actLen, status); + return uprv_fillOutputString(res[index], result, resultLength, status); } break; case UDAT_SHORT_MONTHS: res = syms->getShortMonths(count); if(index < count) { - T_fillOutputParams(&res[index], result, resultLength, - &actLen, status); + return uprv_fillOutputString(res[index], result, resultLength, status); } break; case UDAT_WEEKDAYS: res = syms->getWeekdays(count); if(index < count) { - T_fillOutputParams(&res[index], result, resultLength, - &actLen, status); + return uprv_fillOutputString(res[index], result, resultLength, status); } break; case UDAT_SHORT_WEEKDAYS: res = syms->getShortWeekdays(count); if(index < count) { - T_fillOutputParams(&res[index], result, resultLength, - &actLen, status); + return uprv_fillOutputString(res[index], result, resultLength, status); } break; case UDAT_AM_PMS: res = syms->getAmPmStrings(count); if(index < count) { - T_fillOutputParams(&res[index], result, resultLength, - &actLen, status); + return uprv_fillOutputString(res[index], result, resultLength, status); } break; case UDAT_LOCALIZED_CHARS: - syms->getLocalPatternChars(res1); - T_fillOutputParams(&res1, result, resultLength, &actLen, status); - break; + { + UnicodeString res1(result, 0, resultLength); + syms->getLocalPatternChars(res1); + return uprv_fillOutputString(res1, result, resultLength, status); + } } - return actLen; + return 0; } U_CAPI int32_t diff --git a/icu4c/source/i18n/umsg.cpp b/icu4c/source/i18n/umsg.cpp index 037668f4f3..43df47158c 100644 --- a/icu4c/source/i18n/umsg.cpp +++ b/icu4c/source/i18n/umsg.cpp @@ -273,7 +273,6 @@ u_vformatMessage( const char *locale, if(U_FAILURE(*status)) return -1; int32_t patLen = (patternLength == -1 ? u_strlen(pattern) : patternLength); - int32_t actLen; // ======================================== // Begin pseudo-parser @@ -416,8 +415,7 @@ u_vformatMessage( const char *locale, FieldPosition fp; fmt.format(args, count, res, fp, *status); - T_fillOutputParams(&res, result, resultLength, &actLen, status); - return actLen; + return uprv_fillOutputString(res, result, resultLength, status); } // For parse, do the reverse of format: diff --git a/icu4c/source/i18n/unum.cpp b/icu4c/source/i18n/unum.cpp index 4c878f3f8d..507c373ac7 100644 --- a/icu4c/source/i18n/unum.cpp +++ b/icu4c/source/i18n/unum.cpp @@ -141,8 +141,6 @@ unum_format( const UNumberFormat* fmt, { if(U_FAILURE(*status)) return -1; - int32_t actSize; - UnicodeString res(result, 0, resultLength); FieldPosition fp; @@ -150,14 +148,13 @@ unum_format( const UNumberFormat* fmt, fp.setField(pos->field); ((NumberFormat*)fmt)->format(number, res, fp); - T_fillOutputParams(&res, result, resultLength, &actSize, status); if(pos != 0) { pos->beginIndex = fp.getBeginIndex(); pos->endIndex = fp.getEndIndex(); } - return actSize; + return uprv_fillOutputString(res, result, resultLength, status); } U_CAPI int32_t @@ -170,8 +167,6 @@ unum_formatDouble( const UNumberFormat* fmt, { if(U_FAILURE(*status)) return -1; - int32_t actSize; - UnicodeString res(result, 0, resultLength); FieldPosition fp; @@ -179,14 +174,13 @@ unum_formatDouble( const UNumberFormat* fmt, fp.setField(pos->field); ((NumberFormat*)fmt)->format(number, res, fp); - T_fillOutputParams(&res, result, resultLength, &actSize, status); if(pos != 0) { pos->beginIndex = fp.getBeginIndex(); pos->endIndex = fp.getEndIndex(); } - return actSize; + return uprv_fillOutputString(res, result, resultLength, status); } U_CAPI int32_t @@ -432,8 +426,6 @@ unum_getTextAttribute( const UNumberFormat* fmt, if(U_FAILURE(*status)) return -1; - int32_t actSize = 0; - UnicodeString res(result, 0, resultLength); switch(tag) { @@ -455,7 +447,7 @@ unum_getTextAttribute( const UNumberFormat* fmt, case UNUM_PADDING_CHARACTER: *result = ((DecimalFormat*)fmt)->getPadCharacter(); - actSize = 1; + return 1; break; default: @@ -463,9 +455,7 @@ unum_getTextAttribute( const UNumberFormat* fmt, return -1; } - if (actSize != 1) - T_fillOutputParams(&res, result, resultLength, &actSize, status); - return actSize; + return uprv_fillOutputString(res, result, resultLength, status); } U_CAPI void @@ -516,8 +506,6 @@ unum_toPattern( const UNumberFormat* fmt, { if(U_FAILURE(*status)) return -1; - int32_t actSize; - UnicodeString pat(result, 0, resultLength); if(isPatternLocalized) @@ -525,8 +513,7 @@ unum_toPattern( const UNumberFormat* fmt, else ((DecimalFormat*)fmt)->toPattern(pat); - T_fillOutputParams(&pat, result, resultLength, &actSize, status); - return actSize; + return uprv_fillOutputString(pat, result, resultLength, status); } U_CAPI void diff --git a/icu4c/source/i18n/utrans.cpp b/icu4c/source/i18n/utrans.cpp index 5e80d457ea..f86a688a1f 100644 --- a/icu4c/source/i18n/utrans.cpp +++ b/icu4c/source/i18n/utrans.cpp @@ -351,7 +351,10 @@ utrans_transUChars(const UTransliterator* trans, // Copy the string buffer back to text (only if necessary) // and fill in *neededCapacity (if neededCapacity != NULL). - T_fillOutputParams(&str, text, textCapacity, textLength, status); + textLen = uprv_fillOutputString(str, text, textCapacity, status); + if(textLength != NULL) { + *textLength = textLen; + } } U_CAPI void @@ -378,5 +381,8 @@ utrans_transIncrementalUChars(const UTransliterator* trans, // Copy the string buffer back to text (only if necessary) // and fill in *neededCapacity (if neededCapacity != NULL). - T_fillOutputParams(&str, text, textCapacity, textLength, status); + textLen = uprv_fillOutputString(str, text, textCapacity, status); + if(textLength != NULL) { + *textLength = textLen; + } }