]> granicus.if.org Git - icu/commitdiff
ICU-7877 optionally explicit UnicodeString constructors, and make them explicit insid...
authorMarkus Scherer <markus.icu@gmail.com>
Thu, 7 Jul 2011 18:46:19 +0000 (18:46 +0000)
committerMarkus Scherer <markus.icu@gmail.com>
Thu, 7 Jul 2011 18:46:19 +0000 (18:46 +0000)
X-SVN-Rev: 30293

41 files changed:
icu4c/source/common/rbbiscan.cpp
icu4c/source/common/unicode/unistr.h
icu4c/source/common/uniset_props.cpp
icu4c/source/i18n/alphaindex.cpp
icu4c/source/i18n/anytrans.cpp
icu4c/source/i18n/cpdtrans.cpp
icu4c/source/i18n/currpinf.cpp
icu4c/source/i18n/dcfmtsym.cpp
icu4c/source/i18n/decimfmt.cpp
icu4c/source/i18n/dtitvfmt.cpp
icu4c/source/i18n/dtitvinf.cpp
icu4c/source/i18n/esctrn.cpp
icu4c/source/i18n/funcrepl.cpp
icu4c/source/i18n/msgfmt.cpp
icu4c/source/i18n/nfrs.cpp
icu4c/source/i18n/nfrule.cpp
icu4c/source/i18n/nfsubs.cpp
icu4c/source/i18n/numfmt.cpp
icu4c/source/i18n/numsys.cpp
icu4c/source/i18n/plurrule.cpp
icu4c/source/i18n/rbnf.cpp
icu4c/source/i18n/rbt_pars.cpp
icu4c/source/i18n/rbt_rule.cpp
icu4c/source/i18n/remtrans.cpp
icu4c/source/i18n/simpletz.cpp
icu4c/source/i18n/smpdtfmt.cpp
icu4c/source/i18n/strmatch.cpp
icu4c/source/i18n/strrepl.cpp
icu4c/source/i18n/timezone.cpp
icu4c/source/i18n/tmutfmt.cpp
icu4c/source/i18n/translit.cpp
icu4c/source/i18n/transreg.cpp
icu4c/source/i18n/tridpars.cpp
icu4c/source/i18n/tzgnames.cpp
icu4c/source/i18n/tznames_impl.cpp
icu4c/source/i18n/ucurr.cpp
icu4c/source/i18n/umsg.cpp
icu4c/source/i18n/unum.cpp
icu4c/source/i18n/vtzone.cpp
icu4c/source/i18n/vzone.cpp
icu4c/source/i18n/zrule.cpp

index b5c314c868617b479ec74c47cc39b5ff95411fba..5e74d7e58c5f8a8d7481f764552405de8552e14b 100644 (file)
@@ -120,12 +120,17 @@ RBBIRuleScanner::RBBIRuleScanner(RBBIRuleBuilder *rb)
     //            all instances of RBBIRuleScanners.  BUT this is quite a bit simpler,
     //            and the time to build these few sets should be small compared to a
     //            full break iterator build.
-    fRuleSets[kRuleSet_rule_char-128]       = UnicodeSet(gRuleSet_rule_char_pattern,       *rb->fStatus);
+    fRuleSets[kRuleSet_rule_char-128]
+        = UnicodeSet(UnicodeString(gRuleSet_rule_char_pattern),       *rb->fStatus);
     // fRuleSets[kRuleSet_white_space-128] = [:Pattern_White_Space:]
-    fRuleSets[kRuleSet_white_space-128].add(9, 0xd).add(0x20).add(0x85).add(0x200e, 0x200f).add(0x2028, 0x2029);
-    fRuleSets[kRuleSet_name_char-128]       = UnicodeSet(gRuleSet_name_char_pattern,       *rb->fStatus);
-    fRuleSets[kRuleSet_name_start_char-128] = UnicodeSet(gRuleSet_name_start_char_pattern, *rb->fStatus);
-    fRuleSets[kRuleSet_digit_char-128]      = UnicodeSet(gRuleSet_digit_char_pattern,      *rb->fStatus);
+    fRuleSets[kRuleSet_white_space-128].
+        add(9, 0xd).add(0x20).add(0x85).add(0x200e, 0x200f).add(0x2028, 0x2029);
+    fRuleSets[kRuleSet_name_char-128]
+        = UnicodeSet(UnicodeString(gRuleSet_name_char_pattern),       *rb->fStatus);
+    fRuleSets[kRuleSet_name_start_char-128]
+        = UnicodeSet(UnicodeString(gRuleSet_name_start_char_pattern), *rb->fStatus);
+    fRuleSets[kRuleSet_digit_char-128]
+        = UnicodeSet(UnicodeString(gRuleSet_digit_char_pattern),      *rb->fStatus);
     if (*rb->fStatus == U_ILLEGAL_ARGUMENT_ERROR) {
         // This case happens if ICU's data is missing.  UnicodeSet tries to look up property
         //   names from the init string, can't find them, and claims an illegal argument.
@@ -414,7 +419,7 @@ UBool RBBIRuleScanner::doParseActions(int32_t action)
         // sets that just happen to contain only one character.
         {
             n = pushNewNode(RBBINode::setRef);
-            findSetFor(fC.fChar, n);
+            findSetFor(UnicodeString(fC.fChar), n);
             n->fFirstPos = fScanIndex;
             n->fLastPos  = fNextIndex;
             fRB->fRules.extractBetween(n->fFirstPos, n->fLastPos, n->fText);
@@ -425,7 +430,7 @@ UBool RBBIRuleScanner::doParseActions(int32_t action)
         // scanned a ".", meaning match any single character.
         {
             n = pushNewNode(RBBINode::setRef);
-            findSetFor(kAny, n);
+            findSetFor(UnicodeString(TRUE, kAny, 3), n);
             n->fFirstPos = fScanIndex;
             n->fLastPos  = fNextIndex;
             fRB->fRules.extractBetween(n->fFirstPos, n->fLastPos, n->fText);
@@ -1046,7 +1051,7 @@ void RBBIRuleScanner::parse() {
     if (fRB->fReverseTree == NULL) {
         fRB->fReverseTree  = pushNewNode(RBBINode::opStar);
         RBBINode  *operand = pushNewNode(RBBINode::setRef);
-        findSetFor(kAny, operand);
+        findSetFor(UnicodeString(TRUE, kAny, 3), operand);
         fRB->fReverseTree->fLeftChild = operand;
         operand->fParent              = fRB->fReverseTree;
         fNodeStackPtr -= 2;
index ca2e81abc2acb4dd0f688a32856252d725c3b206..e9785d673ae168b94bd3a6174de6e8499b9c2174 100644 (file)
@@ -132,6 +132,43 @@ class UnicodeStringAppendable;  // unicode/appendable.h
  */
 #define UNICODE_STRING_SIMPLE(cs) UNICODE_STRING(cs, -1)
 
+/**
+ * \def UNISTR_FROM_CHAR_EXPLICIT
+ * This can be defined to be empty or "explicit".
+ * If explicit, then the UnicodeString(UChar) and UnicodeString(UChar32)
+ * constructors are marked as explicit, preventing their inadvertent use.
+ * @draft ICU 49
+ */
+#ifndef UNISTR_FROM_CHAR_EXPLICIT
+# if defined(U_COMBINED_IMPLEMENTATION) || defined(U_COMMON_IMPLEMENTATION) || defined(U_I18N_IMPLEMENTATION) || defined(U_IO_IMPLEMENTATION)
+    // Auto-"explicit" in ICU library code.
+#   define UNISTR_FROM_CHAR_EXPLICIT explicit
+# else
+    // Empty by default for source code compatibility.
+#   define UNISTR_FROM_CHAR_EXPLICIT
+# endif
+#endif
+
+/**
+ * \def UNISTR_FROM_STRING_EXPLICIT
+ * This can be defined to be empty or "explicit".
+ * If explicit, then the UnicodeString(const char *) and UnicodeString(const UChar *)
+ * constructors are marked as explicit, preventing their inadvertent use.
+ *
+ * In particular, this helps prevent accidentally depending on ICU conversion code
+ * by passing a string literal into an API with a const UnicodeString & parameter.
+ * @draft ICU 49
+ */
+#ifndef UNISTR_FROM_STRING_EXPLICIT
+# if defined(U_COMBINED_IMPLEMENTATION) || defined(U_COMMON_IMPLEMENTATION) || defined(U_I18N_IMPLEMENTATION) || defined(U_IO_IMPLEMENTATION)
+    // Auto-"explicit" in ICU library code.
+#   define UNISTR_FROM_STRING_EXPLICIT explicit
+# else
+    // Empty by default for source code compatibility.
+#   define UNISTR_FROM_STRING_EXPLICIT
+# endif
+#endif
+
 /**
  * UnicodeString is a string class that stores Unicode characters directly and provides
  * similar functionality as the Java String and StringBuffer classes.
@@ -2822,25 +2859,37 @@ public:
 
   /**
    * Single UChar (code unit) constructor.
+   *
+   * It is recommended to mark this constructor "explicit" by
+   * <code>-DUNISTR_FROM_CHAR_EXPLICIT=explicit</code>
+   * on the compiler command line or similar.
    * @param ch the character to place in the UnicodeString
    * @stable ICU 2.0
    */
-  UnicodeString(UChar ch);
+  UNISTR_FROM_CHAR_EXPLICIT UnicodeString(UChar ch);
 
   /**
    * Single UChar32 (code point) constructor.
+   *
+   * It is recommended to mark this constructor "explicit" by
+   * <code>-DUNISTR_FROM_CHAR_EXPLICIT=explicit</code>
+   * on the compiler command line or similar.
    * @param ch the character to place in the UnicodeString
    * @stable ICU 2.0
    */
-  UnicodeString(UChar32 ch);
+  UNISTR_FROM_CHAR_EXPLICIT UnicodeString(UChar32 ch);
 
   /**
    * UChar* constructor.
+   *
+   * It is recommended to mark this constructor "explicit" by
+   * <code>-DUNISTR_FROM_STRING_EXPLICIT=explicit</code>
+   * on the compiler command line or similar.
    * @param text The characters to place in the UnicodeString.  <TT>text</TT>
    * must be NULL (U+0000) terminated.
    * @stable ICU 2.0
    */
-  UnicodeString(const UChar *text);
+  UNISTR_FROM_STRING_EXPLICIT UnicodeString(const UChar *text);
 
   /**
    * UChar* constructor.
@@ -2899,14 +2948,22 @@ public:
 
   /**
    * char* constructor.
+   * Uses the default converter (and thus depends on the ICU conversion code)
+   * unless U_CHARSET_IS_UTF8 is set to 1.
+   *
+   * It is recommended to mark this constructor "explicit" by
+   * <code>-DUNISTR_FROM_STRING_EXPLICIT=explicit</code>
+   * on the compiler command line or similar.
    * @param codepageData an array of bytes, null-terminated,
    *                     in the platform's default codepage.
    * @stable ICU 2.0
    */
-  UnicodeString(const char *codepageData);
+  UNISTR_FROM_STRING_EXPLICIT UnicodeString(const char *codepageData);
 
   /**
    * char* constructor.
+   * Uses the default converter (and thus depends on the ICU conversion code)
+   * unless U_CHARSET_IS_UTF8 is set to 1.
    * @param codepageData an array of bytes in the platform's default codepage.
    * @param dataLength The number of bytes in <TT>codepageData</TT>.
    * @stable ICU 2.0
index 30c65f470e3224de5a80aba74ccd94b748eb6a1f..115b5e094264b860822c7ce8faf1d4342f173abb 100644 (file)
@@ -660,7 +660,7 @@ void UnicodeSet::applyPattern(RuleCharacterIterator& chars,
                         c = chars.next(opts, literal, ec);
                         if (U_FAILURE(ec)) return;
                         if (c == 0x5D /*']'*/ && !literal) {
-                            patLocal.append(HYPHEN_RIGHT_BRACE);
+                            patLocal.append(HYPHEN_RIGHT_BRACE, 2);
                             mode = 2;
                             continue;
                         }
@@ -1224,7 +1224,12 @@ UnicodeSet& UnicodeSet::applyPropertyPattern(const UnicodeString& pattern,
     }
 
     // Look for the matching close delimiter, either :] or }
-    int32_t close = pattern.indexOf(posix ? POSIX_CLOSE : PERL_CLOSE, pos);
+    int32_t close;
+    if (posix) {
+      close = pattern.indexOf(POSIX_CLOSE, 2, pos);
+    } else {
+      close = pattern.indexOf(CLOSE_BRACE, pos);
+    }
     if (close < 0) {
         // Syntax error; close delimiter missing
         FAIL(ec);
index d9d69c0b396b6c10aa2d11beb6cfb55028b4eac3..efdf7a7b90fb33459027b9be685fab07a81f2c0a 100644 (file)
@@ -1048,7 +1048,7 @@ void AlphabeticIndex::hackName(UnicodeString &dest, const UnicodeString &name, c
             index--;
             break;
         }
-        int32_t compareResult = col->compare(name, (*HACK_PINYIN_LOOKUP)[index]); 
+        int32_t compareResult = col->compare(name, UnicodeString(TRUE, (*HACK_PINYIN_LOOKUP)[index], -1));
         if (compareResult < 0) {
             index--;
         }
index 5147ec84b3ba8c9aea149623ca4808d8f8453f90..c3b3b67c25ce89940e210fcc4375590bf99834d0 100644 (file)
@@ -288,7 +288,7 @@ Transliterator* AnyTransliterator::getTransliterator(UScriptCode source) const {
             
             // Try to pivot around Latin, our most common script
             id = sourceName;
-            id.append(LATIN_PIVOT).append(target);
+            id.append(LATIN_PIVOT, -1).append(target);
             t = Transliterator::createInstance(id, UTRANS_FORWARD, ec);
             if (U_FAILURE(ec) || t == NULL) {
                 delete t;
@@ -341,7 +341,7 @@ void AnyTransliterator::registerIDs() {
         Transliterator::_getAvailableSource(s, source);
 
         // Ignore the "Any" source
-        if (source.caseCompare(ANY, 0 /*U_FOLD_CASE_DEFAULT*/) == 0) continue;
+        if (source.caseCompare(ANY, 3, 0 /*U_FOLD_CASE_DEFAULT*/) == 0) continue;
 
         int32_t targetCount = Transliterator::_countAvailableTargets(source);
         for (int32_t t=0; t<targetCount; ++t) {
@@ -364,7 +364,7 @@ void AnyTransliterator::registerIDs() {
                 Transliterator::_getAvailableVariant(v, source, target, variant);
                 
                 UnicodeString id;
-                TransliteratorIDParser::STVtoID(ANY, target, variant, id);
+                TransliteratorIDParser::STVtoID(UnicodeString(TRUE, ANY, 3), target, variant, id);
                 ec = U_ZERO_ERROR;
                 AnyTransliterator* t = new AnyTransliterator(id, target, variant,
                                                              targetScript, ec);
@@ -372,7 +372,7 @@ void AnyTransliterator::registerIDs() {
                     delete t;
                 } else {
                     Transliterator::_registerInstance(t);
-                    Transliterator::_registerSpecialInverse(target, NULL_ID, FALSE);
+                    Transliterator::_registerSpecialInverse(target, UnicodeString(TRUE, NULL_ID, 4), FALSE);
                 }
             }
         }
index ebe5d44bf6c25e5a65fbd32afe883db26ee3a887..5f56492b99af06537dfede5f8dbc3dc3046e7afc 100644 (file)
@@ -1,6 +1,6 @@
 /*
 **********************************************************************
-*   Copyright (C) 1999-2008, International Business Machines
+*   Copyright (C) 1999-2011, International Business Machines
 *   Corporation and others.  All Rights Reserved.
 **********************************************************************
 *   Date        Name        Description
@@ -24,8 +24,6 @@
 static const UChar ID_DELIM = 0x003B; /*;*/
 static const UChar NEWLINE  = 10;
 
-// Empty string
-static const UChar EMPTY[] = {0}; //""
 static const UChar COLON_COLON[] = {0x3A, 0x3A, 0}; //"::"
 
 U_NAMESPACE_BEGIN
@@ -110,7 +108,7 @@ CompoundTransliterator::CompoundTransliterator(const UnicodeString& newID,
 CompoundTransliterator::CompoundTransliterator(UVector& list,
                                                UParseError& /*parseError*/,
                                                UErrorCode& status) :
-    Transliterator(EMPTY, NULL),
+    Transliterator(UnicodeString(), NULL),
     trans(0), numAnonymousRBTs(0)
 {
     // TODO add code for parseError...currently unused, but
@@ -123,7 +121,7 @@ CompoundTransliterator::CompoundTransliterator(UVector& list,
                                                int32_t anonymousRBTs,
                                                UParseError& /*parseError*/,
                                                UErrorCode& status) :
-    Transliterator(EMPTY, NULL),
+    Transliterator(UnicodeString(), NULL),
     trans(0), numAnonymousRBTs(anonymousRBTs)
 {
     init(list, UTRANS_FORWARD, FALSE, status);
@@ -404,7 +402,7 @@ UnicodeString& CompoundTransliterator::toRules(UnicodeString& rulesSource,
         // If we are a compound RBT and if we have a global
         // filter, then emit it at the top.
         UnicodeString pat;
-        rulesSource.append(COLON_COLON).append(getFilter()->toPattern(pat, escapeUnprintable)).append(ID_DELIM);
+        rulesSource.append(COLON_COLON, 2).append(getFilter()->toPattern(pat, escapeUnprintable)).append(ID_DELIM);
     }
     for (int32_t i=0; i<count; ++i) {
         UnicodeString rule;
@@ -413,9 +411,9 @@ UnicodeString& CompoundTransliterator::toRules(UnicodeString& rulesSource,
         // ::BEGIN/::END blocks) are given IDs that begin with
         // "%Pass": use toRules() to write all the rules to the output
         // (and insert "::Null;" if we have two in a row)
-        if (trans[i]->getID().startsWith(PASS_STRING)) {
+        if (trans[i]->getID().startsWith(PASS_STRING, 5)) {
             trans[i]->toRules(rule, escapeUnprintable);
-            if (numAnonymousRBTs > 1 && i > 0 && trans[i - 1]->getID().startsWith(PASS_STRING))
+            if (numAnonymousRBTs > 1 && i > 0 && trans[i - 1]->getID().startsWith(PASS_STRING, 5))
                 rule = UNICODE_STRING_SIMPLE("::Null;") + rule;
 
         // we also use toRules() on CompoundTransliterators (which we
index a0d37f13a227db1cf68935e392c7ac80da7fdf51..e80d84702b5c625d1012b408cf17c3bd2f489502 100644 (file)
@@ -159,9 +159,9 @@ CurrencyPluralInfo::getCurrencyPluralPattern(const UnicodeString&  pluralCount,
         (UnicodeString*)fPluralCountToCurrencyUnitPattern->get(pluralCount);
     if (currencyPluralPattern == NULL) {
         // fall back to "other"
-        if (pluralCount.compare(gPluralCountOther)) {
+        if (pluralCount.compare(gPluralCountOther, 5)) {
             currencyPluralPattern = 
-                (UnicodeString*)fPluralCountToCurrencyUnitPattern->get(gPluralCountOther);
+                (UnicodeString*)fPluralCountToCurrencyUnitPattern->get(UnicodeString(TRUE, gPluralCountOther, 5));
         }
         if (currencyPluralPattern == NULL) {
             // no currencyUnitPatterns defined, 
@@ -291,15 +291,15 @@ CurrencyPluralInfo::setupCurrencyPluralPattern(const Locale& loc, UErrorCode& st
                     pattern->extract(0, pattern->length(), result_1, "UTF-8");
                     std::cout << "pluralCount: " << pluralCount << "; pattern: " << result_1 << "\n";
 #endif
-                    pattern->findAndReplace(gPart0
+                    pattern->findAndReplace(UnicodeString(TRUE, gPart0, 3)
                       UnicodeString(numberStylePattern, numberStylePatternLen));
-                    pattern->findAndReplace(gPart1, gTripleCurrencySign);
+                    pattern->findAndReplace(UnicodeString(TRUE, gPart1, 3), UnicodeString(TRUE, gTripleCurrencySign, 3));
 
                     if (hasSeparator) {
                         UnicodeString negPattern(patternChars, ptnLen);
-                        negPattern.findAndReplace(gPart0
+                        negPattern.findAndReplace(UnicodeString(TRUE, gPart0, 3)
                           UnicodeString(negNumberStylePattern, negNumberStylePatternLen));
-                        negPattern.findAndReplace(gPart1, gTripleCurrencySign);
+                        negPattern.findAndReplace(UnicodeString(TRUE, gPart1, 3), UnicodeString(TRUE, gTripleCurrencySign, 3));
                         pattern->append(gNumberPatternSeparator);
                         pattern->append(negPattern);
                     }
index cc537830ec7914895524faef14f25faa08f79c92..638c18597a090d393bcc7d99ff99bca3c363e362 100644 (file)
@@ -1,6 +1,6 @@
 /*
 *******************************************************************************
-* Copyright (C) 1997-2010, International Business Machines Corporation and    *
+* Copyright (C) 1997-2011, International Business Machines Corporation and    *
 * others. All Rights Reserved.                                                *
 *******************************************************************************
 *
@@ -206,18 +206,17 @@ DecimalFormatSymbols::initialize(const Locale& loc, UErrorCode& status, UBool us
         NumberingSystem* ns = NumberingSystem::createInstance(loc,status);
         if (U_SUCCESS(status) && ns->getRadix() == 10 && !ns->isAlgorithmic()) {
             nsName = ns->getName();
-            UnicodeString *DigitString = new UnicodeString(ns->getDescription());
-                setSymbol(kZeroDigitSymbol,DigitString->charAt(0),FALSE);
-                setSymbol(kOneDigitSymbol,DigitString->charAt(1),FALSE);
-                setSymbol(kTwoDigitSymbol,DigitString->charAt(2),FALSE);
-                setSymbol(kThreeDigitSymbol,DigitString->charAt(3),FALSE);
-                setSymbol(kFourDigitSymbol,DigitString->charAt(4),FALSE);
-                setSymbol(kFiveDigitSymbol,DigitString->charAt(5),FALSE);
-                setSymbol(kSixDigitSymbol,DigitString->charAt(6),FALSE);
-                setSymbol(kSevenDigitSymbol,DigitString->charAt(7),FALSE);
-                setSymbol(kEightDigitSymbol,DigitString->charAt(8),FALSE);
-                setSymbol(kNineDigitSymbol,DigitString->charAt(9),FALSE);
-            delete DigitString;
+            UnicodeString digitString(ns->getDescription());
+            setSymbol(kZeroDigitSymbol,  digitString.tempSubString(0, 1), FALSE);
+            setSymbol(kOneDigitSymbol,   digitString.tempSubString(1, 1), FALSE);
+            setSymbol(kTwoDigitSymbol,   digitString.tempSubString(2, 1), FALSE);
+            setSymbol(kThreeDigitSymbol, digitString.tempSubString(3, 1), FALSE);
+            setSymbol(kFourDigitSymbol,  digitString.tempSubString(4, 1), FALSE);
+            setSymbol(kFiveDigitSymbol,  digitString.tempSubString(5, 1), FALSE);
+            setSymbol(kSixDigitSymbol,   digitString.tempSubString(6, 1), FALSE);
+            setSymbol(kSevenDigitSymbol, digitString.tempSubString(7, 1), FALSE);
+            setSymbol(kEightDigitSymbol, digitString.tempSubString(8, 1), FALSE);
+            setSymbol(kNineDigitSymbol,  digitString.tempSubString(9, 1), FALSE);
         } else {
             nsName = gLatn;
         }
@@ -252,7 +251,7 @@ DecimalFormatSymbols::initialize(const Locale& loc, UErrorCode& status, UBool us
                 }
 
                 if ( U_SUCCESS(localStatus) ) {
-                    setSymbol((ENumberFormatSymbol)i,sym);
+                    setSymbol((ENumberFormatSymbol)i, UnicodeString(TRUE, sym, len));
                     if ( i == kMonetarySeparatorSymbol ) {
                         kMonetaryDecimalSet = TRUE;
                     } else if ( i == kMonetaryGroupingSeparatorSymbol ) {
@@ -292,7 +291,7 @@ DecimalFormatSymbols::initialize(const Locale& loc, UErrorCode& status, UBool us
         // Reuse numberElements[0] as a temporary buffer
         uprv_getStaticCurrencyName(curriso, locStr, tempStr, internalStatus);
         if (U_SUCCESS(internalStatus)) {
-            fSymbols[kIntlCurrencySymbol] = curriso;
+            fSymbols[kIntlCurrencySymbol].setTo(curriso, -1);
             fSymbols[kCurrencySymbol] = tempStr;
         }
         /* else use the default values. */
@@ -321,8 +320,8 @@ DecimalFormatSymbols::initialize(const Locale& loc, UErrorCode& status, UBool us
                 currency = ures_getByIndex(currency, 2, currency, &localStatus);
                 int32_t currPatternLen = 0;
                 currPattern = ures_getStringByIndex(currency, (int32_t)0, &currPatternLen, &localStatus);
-                UnicodeString decimalSep = ures_getStringByIndex(currency, (int32_t)1, NULL, &localStatus);
-                UnicodeString groupingSep = ures_getStringByIndex(currency, (int32_t)2, NULL, &localStatus);
+                UnicodeString decimalSep = ures_getUnicodeStringByIndex(currency, (int32_t)1, &localStatus);
+                UnicodeString groupingSep = ures_getUnicodeStringByIndex(currency, (int32_t)2, &localStatus);
                 if(U_SUCCESS(localStatus)){
                     fSymbols[kMonetaryGroupingSeparatorSymbol] = groupingSep;
                     fSymbols[kMonetarySeparatorSymbol] = decimalSep;
@@ -353,8 +352,7 @@ DecimalFormatSymbols::initialize(const Locale& loc, UErrorCode& status, UBool us
             if (localStatus == U_USING_FALLBACK_WARNING || U_SUCCESS(localStatus)) {
                 localStatus = U_ZERO_ERROR;
                 for (int32_t i = 0; i < UNUM_CURRENCY_SPACING_COUNT; i++) {
-                  currencySpcBeforeSym[i] = ures_getStringByKey(dataRes, keywords[i],
-                                                            NULL, &localStatus);
+                  currencySpcBeforeSym[i] = ures_getUnicodeStringByKey(dataRes, keywords[i], &localStatus);
                 }
                 ures_close(dataRes);
             }
@@ -363,8 +361,7 @@ DecimalFormatSymbols::initialize(const Locale& loc, UErrorCode& status, UBool us
             if (localStatus == U_USING_FALLBACK_WARNING || U_SUCCESS(localStatus)) {
                 localStatus = U_ZERO_ERROR;
                 for (int32_t i = 0; i < UNUM_CURRENCY_SPACING_COUNT; i++) {
-                  currencySpcAfterSym[i] = ures_getStringByKey(dataRes, keywords[i],
-                                                                NULL, &localStatus);
+                  currencySpcAfterSym[i] = ures_getUnicodeStringByKey(dataRes, keywords[i], &localStatus);
                 }
                 ures_close(dataRes);
             }
@@ -402,7 +399,7 @@ DecimalFormatSymbols::initialize() {
     fSymbols[kPlusSignSymbol] = (UChar)0x002b;          // '+' plus sign
     fSymbols[kMinusSignSymbol] = (UChar)0x2d;           // '-' minus sign
     fSymbols[kCurrencySymbol] = (UChar)0xa4;            // 'OX' currency symbol
-    fSymbols[kIntlCurrencySymbol] = INTL_CURRENCY_SYMBOL_STR;
+    fSymbols[kIntlCurrencySymbol].setTo(TRUE, INTL_CURRENCY_SYMBOL_STR, 2);
     fSymbols[kMonetarySeparatorSymbol] = (UChar)0x2e;   // '.' monetary decimal separator
     fSymbols[kExponentialSymbol] = (UChar)0x45;         // 'E' exponential
     fSymbols[kPerMillSymbol] = (UChar)0x2030;           // '%o' per mill
index 9e05200392bf3efb57506ac905d9650ea4a64d86..fa671fcddcf3d5d878d1198c02747ba0913f8bef 100644 (file)
@@ -454,7 +454,7 @@ DecimalFormat::construct(UErrorCode&             status,
         // need it for mix parsing
         setupCurrencyAffixPatterns(status);
         // expanded affixes for plural names
-        if (patternUsed->indexOf(fgTripleCurrencySign) != -1) {
+        if (patternUsed->indexOf(fgTripleCurrencySign, 3, 0) != -1) {
             setupCurrencyAffixes(*patternUsed, TRUE, TRUE, status);
         }
     }
@@ -2714,7 +2714,7 @@ DecimalFormat::setCurrencyForSymbols() {
     uprv_getStaticCurrencyName(intlCurrencySymbol, loc, currencySymbol, ec);
     if (U_SUCCESS(ec)
         && getConstSymbol(DecimalFormatSymbols::kCurrencySymbol) == currencySymbol
-        && getConstSymbol(DecimalFormatSymbols::kIntlCurrencySymbol) == intlCurrencySymbol)
+        && getConstSymbol(DecimalFormatSymbols::kIntlCurrencySymbol) == UnicodeString(intlCurrencySymbol))
     {
         // Trap an error in mapping locale to currency.  If we can't
         // map, then don't fail and set the currency to "".
@@ -2943,7 +2943,7 @@ void DecimalFormat::setFormatWidth(int32_t width) {
 }
 
 UnicodeString DecimalFormat::getPadCharacterString() const {
-    return fPad;
+    return UnicodeString(fPad);
 }
 
 void DecimalFormat::setPadCharacter(const UnicodeString &padChar) {
@@ -3288,7 +3288,7 @@ void DecimalFormat::expandAffix(const UnicodeString& pattern,
                         affix += UnicodeString(s, len);
                         handler.addAttribute(kCurrencyField, beginIdx, affix.length());
                     } else if(intl) {
-                        affix += currencyUChars;
+                        affix.append(currencyUChars, -1);
                         handler.addAttribute(kCurrencyField, beginIdx, affix.length());
                     } else {
                         int32_t len;
@@ -3309,7 +3309,7 @@ void DecimalFormat::expandAffix(const UnicodeString& pattern,
                                 // return.
                                 if (fCurrencyChoice == NULL) {
                                     // TODO Replace double-check with proper thread-safe code
-                                    ChoiceFormat* fmt = new ChoiceFormat(s, ec);
+                                    ChoiceFormat* fmt = new ChoiceFormat(UnicodeString(s), ec);
                                     if (U_SUCCESS(ec)) {
                                         umtx_lock(NULL);
                                         if (fCurrencyChoice == NULL) {
@@ -3339,7 +3339,7 @@ void DecimalFormat::expandAffix(const UnicodeString& pattern,
                                 } else {
                                     // We only arrive here if the currency choice
                                     // format in the locale data is INVALID.
-                                    affix += currencyUChars;
+                                    affix.append(currencyUChars, -1);
                                     handler.addAttribute(kCurrencyField, beginIdx, affix.length());
                                 }
                             }
@@ -4503,7 +4503,7 @@ DecimalFormat::applyPattern(const UnicodeString& pattern,
         if (fAffixPatternsForCurrency == NULL) {
             setupCurrencyAffixPatterns(status);
         }
-        if (pattern.indexOf(fgTripleCurrencySign) != -1) {
+        if (pattern.indexOf(fgTripleCurrencySign, 3, 0) != -1) {
             // only setup the affixes of the current pattern.
             setupCurrencyAffixes(pattern, TRUE, FALSE, status);
         }
@@ -4634,7 +4634,7 @@ void DecimalFormat::setCurrencyInternally(const UChar* theCurrency,
 void DecimalFormat::setCurrency(const UChar* theCurrency, UErrorCode& ec) {
     // set the currency before compute affixes to get the right currency names
     NumberFormat::setCurrency(theCurrency, ec);
-    if (fFormatPattern.indexOf(fgTripleCurrencySign) != -1) {
+    if (fFormatPattern.indexOf(fgTripleCurrencySign, 3, 0) != -1) {
         UnicodeString savedPtn = fFormatPattern;
         setupCurrencyAffixes(fFormatPattern, TRUE, TRUE, ec);
         UParseError parseErr;
index 6a5e84aeb7d773d270a657f5af5d9d1ffff54fce..79f67ab605819e082ca9e9f05aca0558717cd07a 100644 (file)
@@ -657,7 +657,7 @@ DateIntervalFormat::initializePattern(UErrorCode& status) {
         if ( timeSkeleton.length() != 0 ) {
             if ( dateSkeleton.length() == 0 ) {
                 // prefix with yMd
-                timeSkeleton.insert(0, gDateFormatSkeleton[DateFormat::kShort]);
+                timeSkeleton.insert(0, gDateFormatSkeleton[DateFormat::kShort], -1);
                 UnicodeString pattern = fDtpng->getBestPattern(timeSkeleton, status);
                 if ( U_FAILURE(status) ) {
                     return;    
@@ -682,7 +682,7 @@ DateIntervalFormat::initializePattern(UErrorCode& status) {
         // done
     } else if ( dateSkeleton.length() == 0 ) {
         // prefix with yMd
-        timeSkeleton.insert(0, gDateFormatSkeleton[DateFormat::kShort]);
+        timeSkeleton.insert(0, gDateFormatSkeleton[DateFormat::kShort], -1);
         UnicodeString pattern = fDtpng->getBestPattern(timeSkeleton, status);
         if ( U_FAILURE(status) ) {
             return;    
index 87130a3211b8d4b366b8f638692429c74baaa8b4..67b9f83323f2dcf837e7ba542550a2fa13904c6f 100644 (file)
@@ -293,14 +293,12 @@ DateIntervalInfo::initializeData(const Locale& locale, UErrorCode& err)
                     continue;
                 }
 
-                const UChar* pattern;
                 const char* key;
-                int32_t ptLength;
                 int32_t ptnNum = ures_getSize(intervalPatterns.getAlias());
                 int32_t ptnIndex;
                 for ( ptnIndex = 0; ptnIndex < ptnNum; ++ptnIndex ) {
-                    pattern = ures_getNextString(intervalPatterns.getAlias(), &ptLength, &key,
-                                                 &status);
+                    UnicodeString pattern =
+                        ures_getNextUnicodeString(intervalPatterns.getAlias(), &key, &status);
                     if ( U_FAILURE(status) ) {
                         break;
                     }
@@ -440,14 +438,8 @@ DateIntervalInfo::getBestSkeleton(const UnicodeString& skeleton,
     const UnicodeString* inputSkeleton = &skeleton; 
     UnicodeString copySkeleton;
     if ( skeleton.indexOf(CHAR_Z) != -1 ) {
-        UChar zstr[2];
-        UChar vstr[2]; 
-        zstr[0]=CHAR_Z;
-        vstr[0]=CHAR_V;
-        zstr[1]=0;
-        vstr[1]=0;
         copySkeleton = skeleton;
-        copySkeleton.findAndReplace(zstr, vstr);
+        copySkeleton.findAndReplace(UnicodeString(CHAR_Z), UnicodeString(CHAR_V));
         inputSkeleton = &copySkeleton;
         replaceZWithV = true;
     }
index 93f13f5816c766461a14f3fac563462d159d34da..0af201afc37a7a5bd4e56662f1ffe0b363bcb18a 100644 (file)
@@ -1,6 +1,6 @@
 /*
 **********************************************************************
-*   Copyright (c) 2001-2006, International Business Machines
+*   Copyright (c) 2001-2011, International Business Machines
 *   Corporation and others.  All Rights Reserved.
 **********************************************************************
 *   Date        Name        Description
@@ -25,7 +25,6 @@ static const UChar XML10PRE[] = {38,35,0}; // "&#"
 static const UChar PERLPRE[] = {92,120,123,0}; // "\\x{"
 static const UChar SEMI[] = {59,0}; // ";"
 static const UChar RBRACE[] = {125,0}; // "}"
-static const UChar EMPTY[] = {0}; // ""
 
 UOBJECT_DEFINE_RTTI_IMPLEMENTATION(EscapeTransliterator)
 
@@ -34,28 +33,28 @@ UOBJECT_DEFINE_RTTI_IMPLEMENTATION(EscapeTransliterator)
  */
 static Transliterator* _createEscUnicode(const UnicodeString& ID, Transliterator::Token /*context*/) {
     // Unicode: "U+10FFFF" hex, min=4, max=6
-    return new EscapeTransliterator(ID, UNIPRE, EMPTY, 16, 4, TRUE, NULL);
+    return new EscapeTransliterator(ID, UnicodeString(TRUE, UNIPRE, 2), UnicodeString(), 16, 4, TRUE, NULL);
 }
 static Transliterator* _createEscJava(const UnicodeString& ID, Transliterator::Token /*context*/) {
     // Java: "\\uFFFF" hex, min=4, max=4
-    return new EscapeTransliterator(ID, BS_u, EMPTY, 16, 4, FALSE, NULL);
+    return new EscapeTransliterator(ID, UnicodeString(TRUE, BS_u, 2), UnicodeString(), 16, 4, FALSE, NULL);
 }
 static Transliterator* _createEscC(const UnicodeString& ID, Transliterator::Token /*context*/) {
     // C: "\\uFFFF" hex, min=4, max=4; \\U0010FFFF hex, min=8, max=8
-    return new EscapeTransliterator(ID, BS_u, EMPTY, 16, 4, TRUE,
-             new EscapeTransliterator(EMPTY, BS_U, EMPTY, 16, 8, TRUE, NULL));
+    return new EscapeTransliterator(ID, UnicodeString(TRUE, BS_u, 2), UnicodeString(), 16, 4, TRUE,
+             new EscapeTransliterator(UnicodeString(), UnicodeString(TRUE, BS_U, 2), UnicodeString(), 16, 8, TRUE, NULL));
 }
 static Transliterator* _createEscXML(const UnicodeString& ID, Transliterator::Token /*context*/) {
     // XML: "&#x10FFFF;" hex, min=1, max=6
-    return new EscapeTransliterator(ID, XMLPRE, SEMI, 16, 1, TRUE, NULL);
+    return new EscapeTransliterator(ID, UnicodeString(TRUE, XMLPRE, 3), UnicodeString(SEMI[0]), 16, 1, TRUE, NULL);
 }
 static Transliterator* _createEscXML10(const UnicodeString& ID, Transliterator::Token /*context*/) {
     // XML10: "&1114111;" dec, min=1, max=7 (not really "Any-Hex")
-    return new EscapeTransliterator(ID, XML10PRE, SEMI, 10, 1, TRUE, NULL);
+    return new EscapeTransliterator(ID, UnicodeString(TRUE, XML10PRE, 2), UnicodeString(SEMI[0]), 10, 1, TRUE, NULL);
 }
 static Transliterator* _createEscPerl(const UnicodeString& ID, Transliterator::Token /*context*/) {
     // Perl: "\\x{263A}" hex, min=1, max=6
-    return new EscapeTransliterator(ID, PERLPRE, RBRACE, 16, 1, TRUE, NULL);
+    return new EscapeTransliterator(ID, UnicodeString(TRUE, PERLPRE, 3), UnicodeString(RBRACE[0]), 16, 1, TRUE, NULL);
 }
 
 /**
index 03d71834762b438477e212414856c01c9e63eee5..f13d3bc544e65b325f5e77454fb5e4141cd71359 100644 (file)
@@ -1,6 +1,6 @@
 /*
 **********************************************************************
-*   Copyright (c) 2002-2008, International Business Machines Corporation
+*   Copyright (c) 2002-2011, International Business Machines Corporation
 *   and others.  All Rights Reserved.
 **********************************************************************
 *   Date        Name        Description
@@ -97,9 +97,9 @@ UnicodeString& FunctionReplacer::toReplacerPattern(UnicodeString& rule,
     rule.truncate(0);
     rule.append(AMPERSAND);
     rule.append(translit->getID());
-    rule.append(OPEN);
+    rule.append(OPEN, 2);
     rule.append(replacer->toReplacer()->toReplacerPattern(str, escapeUnprintable));
-    rule.append(CLOSE);
+    rule.append(CLOSE, 2);
     return rule;
 }
 
index 57f246f379687c9834a75303562ffc1686db0609..e5825384208eb317cbb176be6b662f7a11e05545 100644 (file)
@@ -175,7 +175,7 @@ UOBJECT_DEFINE_RTTI_IMPLEMENTATION(FormatNameEnumeration)
 static UnicodeString& itos(int32_t i, UnicodeString& appendTo) {
     UChar temp[16];
     uprv_itou(temp,16,i,10,0); // 10 == radix
-    appendTo.append(temp);
+    appendTo.append(temp, -1);
     return appendTo;
 }
 
index b7b93b24b417a4cd9b1f6479e6b28d7a5a50e7ce..d5682c31922594e9c95eb1fd4e8f51f0be5f9811 100644 (file)
@@ -161,7 +161,7 @@ NFRuleSet::NFRuleSet(UnicodeString* descriptions, int32_t index, UErrorCode& sta
         status = U_PARSE_ERROR;
     }
 
-    fIsPublic = name.indexOf(gPercentPercent) != 0;
+    fIsPublic = name.indexOf(gPercentPercent, 2, 0) != 0;
 
     // all of the other members of NFRuleSet are initialized
     // by parseRules()
@@ -701,14 +701,14 @@ NFRuleSet::appendRules(UnicodeString& result) const
 
     // followed by the regular rules...
     for (uint32_t i = 0; i < rules.size(); i++) {
-        result.append(gFourSpaces);
+        result.append(gFourSpaces, 4);
         rules[i]->_appendRuleText(result);
         result.append(gLineFeed);
     }
 
     // followed by the special rules (if they exist)
     if (negativeNumberRule) {
-        result.append(gFourSpaces);
+        result.append(gFourSpaces, 4);
         negativeNumberRule->_appendRuleText(result);
         result.append(gLineFeed);
     }
@@ -716,7 +716,7 @@ NFRuleSet::appendRules(UnicodeString& result) const
     {
         for (uint32_t i = 0; i < 3; ++i) {
             if (fractionRules[i]) {
-                result.append(gFourSpaces);
+                result.append(gFourSpaces, 4);
                 fractionRules[i]->_appendRuleText(result);
                 result.append(gLineFeed);
             }
index 46932273754a1408166af15cd76578aa109ac4ca..b96a84eb91d80c474316e162fa983cf4a26ec8b5 100644 (file)
@@ -76,7 +76,6 @@ static const UChar gGreaterZero[] =             {0x3E, 0x30, 0};    /* ">0" */
 static const UChar gEqualPercent[] =            {0x3D, 0x25, 0};    /* "=%" */
 static const UChar gEqualHash[] =               {0x3D, 0x23, 0};    /* "=#" */
 static const UChar gEqualZero[] =               {0x3D, 0x30, 0};    /* "=0" */
-static const UChar gEmptyString[] =             {0};                /* "" */
 static const UChar gGreaterGreaterGreater[] =   {0x3E, 0x3E, 0x3E, 0}; /* ">>>" */
 
 static const UChar * const tokenStrings[] = {
@@ -242,16 +241,16 @@ NFRule::parseRuleDescriptor(UnicodeString& description, UErrorCode& status)
         // check first to see if the rule descriptor matches the token
         // for one of the special rules.  If it does, set the base
         // value to the correct identfier value
-        if (descriptor == gMinusX) {
+        if (0 == descriptor.compare(gMinusX, 2)) {
             setType(kNegativeNumberRule);
         }
-        else if (descriptor == gXDotX) {
+        else if (0 == descriptor.compare(gXDotX, 3)) {
             setType(kImproperFractionRule);
         }
-        else if (descriptor == gZeroDotX) {
+        else if (0 == descriptor.compare(gZeroDotX, 3)) {
             setType(kProperFractionRule);
         }
-        else if (descriptor == gXDotZero) {
+        else if (0 == descriptor.compare(gXDotZero, 3)) {
             setType(kMasterRule);
         }
 
@@ -409,12 +408,12 @@ NFRule::extractSubstitution(const NFRuleSet* ruleSet,
     // at the end of the rule text
     if (subStart == -1) {
         return NFSubstitution::makeSubstitution(ruleText.length(), this, predecessor,
-            ruleSet, rbnf, gEmptyString, status);
+            ruleSet, rbnf, UnicodeString(), status);
     }
 
     // special-case the ">>>" token, since searching for the > at the
     // end will actually find the > in the middle
-    if (ruleText.indexOf(gGreaterGreaterGreater) == subStart) {
+    if (ruleText.indexOf(gGreaterGreaterGreater, 3, 0) == subStart) {
         subEnd = subStart + 2;
 
         // otherwise the substitution token ends with the same character
@@ -437,7 +436,7 @@ NFRule::extractSubstitution(const NFRuleSet* ruleSet,
     // at the end of the rule
     if (subEnd == -1) {
         return NFSubstitution::makeSubstitution(ruleText.length(), this, predecessor,
-            ruleSet, rbnf, gEmptyString, status);
+            ruleSet, rbnf, UnicodeString(), status);
     }
 
     // if we get here, we have a real substitution token (or at least
@@ -581,10 +580,10 @@ void
 NFRule::_appendRuleText(UnicodeString& result) const
 {
     switch (getType()) {
-    case kNegativeNumberRule: result.append(gMinusX); break;
-    case kImproperFractionRule: result.append(gXDotX); break;
-    case kProperFractionRule: result.append(gZeroDotX); break;
-    case kMasterRule: result.append(gXDotZero); break;
+    case kNegativeNumberRule: result.append(gMinusX, 2); break;
+    case kImproperFractionRule: result.append(gXDotX, 3); break;
+    case kProperFractionRule: result.append(gZeroDotX, 3); break;
+    case kMasterRule: result.append(gXDotZero, 3); break;
     default:
         // for a normal rule, write out its base value, and if the radix is
         // something other than 10, write out the radix (with the preceding
@@ -609,7 +608,7 @@ NFRule::_appendRuleText(UnicodeString& result) const
     // if the rule text begins with a space, write an apostrophe
     // (whitespace after the rule descriptor is ignored; the
     // apostrophe is used to make the whitespace significant)
-    if (ruleText.startsWith(gSpace) && sub1->getPos() != 0) {
+    if (ruleText.charAt(0) == gSpace && sub1->getPos() != 0) {
         result.append(gTick);
     }
 
index 4348f5d4fc10ce471a0a0f522742ed442a2ed30e..e5c9e635d6833b48d0854fbf39585f3c7aa7ce2c 100644 (file)
@@ -1,6 +1,6 @@
 /*
 ******************************************************************************
-*   Copyright (C) 1997-2010, International Business Machines
+*   Copyright (C) 1997-2011, International Business Machines
 *   Corporation and others.  All Rights Reserved.
 ******************************************************************************
 *   file name:  nfsubs.cpp
@@ -784,7 +784,7 @@ SameValueSubstitution::SameValueSubstitution(int32_t _pos,
                         UErrorCode& status)
 : NFSubstitution(_pos, _ruleSet, formatter, description, status)
 {
-    if (description == gEqualsEquals) {
+    if (0 == description.compare(gEqualsEquals, 2)) {
         // throw new IllegalArgumentException("== is not a legal token");
         status = U_PARSE_ERROR;
     }
@@ -835,7 +835,7 @@ ModulusSubstitution::ModulusSubstitution(int32_t _pos,
       status = U_PARSE_ERROR;
   }
 
-  if (description == gGreaterGreaterGreaterThan) {
+  if (0 == description.compare(gGreaterGreaterGreaterThan, 3)) {
     // the >>> token doesn't alter how this substituion calculates the
     // values it uses for formatting and parsing, but it changes
     // what's done with that value after it's obtained: >>> short-
@@ -982,11 +982,11 @@ FractionalPartSubstitution::FractionalPartSubstitution(int32_t _pos,
 
 {
     // akk, ruleSet can change in superclass constructor
-    if (description == gGreaterGreaterThan ||
-        description == gGreaterGreaterGreaterThan ||
+    if (0 == description.compare(gGreaterGreaterThan, 2) ||
+        0 == description.compare(gGreaterGreaterGreaterThan, 3) ||
         _ruleSet == getRuleSet()) {
         byDigits = TRUE;
-        if (description == gGreaterGreaterGreaterThan) {
+        if (0 == description.compare(gGreaterGreaterGreaterThan, 3)) {
             useSpaces = FALSE;
         }
     } else {
index ff35d31edb20cc42cbffb88885e27dfbae77fdd0..94fc21a6be760e9c943d2da66b8f4ef590cac914 100644 (file)
@@ -1283,7 +1283,8 @@ NumberFormat::makeInstance(const Locale& desiredLocale,
         // replace single currency sign in the pattern with double currency sign
         // if the style is UNUM_CURRENCY_ISO
         if (style == UNUM_CURRENCY_ISO) {
-            pattern.findAndReplace(gSingleCurrencySign, gDoubleCurrencySign);
+            pattern.findAndReplace(UnicodeString(TRUE, gSingleCurrencySign, 1),
+                                   UnicodeString(TRUE, gDoubleCurrencySign, 2));
         }
 
         // "new DecimalFormat()" does not adopt the symbols if its memory allocation fails.
index 534ed156cefeb60318008e25bf57f7508f258f20..e01f09820395e83bb70a521ecca2a3817e0bd1ff 100644 (file)
@@ -1,6 +1,6 @@
 /*
 *******************************************************************************
-* Copyright (C) 2010, International Business Machines Corporation and
+* Copyright (C) 2010-2011, International Business Machines Corporation and
 * others. All Rights Reserved.
 *******************************************************************************
 *
@@ -143,41 +143,36 @@ NumberingSystem::createInstance(UErrorCode& status) {
 
 NumberingSystem* U_EXPORT2
 NumberingSystem::createInstanceByName(const char *name, UErrorCode& status) {
-    
-     UResourceBundle *numberingSystemsInfo = NULL;
-     UResourceBundle *nsTop, *nsCurrent;
-     const UChar* description = NULL;
-     int32_t radix = 10;
-     int32_t algorithmic = 0;
-     int32_t len;
-
-     numberingSystemsInfo = ures_openDirect(NULL,gNumberingSystems, &status);
-     nsCurrent = ures_getByKey(numberingSystemsInfo,gNumberingSystems,NULL,&status);
-     nsTop = ures_getByKey(nsCurrent,name,NULL,&status);
-     description = ures_getStringByKey(nsTop,gDesc,&len,&status);
-
-        ures_getByKey(nsTop,gRadix,nsCurrent,&status);
-     radix = ures_getInt(nsCurrent,&status);
-
-     ures_getByKey(nsTop,gAlgorithmic,nsCurrent,&status);
-     algorithmic = ures_getInt(nsCurrent,&status);
-
-     UBool isAlgorithmic = ( algorithmic == 1 );
-     UnicodeString nsd;
-     nsd.setTo(description);
-
-        ures_close(nsCurrent);
-        ures_close(nsTop);
-     ures_close(numberingSystemsInfo);
-
-     if (U_FAILURE(status)) {
-         status = U_UNSUPPORTED_ERROR;
-         return NULL;
-     }
-
-     NumberingSystem* ns = NumberingSystem::createInstance(radix,isAlgorithmic,nsd,status);
-     ns->setName(name);
-     return ns;
+    UResourceBundle *numberingSystemsInfo = NULL;
+    UResourceBundle *nsTop, *nsCurrent;
+    int32_t radix = 10;
+    int32_t algorithmic = 0;
+
+    numberingSystemsInfo = ures_openDirect(NULL,gNumberingSystems, &status);
+    nsCurrent = ures_getByKey(numberingSystemsInfo,gNumberingSystems,NULL,&status);
+    nsTop = ures_getByKey(nsCurrent,name,NULL,&status);
+    UnicodeString nsd = ures_getUnicodeStringByKey(nsTop,gDesc,&status);
+
+    ures_getByKey(nsTop,gRadix,nsCurrent,&status);
+    radix = ures_getInt(nsCurrent,&status);
+
+    ures_getByKey(nsTop,gAlgorithmic,nsCurrent,&status);
+    algorithmic = ures_getInt(nsCurrent,&status);
+
+    UBool isAlgorithmic = ( algorithmic == 1 );
+
+    ures_close(nsCurrent);
+    ures_close(nsTop);
+    ures_close(numberingSystemsInfo);
+
+    if (U_FAILURE(status)) {
+        status = U_UNSUPPORTED_ERROR;
+        return NULL;
+    }
+
+    NumberingSystem* ns = NumberingSystem::createInstance(radix,isAlgorithmic,nsd,status);
+    ns->setName(name);
+    return ns;
 }
 
     /**
index 3fcbfa5cbce4372b8539b1fd9f824fac4c87c658..edb7d807271c7422eb2c6e412faacfbf5482a3c2 100644 (file)
@@ -140,7 +140,7 @@ PluralRules::createRules(const UnicodeString& description, UErrorCode& status) {
 
 PluralRules* U_EXPORT2
 PluralRules::createDefaultRules(UErrorCode& status) {
-    return createRules(PLURAL_DEFAULT_RULE, status);
+    return createRules(UnicodeString(TRUE, PLURAL_DEFAULT_RULE, -1), status);
 }
 
 PluralRules* U_EXPORT2
@@ -175,7 +175,7 @@ PluralRules::forLocale(const Locale& locale, UErrorCode& status) {
 UnicodeString
 PluralRules::select(int32_t number) const {
     if (mRules == NULL) {
-        return PLURAL_DEFAULT_RULE;
+        return UnicodeString(TRUE, PLURAL_DEFAULT_RULE, -1);
     }
     else {
         return mRules->select(number);
@@ -185,7 +185,7 @@ PluralRules::select(int32_t number) const {
 UnicodeString
 PluralRules::select(double number) const {
     if (mRules == NULL) {
-        return PLURAL_DEFAULT_RULE;
+        return UnicodeString(TRUE, PLURAL_DEFAULT_RULE, -1);
     }
     else {
         return mRules->select(number);
@@ -270,7 +270,7 @@ PluralRules::getSamplesInternal(const UnicodeString &keyword, double *dest,
 
 UBool
 PluralRules::isKeyword(const UnicodeString& keyword) const {
-    if ( keyword == PLURAL_KEYWORD_OTHER ) {
+    if (0 == keyword.compare(PLURAL_KEYWORD_OTHER, 5)) {
         return true;
     }
     else {
@@ -285,7 +285,7 @@ PluralRules::isKeyword(const UnicodeString& keyword) const {
 
 UnicodeString
 PluralRules::getKeywordOther() const {
-    return PLURAL_KEYWORD_OTHER;
+    return UnicodeString(TRUE, PLURAL_KEYWORD_OTHER, 5);
 }
 
 UBool
@@ -489,7 +489,7 @@ PluralRules::getKeywordIndex(const UnicodeString& keyword,
             }
             rc = rc->next;
         }
-        if (keyword == PLURAL_KEYWORD_OTHER) {
+        if (0 == keyword.compare(PLURAL_KEYWORD_OTHER, 5)) {
             return n;
         }
     }
@@ -525,7 +525,7 @@ PluralRules::initSamples(UErrorCode& status) {
     RuleChain* rc = mRules;
     while (rc != NULL) {
         if (rc->ruleHeader != NULL) {
-            if (otherIndex == -1 && rc->keyword == PLURAL_KEYWORD_OTHER) {
+            if (otherIndex == -1 && 0 == rc->keyword.compare(PLURAL_KEYWORD_OTHER, 5)) {
                 otherIndex = maxIndex;
             }
             ++maxIndex;
@@ -978,7 +978,7 @@ RuleChain::select(double number) const {
        return next->select(number);
    }
    else {
-       return PLURAL_KEYWORD_OTHER;
+       return UnicodeString(TRUE, PLURAL_KEYWORD_OTHER, 5);
    }
 
 }
@@ -1051,11 +1051,11 @@ RuleChain::dumpRules(UnicodeString& result) {
                     }
                 }
                 if ( (andRule=andRule->next) != NULL) {
-                    result += PK_AND;
+                    result.append(PK_AND, 3);
                 }
             }
             if ( (orRule = orRule->next) != NULL ) {
-                result += PK_OR;
+                result.append(PK_OR, 2);
             }
         }
     }
@@ -1338,28 +1338,28 @@ RuleParser::getKeyType(const UnicodeString& token, tokenType& keyType, UErrorCod
     }
     if ( keyType==tNumber) {
     }
-    else if (token==PK_VAR_N) {
+    else if (0 == token.compare(PK_VAR_N, 1)) {
         keyType = tVariableN;
     }
-    else if (token==PK_IS) {
+    else if (0 == token.compare(PK_IS, 2)) {
         keyType = tIs;
     }
-    else if (token==PK_AND) {
+    else if (0 == token.compare(PK_AND, 3)) {
         keyType = tAnd;
     }
-    else if (token==PK_IN) {
+    else if (0 == token.compare(PK_IN, 2)) {
         keyType = tIn;
     }
-    else if (token==PK_WITHIN) {
+    else if (0 == token.compare(PK_WITHIN, 6)) {
         keyType = tWithin;
     }
-    else if (token==PK_NOT) {
+    else if (0 == token.compare(PK_NOT, 3)) {
         keyType = tNot;
     }
-    else if (token==PK_MOD) {
+    else if (0 == token.compare(PK_MOD, 3)) {
         keyType = tMod;
     }
-    else if (token==PK_OR) {
+    else if (0 == token.compare(PK_OR, 2)) {
         keyType = tOr;
     }
     else if ( isValidKeyword(token) ) {
@@ -1388,7 +1388,7 @@ PluralKeywordEnumeration::PluralKeywordEnumeration(RuleChain *header, UErrorCode
         if (U_FAILURE(status)) {
             return;
         }
-        if (node->keyword == PLURAL_KEYWORD_OTHER) {
+        if (0 == node->keyword.compare(PLURAL_KEYWORD_OTHER, 5)) {
             addKeywordOther= FALSE;
         }
         node=node->next;
index edd8bc9ebef267b43fdb1bf5d8d85d5b20199dc9..cd1132dea2eece5e9b6f995d32b1208396ca9ca1 100644 (file)
@@ -757,7 +757,6 @@ RuleBasedNumberFormat::RuleBasedNumberFormat(URBNFRuleSetTag tag, const Locale&
     // TODO: read localization info from resource
     LocalizationInfo* locinfo = NULL;
 
-    int32_t len = 0;
     UResourceBundle* nfrb = ures_open(U_ICUDATA_RBNF, locale.getName(), &status);
     if (U_SUCCESS(status)) {
         setLocaleIDs(ures_getLocaleByType(nfrb, ULOC_VALID_LOCALE, &status),
@@ -773,14 +772,12 @@ RuleBasedNumberFormat::RuleBasedNumberFormat(URBNFRuleSetTag tag, const Locale&
             ures_close(nfrb);
             return;
         }
-        
+
         UnicodeString desc;
         while (ures_hasNext(ruleSets)) {
-           const UChar* currentString = ures_getNextString(ruleSets,&len,NULL,&status);
-           desc.append(currentString);
+           desc.append(ures_getNextUnicodeString(ruleSets,NULL,&status));
         }
         UParseError perror;
-        
 
         init (desc, locinfo, perror, status);
 
@@ -1089,7 +1086,7 @@ RuleBasedNumberFormat::format(int32_t number,
 {
     // return format((int64_t)number, ruleSetName, toAppendTo, pos, status);
     if (U_SUCCESS(status)) {
-        if (ruleSetName.indexOf(gPercentPercent) == 0) {
+        if (ruleSetName.indexOf(gPercentPercent, 2, 0) == 0) {
             // throw new IllegalArgumentException("Can't use internal rule set");
             status = U_ILLEGAL_ARGUMENT_ERROR;
         } else {
@@ -1111,7 +1108,7 @@ RuleBasedNumberFormat::format(int64_t number,
                               UErrorCode& status) const
 {
     if (U_SUCCESS(status)) {
-        if (ruleSetName.indexOf(gPercentPercent) == 0) {
+        if (ruleSetName.indexOf(gPercentPercent, 2, 0) == 0) {
             // throw new IllegalArgumentException("Can't use internal rule set");
             status = U_ILLEGAL_ARGUMENT_ERROR;
         } else {
@@ -1143,7 +1140,7 @@ RuleBasedNumberFormat::format(double number,
                               UErrorCode& status) const
 {
     if (U_SUCCESS(status)) {
-        if (ruleSetName.indexOf(gPercentPercent) == 0) {
+        if (ruleSetName.indexOf(gPercentPercent, 2, 0) == 0) {
             // throw new IllegalArgumentException("Can't use internal rule set");
             status = U_ILLEGAL_ARGUMENT_ERROR;
         } else {
@@ -1324,7 +1321,7 @@ RuleBasedNumberFormat::init(const UnicodeString& rules, LocalizationInfo* locali
     // is, pull them out into our temporary holding place for them,
     // and delete them from the description before the real desciption-
     // parsing code sees them
-    int32_t lp = description.indexOf(gLenientParse);
+    int32_t lp = description.indexOf(gLenientParse, -1, 0);
     if (lp != -1) {
         // we've got to make sure we're not in the middle of a rule
         // (where "%%lenient-parse" would actually get treated as
@@ -1333,7 +1330,7 @@ RuleBasedNumberFormat::init(const UnicodeString& rules, LocalizationInfo* locali
             // locate the beginning and end of the actual collation
             // rules (there may be whitespace between the name and
             // the first token in the description)
-            int lpEnd = description.indexOf(gSemiPercent, lp);
+            int lpEnd = description.indexOf(gSemiPercent, 2, lp);
 
             if (lpEnd == -1) {
                 lpEnd = description.length() - 1;
@@ -1361,7 +1358,7 @@ RuleBasedNumberFormat::init(const UnicodeString& rules, LocalizationInfo* locali
     // rule sets (";%" marks the end of one rule set and the beginning
     // of the next)
     int numRuleSets = 0;
-    for (int32_t p = description.indexOf(gSemiPercent); p != -1; p = description.indexOf(gSemiPercent, p)) {
+    for (int32_t p = description.indexOf(gSemiPercent, 2, 0); p != -1; p = description.indexOf(gSemiPercent, 2, p)) {
         ++numRuleSets;
         ++p;
     }
@@ -1399,7 +1396,7 @@ RuleBasedNumberFormat::init(const UnicodeString& rules, LocalizationInfo* locali
     {
         int curRuleSet = 0;
         int32_t start = 0;
-        for (int32_t p = description.indexOf(gSemiPercent); p != -1; p = description.indexOf(gSemiPercent, start)) {
+        for (int32_t p = description.indexOf(gSemiPercent, 2, 0); p != -1; p = description.indexOf(gSemiPercent, 2, start)) {
             ruleSetDescriptions[curRuleSet].setTo(description, start, p + 1 - start);
             ruleSets[curRuleSet] = new NFRuleSet(ruleSetDescriptions, curRuleSet, status);
             if (ruleSets[curRuleSet] == 0) {
index 54132e01eb442fdc96a13c7154ead23174d85371..fcdc1c15d7c02548a418e5b213ed7c129dc224c0 100644 (file)
@@ -357,7 +357,7 @@ RuleHalf::~RuleHalf() {
 int32_t RuleHalf::parse(const UnicodeString& rule, int32_t pos, int32_t limit, UErrorCode& status) {
     int32_t start = pos;
     text.truncate(0);
-    pos = parseSection(rule, pos, limit, text, ILLEGAL_TOP, FALSE, status);
+    pos = parseSection(rule, pos, limit, text, UnicodeString(TRUE, ILLEGAL_TOP, -1), FALSE, status);
 
     if (cursorOffset > 0 && cursor != cursorOffsetPos) {
         return syntaxError(U_MISPLACED_CURSOR_OFFSET, rule, start, status);
@@ -522,7 +522,7 @@ int32_t RuleHalf::parseSection(const UnicodeString& rule, int32_t pos, int32_t l
                 int32_t segmentNumber = nextSegmentNumber++; // 1-based
                 
                 // Parse the segment
-                pos = parseSection(rule, pos, limit, buf, ILLEGAL_SEG, TRUE, status);
+                pos = parseSection(rule, pos, limit, buf, UnicodeString(TRUE, ILLEGAL_SEG, -1), TRUE, status);
                 
                 // After parsing a segment, the relevant characters are
                 // in buf, starting at offset bufSegStart.  Extract them
@@ -564,7 +564,7 @@ int32_t RuleHalf::parseSection(const UnicodeString& rule, int32_t pos, int32_t l
                 int32_t bufSegStart = buf.length();
                 
                 // Parse the segment
-                pos = parseSection(rule, iref, limit, buf, ILLEGAL_FUNC, TRUE, status);
+                pos = parseSection(rule, iref, limit, buf, UnicodeString(TRUE, ILLEGAL_FUNC, -1), TRUE, status);
                 
                 // After parsing a segment, the relevant characters are
                 // in buf, starting at offset bufSegStart.
@@ -1193,7 +1193,7 @@ static const UChar PRAGMA_NFC_RULES[] = {0x7E,0x6E,0x66,0x63,0x20,0x72,0x75,0x6C
  */
 UBool TransliteratorParser::resemblesPragma(const UnicodeString& rule, int32_t pos, int32_t limit) {
     // Must start with /use\s/i
-    return ICU_Utility::parsePattern(rule, pos, limit, PRAGMA_USE, NULL) >= 0;
+    return ICU_Utility::parsePattern(rule, pos, limit, UnicodeString(TRUE, PRAGMA_USE, 4), NULL) >= 0;
 }
 
 /**
@@ -1218,25 +1218,25 @@ int32_t TransliteratorParser::parsePragma(const UnicodeString& rule, int32_t pos
     // use maximum backup 16;
     // use nfd rules;
     // use nfc rules;
-    int p = ICU_Utility::parsePattern(rule, pos, limit, PRAGMA_VARIABLE_RANGE, array);
+    int p = ICU_Utility::parsePattern(rule, pos, limit, UnicodeString(TRUE, PRAGMA_VARIABLE_RANGE, -1), array);
     if (p >= 0) {
         setVariableRange(array[0], array[1], status);
         return p;
     }
     
-    p = ICU_Utility::parsePattern(rule, pos, limit, PRAGMA_MAXIMUM_BACKUP, array);
+    p = ICU_Utility::parsePattern(rule, pos, limit, UnicodeString(TRUE, PRAGMA_MAXIMUM_BACKUP, -1), array);
     if (p >= 0) {
         pragmaMaximumBackup(array[0]);
         return p;
     }
     
-    p = ICU_Utility::parsePattern(rule, pos, limit, PRAGMA_NFD_RULES, NULL);
+    p = ICU_Utility::parsePattern(rule, pos, limit, UnicodeString(TRUE, PRAGMA_NFD_RULES, -1), NULL);
     if (p >= 0) {
         pragmaNormalizeRules(UNORM_NFD);
         return p;
     }
     
-    p = ICU_Utility::parsePattern(rule, pos, limit, PRAGMA_NFC_RULES, NULL);
+    p = ICU_Utility::parsePattern(rule, pos, limit, UnicodeString(TRUE, PRAGMA_NFC_RULES, -1), NULL);
     if (p >= 0) {
         pragmaNormalizeRules(UNORM_NFC);
         return p;
@@ -1587,7 +1587,7 @@ void TransliteratorParser::setSegmentObject(int32_t seg, StringMatcher* adopted,
  */
 UChar TransliteratorParser::getDotStandIn(UErrorCode& status) {
     if (dotStandIn == (UChar) -1) {
-        UnicodeSet* tempus = new UnicodeSet(DOT_SET, status);
+        UnicodeSet* tempus = new UnicodeSet(UnicodeString(TRUE, DOT_SET, -1), status);
         // Null pointer check.
         if (tempus == NULL) {
             status = U_MEMORY_ALLOCATION_ERROR;
index 69a2202637458ece6a4e3bf761d2caef1836be38..c3c05cad4b5fc1f0938bfc7ba45898c0a5b9ad3a 100644 (file)
@@ -1,6 +1,6 @@
 /*
  **********************************************************************
- *   Copyright (C) 1999-2008, International Business Machines
+ *   Copyright (C) 1999-2011, International Business Machines
  *   Corporation and others.  All Rights Reserved.
  **********************************************************************
  *   Date        Name        Description
@@ -501,7 +501,7 @@ UnicodeString& TransliterationRule::toRule(UnicodeString& rule,
         rule.append((UChar)36/*$*/);
     }
 
-    ICU_Utility::appendToRule(rule, FORWARD_OP, TRUE, escapeUnprintable, quoteBuf);
+    ICU_Utility::appendToRule(rule, UnicodeString(TRUE, FORWARD_OP, 3), TRUE, escapeUnprintable, quoteBuf);
 
     // Emit the output pattern
 
index c21c79b4f94bf9bb10dc8ede7ffff145c3e3e477..4ee98f7d3cc10ac98df89a8f40cfc2d0fd1e8b06 100644 (file)
@@ -1,6 +1,6 @@
 /*
 **********************************************************************
-*   Copyright (c) 2001-2008, International Business Machines
+*   Copyright (c) 2001-2011, International Business Machines
 *   Corporation and others.  All Rights Reserved.
 **********************************************************************
 *   Date        Name        Description
@@ -35,13 +35,14 @@ static Transliterator* RemoveTransliterator_create(const UnicodeString& /*ID*/,
  */
 void RemoveTransliterator::registerIDs() {
 
-    Transliterator::_registerFactory(::CURR_ID, RemoveTransliterator_create, integerToken(0));
+    Transliterator::_registerFactory(UnicodeString(TRUE, ::CURR_ID, -1),
+                                     RemoveTransliterator_create, integerToken(0));
 
     Transliterator::_registerSpecialInverse(UNICODE_STRING_SIMPLE("Remove"),
                                             UNICODE_STRING_SIMPLE("Null"), FALSE);
 }
 
-RemoveTransliterator::RemoveTransliterator() : Transliterator(::CURR_ID, 0) {}
+RemoveTransliterator::RemoveTransliterator() : Transliterator(UnicodeString(TRUE, ::CURR_ID, -1), 0) {}
 
 RemoveTransliterator::~RemoveTransliterator() {}
 
index fb960bbf01a05257a4a8de5037174d48ee9d3965..f04f85f0dbbf9c8d15d6b32ed0dc87c753effb49 100644 (file)
@@ -1,6 +1,6 @@
 /*
  *******************************************************************************
- * Copyright (C) 1997-2010, International Business Machines Corporation and
+ * Copyright (C) 1997-2011, International Business Machines Corporation and
  * others. All Rights Reserved.
  *******************************************************************************
  *
@@ -1103,7 +1103,7 @@ SimpleTimeZone::initTransitionRules(UErrorCode& status) {
                return;
         }
         // For now, use ID + "(DST)" as the name
-        dstRule = new AnnualTimeZoneRule(tzid+DST_STR, getRawOffset(), getDSTSavings(),
+        dstRule = new AnnualTimeZoneRule(tzid+UnicodeString(DST_STR), getRawOffset(), getDSTSavings(),
             dtRule, startYear, AnnualTimeZoneRule::MAX_YEAR);
         
         // Check for Null pointer
@@ -1141,7 +1141,7 @@ SimpleTimeZone::initTransitionRules(UErrorCode& status) {
                return;
         }
         // For now, use ID + "(STD)" as the name
-        stdRule = new AnnualTimeZoneRule(tzid+STD_STR, getRawOffset(), 0,
+        stdRule = new AnnualTimeZoneRule(tzid+UnicodeString(STD_STR), getRawOffset(), 0,
             dtRule, startYear, AnnualTimeZoneRule::MAX_YEAR);
         
         //Check for Null pointer
@@ -1156,10 +1156,10 @@ SimpleTimeZone::initTransitionRules(UErrorCode& status) {
 
         // Create a TimeZoneRule for initial time
         if (firstStdStart < firstDstStart) {
-            initialRule = new InitialTimeZoneRule(tzid+DST_STR, getRawOffset(), dstRule->getDSTSavings());
+            initialRule = new InitialTimeZoneRule(tzid+UnicodeString(DST_STR), getRawOffset(), dstRule->getDSTSavings());
             firstTransition = new TimeZoneTransition(firstStdStart, *initialRule, *stdRule);
         } else {
-            initialRule = new InitialTimeZoneRule(tzid+STD_STR, getRawOffset(), 0);
+            initialRule = new InitialTimeZoneRule(tzid+UnicodeString(STD_STR), getRawOffset(), 0);
             firstTransition = new TimeZoneTransition(firstDstStart, *initialRule, *dstRule);
         }
         // Check for null pointers.
index 2c0d6caef59230f6f507eabb4a7cdebf2f33f21b..d1df7eda8bad83eba0b23285ac2ad72f4361ca0d 100644 (file)
@@ -1100,10 +1100,10 @@ SimpleDateFormat::parseGMT(const UnicodeString &text, ParsePosition &pos) const
 void
 SimpleDateFormat::formatGMTDefault(NumberFormat *currentNumberFormat,UnicodeString &appendTo, int32_t offset) const {
     if (offset < 0) {
-        appendTo += gGmtMinus;
+        appendTo.append(gGmtMinus, 4);
         offset = -offset; // suppress the '-' sign for text display.
     }else{
-        appendTo += gGmtPlus;
+        appendTo.append(gGmtPlus, 4);
     }
 
     offset /= U_MILLIS_PER_SECOND; // now in seconds
@@ -3178,7 +3178,7 @@ void SimpleDateFormat::parseInt(const UnicodeString& text,
     DecimalFormat* df = NULL;
     if (!allowNegative && (df = dynamic_cast<DecimalFormat*>(fmt)) != NULL) {
         df->getNegativePrefix(oldPrefix);
-        df->setNegativePrefix(SUPPRESS_NEGATIVE_PREFIX);
+        df->setNegativePrefix(UnicodeString(TRUE, SUPPRESS_NEGATIVE_PREFIX, -1));
     }
     int32_t oldPos = pos.getIndex();
     fmt->parse(text, number, pos);
@@ -3264,7 +3264,9 @@ UnicodeString&
 SimpleDateFormat::toLocalizedPattern(UnicodeString& result,
                                      UErrorCode& status) const
 {
-    translatePattern(fPattern, result, DateFormatSymbols::getPatternUChars(), fSymbols->fLocalPatternChars, status);
+    translatePattern(fPattern, result,
+                     UnicodeString(DateFormatSymbols::getPatternUChars()),
+                     fSymbols->fLocalPatternChars, status);
     return result;
 }
 
@@ -3282,7 +3284,9 @@ void
 SimpleDateFormat::applyLocalizedPattern(const UnicodeString& pattern,
                                         UErrorCode &status)
 {
-    translatePattern(pattern, fPattern, fSymbols->fLocalPatternChars, DateFormatSymbols::getPatternUChars(), status);
+    translatePattern(pattern, fPattern,
+                     fSymbols->fLocalPatternChars,
+                     UnicodeString(DateFormatSymbols::getPatternUChars()), status);
 }
 
 //----------------------------------------------------------------------
index 8286c7eaa0757494d4298c4ad98eb721e76a75f8..242d83a57cfa24878c9e0259e24f9e011424e872 100644 (file)
@@ -1,6 +1,6 @@
 /*
 **********************************************************************
-*   Copyright (c) 2001-2004, International Business Machines Corporation
+*   Copyright (c) 2001-2011, International Business Machines Corporation
 *   and others.  All Rights Reserved.
 **********************************************************************
 *   Date        Name        Description
@@ -19,8 +19,6 @@
 
 U_NAMESPACE_BEGIN
 
-static const UChar EMPTY[] = { 0 }; // empty string: ""
-
 UOBJECT_DEFINE_RTTI_IMPLEMENTATION(StringMatcher)
 
 StringMatcher::StringMatcher(const UnicodeString& theString,
@@ -228,7 +226,7 @@ int32_t StringMatcher::replace(Replaceable& text,
         }
     }
     
-    text.handleReplaceBetween(start, limit, EMPTY); // delete original text
+    text.handleReplaceBetween(start, limit, UnicodeString()); // delete original text
     
     return outLen;
 }
index 4ae12b05c24ff50c90a79f42bb27c7e24df8d1fe..f05c9c90c486dd5d79f462628381e1f56b14638d 100644 (file)
@@ -1,6 +1,6 @@
 /*
 **********************************************************************
-*   Copyright (c) 2002-2004, International Business Machines Corporation
+*   Copyright (c) 2002-2011, International Business Machines Corporation
 *   and others.  All Rights Reserved.
 **********************************************************************
 *   Date        Name        Description
@@ -19,8 +19,6 @@
 
 U_NAMESPACE_BEGIN
 
-static const UChar EMPTY[] = { 0 }; // empty string: ""
-
 UnicodeReplacer::~UnicodeReplacer() {}
 UOBJECT_DEFINE_RTTI_IMPLEMENTATION(StringReplacer)
 
@@ -194,10 +192,10 @@ int32_t StringReplacer::replace(Replaceable& text,
 
         // Copy new text to start, and delete it
         text.copy(destStart, destLimit, start);
-        text.handleReplaceBetween(tempStart + outLen, destLimit + outLen, EMPTY);
+        text.handleReplaceBetween(tempStart + outLen, destLimit + outLen, UnicodeString());
 
         // Delete the old text (the key)
-        text.handleReplaceBetween(start + outLen, limit + outLen, EMPTY);
+        text.handleReplaceBetween(start + outLen, limit + outLen, UnicodeString());
     }        
 
     if (hasCursor) {
index 3b21f35c95cb4104d629e2b9e6007612a7a21fe7..9df9659f674f7de2737decde29cdb8fc5b270312 100644 (file)
@@ -389,7 +389,7 @@ TimeZone::createTimeZone(const UnicodeString& ID)
     }
     if (result == 0) {
         U_DEBUG_TZ_MSG(("failed to load time zone with id - falling to Etc/Unknown(GMT)"));
-        result = new SimpleTimeZone(0, UNKNOWN_ZONE_ID);
+        result = new SimpleTimeZone(0, UnicodeString(TRUE, UNKNOWN_ZONE_ID, UNKNOWN_ZONE_ID_LENGTH));
     }
     return result;
 }
@@ -715,11 +715,11 @@ private:
             } else {
                 int32_t numEntries = 0;
                 for (int32_t i = 0; i < size; i++) {
-                    const UChar *id = ures_getStringByIndex(res, i, NULL, &ec);
+                    UnicodeString id = ures_getUnicodeStringByIndex(res, i, &ec);
                     if (U_FAILURE(ec)) {
                         break;
                     }
-                    if (u_strcmp(id, UNKNOWN_ZONE_ID) == 0) {
+                    if (0 == id.compare(UNKNOWN_ZONE_ID, UNKNOWN_ZONE_ID_LENGTH)) {
                         // exclude Etc/Unknown
                         continue;
                     }
@@ -729,7 +729,7 @@ private:
                         if (U_FAILURE(ec)) {
                             break;
                         }
-                        if (canonicalID.compare(id, -1) != 0) {
+                        if (canonicalID != id) {
                             // exclude aliases
                             continue;
                         }
@@ -836,7 +836,7 @@ public:
             res = ures_getByKey(res, kNAMES, res, &ec); // dereference Zones section
             for (int32_t i = 0; i < baseLen; i++) {
                 int32_t zidx = baseMap[i];
-                const UChar *id = ures_getStringByIndex(res, zidx, NULL, &ec);
+                UnicodeString id = ures_getUnicodeStringByIndex(res, zidx, &ec);
                 if (U_FAILURE(ec)) {
                     break;
                 }
@@ -1217,35 +1217,36 @@ TimeZone::getDisplayName(UBool daylight, EDisplayType style, const Locale& local
 #endif
 
     // select the proper format string
-    UnicodeString pat;
+    const UChar* patUChars;
     switch(style){
     case LONG:
-        pat = ZZZZ_STR;
+        patUChars = ZZZZ_STR;
         break;
     case SHORT_GENERIC:
-        pat = V_STR;
+        patUChars = V_STR;
         break;
     case LONG_GENERIC:
-        pat = VVVV_STR;
+        patUChars = VVVV_STR;
         break;
     case SHORT_GMT:
-        pat = Z_UC_STR;
+        patUChars = Z_UC_STR;
         break;
     case LONG_GMT:
-        pat = ZZZZ_UC_STR;
+        patUChars = ZZZZ_UC_STR;
         break;
     case SHORT_COMMONLY_USED:
-        //pat = V_UC_STR;
-        pat = Z_STR;
+        //patUChars = V_UC_STR;
+        patUChars = Z_STR;
         break;
     case GENERIC_LOCATION:
-        pat = VVVV_UC_STR;
+        patUChars = VVVV_UC_STR;
         break;
     default: // SHORT
-        //pat = Z_STR;
-        pat = V_UC_STR;
+        //patUChars = Z_STR;
+        patUChars = V_UC_STR;
         break;
     }
+    UnicodeString pat(TRUE, patUChars, -1);
 
     SimpleDateFormat format(pat, locale, status);
     U_DEBUG_TZ_MSG(("getDisplayName(%s)\n", buf));
@@ -1375,7 +1376,7 @@ TimeZone::parseCustomID(const UnicodeString& id, int32_t& sign,
     idUppercase.toUpper();
 
     if (id.length() > GMT_ID_LENGTH &&
-        idUppercase.startsWith(GMT_ID))
+        idUppercase.startsWith(GMT_ID, GMT_ID_LENGTH))
     {
         ParsePosition pos(GMT_ID_LENGTH);
         sign = 1;
@@ -1491,7 +1492,7 @@ UnicodeString&
 TimeZone::formatCustomID(int32_t hour, int32_t min, int32_t sec,
                          UBool negative, UnicodeString& id) {
     // Create time zone ID - GMT[+|-]hhmm[ss]
-    id.setTo(GMT_ID);
+    id.setTo(GMT_ID, GMT_ID_LENGTH);
     if (hour | min | sec) {
         if (negative) {
             id += (UChar)MINUS;
index dbd3ec6e4a754d38df2e8277a7024e57d58ce4cf..9a40fc427d567330a04f3061a4b0adf1c4b859fc 100644 (file)
@@ -325,11 +325,11 @@ TimeUnitFormat::parseObject(const UnicodeString& source,
      */
     if (withNumberFormat == false && longestParseDistance != 0) {
         // set the number using plurrual count
-        if ( *countOfLongestMatch == PLURAL_COUNT_ZERO ) {
+        if (0 == countOfLongestMatch->compare(PLURAL_COUNT_ZERO, 4)) {
             resultNumber = 0;
-        } else if ( *countOfLongestMatch == PLURAL_COUNT_ONE ) {
+        } else if (0 == countOfLongestMatch->compare(PLURAL_COUNT_ONE, 3)) {
             resultNumber = 1;
-        } else if ( *countOfLongestMatch == PLURAL_COUNT_TWO ) {
+        } else if (0 == countOfLongestMatch->compare(PLURAL_COUNT_TWO, 3)) {
             resultNumber = 2;
         } else {
             // should not happen.
@@ -481,13 +481,11 @@ TimeUnitFormat::readFromCurrentLocale(UTimeUnitFormatStyle style, const char* ke
                 }
             }
             int32_t count = ures_getSize(countsToPatternRB);
-            const UChar* pattern;
             const char*  pluralCount;
-            int32_t ptLength; 
             for ( int32_t pluralIndex = 0; pluralIndex < count; ++pluralIndex) {
                 // resource of count to pattern
-                pattern = ures_getNextString(countsToPatternRB, &ptLength,
-                                             &pluralCount, &status);
+                UnicodeString pattern =
+                    ures_getNextUnicodeString(countsToPatternRB, &pluralCount, &status);
                 if (U_FAILURE(status)) {
                     continue;
                 }
@@ -629,7 +627,7 @@ TimeUnitFormat::searchInLocaleChain(UTimeUnitFormatStyle style, const char* key,
         pattern = ures_getStringByKeyWithFallback(countsToPatternRB, searchPluralCount, &ptLength, &status);
         if (U_SUCCESS(status)) {
             //found
-            MessageFormat* messageFormat = new MessageFormat(pattern, fLocale, err);
+            MessageFormat* messageFormat = new MessageFormat(UnicodeString(TRUE, pattern, ptLength), fLocale, err);
             if (U_SUCCESS(err)) {
                 if (fNumberFormat != NULL) {
                     messageFormat->setFormat(0, *fNumberFormat);
@@ -690,20 +688,24 @@ TimeUnitFormat::searchInLocaleChain(UTimeUnitFormatStyle style, const char* key,
     if ( uprv_strcmp(searchPluralCount, gPluralCountOther) == 0 ) {
         // set default fall back the same as the resource in root
         MessageFormat* messageFormat = NULL;
+        const UChar *pattern = NULL;
         if ( srcTimeUnitField == TimeUnit::UTIMEUNIT_SECOND ) {
-            messageFormat = new MessageFormat(DEFAULT_PATTERN_FOR_SECOND, fLocale, err);
+            pattern = DEFAULT_PATTERN_FOR_SECOND;
         } else if ( srcTimeUnitField == TimeUnit::UTIMEUNIT_MINUTE ) {
-            messageFormat = new MessageFormat(DEFAULT_PATTERN_FOR_MINUTE, fLocale, err);
+            pattern = DEFAULT_PATTERN_FOR_MINUTE;
         } else if ( srcTimeUnitField == TimeUnit::UTIMEUNIT_HOUR ) {
-            messageFormat = new MessageFormat(DEFAULT_PATTERN_FOR_HOUR, fLocale, err);
+            pattern = DEFAULT_PATTERN_FOR_HOUR;
         } else if ( srcTimeUnitField == TimeUnit::UTIMEUNIT_WEEK ) {
-            messageFormat = new MessageFormat(DEFAULT_PATTERN_FOR_WEEK, fLocale, err);
+            pattern = DEFAULT_PATTERN_FOR_WEEK;
         } else if ( srcTimeUnitField == TimeUnit::UTIMEUNIT_DAY ) {
-            messageFormat = new MessageFormat(DEFAULT_PATTERN_FOR_DAY, fLocale, err);
+            pattern = DEFAULT_PATTERN_FOR_DAY;
         } else if ( srcTimeUnitField == TimeUnit::UTIMEUNIT_MONTH ) {
-            messageFormat = new MessageFormat(DEFAULT_PATTERN_FOR_MONTH, fLocale, err);
+            pattern = DEFAULT_PATTERN_FOR_MONTH;
         } else if ( srcTimeUnitField == TimeUnit::UTIMEUNIT_YEAR ) {
-            messageFormat = new MessageFormat(DEFAULT_PATTERN_FOR_YEAR, fLocale, err);
+            pattern = DEFAULT_PATTERN_FOR_YEAR;
+        }
+        if (pattern != NULL) {
+            messageFormat = new MessageFormat(UnicodeString(TRUE, pattern, -1), fLocale, err);
         }
         if (U_SUCCESS(err)) {
             if (fNumberFormat != NULL && messageFormat != NULL) {
index 2bbdb48e2c319053c2342c29bf34f638a29ab08e..b1a1253c1faf7a4fe9c0949e25ef99f00dc66c96 100644 (file)
@@ -99,9 +99,6 @@ static icu::TransliteratorRegistry* registry = 0;
 // MUTEX. Avoids function call when registry is initialized.
 #define HAVE_REGISTRY(status) (registry!=0 || initializeRegistry(status))
 
-// Empty string
-static const UChar EMPTY[] = {0}; //""
-
 U_NAMESPACE_BEGIN
 
 UOBJECT_DEFINE_ABSTRACT_RTTI_IMPLEMENTATION(Transliterator)
@@ -598,7 +595,7 @@ void Transliterator::filteredTransliterate(Replaceable& text,
                     int32_t rs = rollbackStart + delta - (index.limit - passStart);
 
                     // Delete the partially transliterated text
-                    text.handleReplaceBetween(passStart, index.limit, EMPTY);
+                    text.handleReplaceBetween(passStart, index.limit, UnicodeString());
 
                     // Copy the rollback text back
                     text.copy(rs, rs + uncommittedLength, passStart);
@@ -636,7 +633,7 @@ void Transliterator::filteredTransliterate(Replaceable& text,
             globalLimit += totalDelta;
 
             // Delete the rollback copy
-            text.handleReplaceBetween(rollbackOrigin, rollbackOrigin + runLength, EMPTY);
+            text.handleReplaceBetween(rollbackOrigin, rollbackOrigin + runLength, UnicodeString());
 
             // Move start past committed text
             index.start = passStart;
@@ -1110,7 +1107,8 @@ Transliterator::createFromRules(const UnicodeString& ID,
             }
             if (!parser.dataVector.isEmpty()) {
                 TransliterationRuleData* data = (TransliterationRuleData*)parser.dataVector.orphanElementAt(0);
-                RuleBasedTransliterator* temprbt = new RuleBasedTransliterator(UnicodeString(CompoundTransliterator::PASS_STRING) + (passNumber++),
+                // TODO: Should passNumber be turned into a decimal-string representation (1 -> "1")?
+                RuleBasedTransliterator* temprbt = new RuleBasedTransliterator(UnicodeString(CompoundTransliterator::PASS_STRING) + UnicodeString(passNumber++),
                         data, TRUE);
                 // Check if NULL before adding it to transliterators to avoid future usage of NULL pointer.
                 if (temprbt == NULL) {
index 90f0adafbeb9c0c61c494dd33bd1182ae82efc82..77281511b0b11e0cbfbcbd3b0d9f6a9e08bc7ea2 100644 (file)
@@ -44,9 +44,11 @@ static const UChar LOCALE_SEP  = 95; // '_'
 //static const UChar VARIANT_SEP = 0x002F; // '/'
 
 // String constants
-static const UChar NO_VARIANT[] = { 0 }; // empty string
 static const UChar ANY[] = { 65, 110, 121, 0 }; // Any
 
+// empty string
+#define NO_VARIANT UnicodeString()
+
 /**
  * Resource bundle key for the RuleBasedTransliterator rule.
  */
@@ -868,7 +870,7 @@ void TransliteratorRegistry::registerEntry(const UnicodeString& source,
     UnicodeString ID;
     UnicodeString s(source);
     if (s.length() == 0) {
-        s = ANY;
+        s.setTo(TRUE, ANY, 3);
     }
     TransliteratorIDParser::STVtoID(source, target, variant, ID);
     registerEntry(ID, s, target, variant, adopted, visible);
@@ -959,7 +961,7 @@ void TransliteratorRegistry::registerSTV(const UnicodeString& source,
                        variants->addElement(tempus, status);
                }
         } else {
-               tempus = new UnicodeString(NO_VARIANT) ;
+               tempus = new UnicodeString();  // = NO_VARIANT
                if (tempus != NULL) {
                        variants->insertElementAt(tempus, 0, status);
                }
@@ -1073,9 +1075,9 @@ TransliteratorEntry* TransliteratorRegistry::findInBundle(const TransliteratorSp
         // but must be consistent and documented.
         if (pass == 0) {
             utag.append(direction == UTRANS_FORWARD ?
-                        TRANSLITERATE_TO : TRANSLITERATE_FROM);
+                        TRANSLITERATE_TO : TRANSLITERATE_FROM, -1);
         } else {
-            utag.append(TRANSLITERATE);
+            utag.append(TRANSLITERATE, -1);
         }
         UnicodeString s(specToFind.get());
         utag.append(s.toUpper(""));
@@ -1282,7 +1284,8 @@ Transliterator* TransliteratorRegistry::instantiateEntry(const UnicodeString& ID
             }
             int32_t passNumber = 1;
             for (int32_t i = 0; U_SUCCESS(status) && i < entry->u.dataVector->size(); i++) {
-                Transliterator* t = new RuleBasedTransliterator(UnicodeString(CompoundTransliterator::PASS_STRING) + (passNumber++),
+                // TODO: Should passNumber be turned into a decimal-string representation (1 -> "1")?
+                Transliterator* t = new RuleBasedTransliterator(UnicodeString(CompoundTransliterator::PASS_STRING) + UnicodeString(passNumber++),
                     (TransliterationRuleData*)(entry->u.dataVector->elementAt(i)), FALSE);
                 if (t == 0)
                     status = U_MEMORY_ALLOCATION_ERROR;
index 56cec9521d22279df529d10fb3215d8ca6123346..b195e5234ede8d102e18f16c7b52983fcb61db72 100644 (file)
@@ -72,7 +72,7 @@ TransliteratorIDParser::SingleID::SingleID(const UnicodeString& c, const Unicode
 Transliterator* TransliteratorIDParser::SingleID::createInstance() {
     Transliterator* t;
     if (basicID.length() == 0) {
-        t = createBasicInstance(ANY_NULL, &canonID);
+        t = createBasicInstance(UnicodeString(TRUE, ANY_NULL, 8), &canonID);
     } else {
         t = createBasicInstance(basicID, &canonID);
     }
@@ -498,7 +498,7 @@ void TransliteratorIDParser::instantiateList(UVector& list,
 
     // An empty list is equivalent to a NULL transliterator.
     if (tlist.size() == 0) {
-        t = createBasicInstance(ANY_NULL, NULL);
+        t = createBasicInstance(UnicodeString(TRUE, ANY_NULL, 8), NULL);
         if (t == NULL) {
             // Should never happen
             ec = U_INTERNAL_TRANSLITERATOR_ERROR;
@@ -547,7 +547,7 @@ void TransliteratorIDParser::IDtoSTV(const UnicodeString& id,
                                      UnicodeString& target,
                                      UnicodeString& variant,
                                      UBool& isSourcePresent) {
-    source = ANY;
+    source.setTo(ANY, 3);
     target.truncate(0);
     variant.truncate(0);
 
@@ -596,7 +596,7 @@ void TransliteratorIDParser::STVtoID(const UnicodeString& source,
                                      UnicodeString& id) {
     id = source;
     if (id.length() == 0) {
-        id = ANY;
+        id.setTo(ANY, 3);
     }
     id.append(TARGET_SEP).append(target);
     if (variant.length() != 0) {
@@ -791,11 +791,11 @@ TransliteratorIDParser::parseFilterID(const UnicodeString& id, int32_t& pos,
     // Empty source or target defaults to ANY
     UBool sawSource = TRUE;
     if (source.length() == 0) {
-        source = ANY;
+        source.setTo(ANY, 3);
         sawSource = FALSE;
     }
     if (target.length() == 0) {
-        target = ANY;
+        target.setTo(ANY, 3);
     }
 
     return new Specs(source, target, variant, sawSource, filter);
@@ -848,7 +848,7 @@ TransliteratorIDParser::specsToID(const Specs* specs, int32_t dir) {
  */
 TransliteratorIDParser::SingleID*
 TransliteratorIDParser::specsToSpecialInverse(const Specs& specs, UErrorCode &status) {
-    if (0!=specs.source.caseCompare(ANY, U_FOLD_CASE_DEFAULT)) {
+    if (0!=specs.source.caseCompare(ANY, 3, U_FOLD_CASE_DEFAULT)) {
         return NULL;
     }
     init(status);
@@ -868,11 +868,11 @@ TransliteratorIDParser::specsToSpecialInverse(const Specs& specs, UErrorCode &st
             buf.append(specs.filter);
         }
         if (specs.sawSource) {
-            buf.append(ANY).append(TARGET_SEP);
+            buf.append(ANY, 3).append(TARGET_SEP);
         }
         buf.append(*inverseTarget);
 
-        UnicodeString basicID(ANY);
+        UnicodeString basicID(TRUE, ANY, 3);
         basicID.append(TARGET_SEP).append(*inverseTarget);
 
         if (specs.variant.length() != 0) {
index 24aaf1ce1d5616fb5b04b7cd4d218c4aea77b564..968ed57af93968b812cca79602aa6f9ee358de1b 100644 (file)
@@ -1,7 +1,7 @@
 /*
 *******************************************************************************
-* Copyright (C) 2011, International Business Machines Corporation and         *
-* others. All Rights Reserved.                                                *
+* Copyright (C) 2011, International Business Machines Corporation and
+* others. All Rights Reserved.
 *******************************************************************************
 */
 
@@ -66,7 +66,7 @@ hashPartialLocationKey(const UHashTok key) {
     PartialLocationKey *p = (PartialLocationKey *)key.pointer;
     UnicodeString str(p->tzID);
     str.append((UChar)0x26)
-        .append(p->mzID)
+        .append(p->mzID, -1)
         .append((UChar)0x23)
         .append((UChar)(p->isLong ? 0x4C : 0x53));
     return str.hashCode();
@@ -303,17 +303,17 @@ TimeZoneGenericNames::initialize(const Locale& locale, UErrorCode& status) {
     if (U_SUCCESS(tmpsts)) {
         const UChar *regionPattern = ures_getStringByKeyWithFallback(zoneStrings, gRegionFormatTag, NULL, &tmpsts);
         if (U_SUCCESS(tmpsts) && u_strlen(regionPattern) > 0) {
-            rpat.setTo(regionPattern);
+            rpat.setTo(regionPattern, -1);
         }
         tmpsts = U_ZERO_ERROR;
         const UChar *fallbackRegionPattern = ures_getStringByKeyWithFallback(zoneStrings, gFallbackRegionFormatTag, NULL, &tmpsts);
         if (U_SUCCESS(tmpsts) && u_strlen(fallbackRegionPattern) > 0) {
-            frpat.setTo(fallbackRegionPattern);
+            frpat.setTo(fallbackRegionPattern, -1);
         }
         tmpsts = U_ZERO_ERROR;
         const UChar *fallbackPattern = ures_getStringByKeyWithFallback(zoneStrings, gFallbackFormatTag, NULL, &tmpsts);
         if (U_SUCCESS(tmpsts) && u_strlen(fallbackPattern) > 0) {
-            fpat.setTo(fallbackPattern);
+            fpat.setTo(fallbackPattern, -1);
         }
     }
     ures_close(zoneStrings);
index e68833c5a6a639b1a6a47d8cee42829b60216748..5460eae973e96a71d1d9fb0ce93cd4933ff76120 100644 (file)
@@ -707,7 +707,7 @@ MetaZoneIDsEnumeration::MetaZoneIDsEnumeration(UVector *mzIDs)
 const UnicodeString*
 MetaZoneIDsEnumeration::snext(UErrorCode& status) {
     if (U_SUCCESS(status) && fMetaZoneIDs != NULL && fPos < fLen) {
-        unistr.setTo((const UChar*)fMetaZoneIDs->elementAt(fPos++));
+        unistr.setTo((const UChar*)fMetaZoneIDs->elementAt(fPos++), -1);
         return &unistr;
     }
     return NULL;
index bd789acef33b63114926296831b96f911cbeed5b..ffad4ff364e370f80f4e1d9c7a157c50f851f145 100644 (file)
@@ -769,7 +769,7 @@ getCurrencyNameCount(const char* loc, int32_t* total_currency_name_count, int32_
                 }
             }
             if (isChoice) {
-                ChoiceFormat fmt(s, ec2);
+                ChoiceFormat fmt(UnicodeString(TRUE, s, len), ec2);
                 int32_t fmt_count;
                 fmt.getFormats(fmt_count);
                 *total_currency_symbol_count += fmt_count;
@@ -892,7 +892,7 @@ collectCurrencyNames(const char* locale,
                 }
             }
             if (isChoice) {
-                ChoiceFormat fmt(s, ec2);
+                ChoiceFormat fmt(UnicodeString(TRUE, s, len), ec2);
                 int32_t fmt_count;
                 const UnicodeString* formats = fmt.getFormats(fmt_count);
                 for (int i = 0; i < fmt_count; ++i) {
@@ -1434,14 +1434,14 @@ uprv_getStaticCurrencyName(const UChar* iso, const char* loc,
         // arbitrary value; pick something != 1; more common.
         result.truncate(0);
         if (isChoiceFormat) {
-            ChoiceFormat f(currname, ec);
+            ChoiceFormat f(UnicodeString(TRUE, currname, len), ec);
             if (U_SUCCESS(ec)) {
                 f.format(2.0, result);
             } else {
-                result = iso;
+                result.setTo(iso, -1);
             }
         } else {
-            result = currname;
+            result.setTo(currname, -1);
         }
     }
 }
index 6c8a09c2648d5d1d919d39552b129e9db2e87c27..8b2bb66836ea92fe93b959f472cbf874898aba61 100644 (file)
@@ -442,7 +442,7 @@ umsg_vformat(   const UMessageFormat *fmt,
             // For some reason, a temporary is needed
             stringVal = va_arg(ap, UChar*);
             if(stringVal){
-                args[i].setString(stringVal);
+                args[i].setString(UnicodeString(stringVal));
             }else{
                 *status=U_ILLEGAL_ARGUMENT_ERROR;
             }
@@ -526,7 +526,7 @@ umsg_vparse(const UMessageFormat *fmt,
     }
 
     UnicodeString srcString(source,sourceLength);
-    Formattable *args = ((const MessageFormat*)fmt)->parse(source,*count,*status);
+    Formattable *args = ((const MessageFormat*)fmt)->parse(srcString,*count,*status);
     UDate *aDate;
     double *aDouble;
     UChar *aString;
index 331049ee317d4d26c9ee07600bcf128c01a45b78..fde9621a3a004f5a75f92a6cd3ac0879696132a5 100644 (file)
@@ -723,8 +723,7 @@ unum_setTextAttribute(    UNumberFormat*                    fmt,
     if(U_FAILURE(*status))
         return;
 
-    int32_t len = (newValueLength == -1 ? u_strlen(newValue) : newValueLength);
-    const UnicodeString val((UChar*)newValue, len, len);
+    UnicodeString val(newValue, newValueLength);
     NumberFormat* nf = reinterpret_cast<NumberFormat*>(fmt);
     DecimalFormat* df = dynamic_cast<DecimalFormat*>(nf);
     if (df != NULL) {
@@ -746,11 +745,11 @@ unum_setTextAttribute(    UNumberFormat*                    fmt,
         break;
         
       case UNUM_PADDING_CHARACTER:
-        df->setPadCharacter(*newValue);
+        df->setPadCharacter(val);
         break;
         
       case UNUM_CURRENCY_CODE:
-        df->setCurrency(newValue, *status);
+        df->setCurrency(val.getTerminatedBuffer(), *status);
         break;
         
       default:
@@ -761,7 +760,7 @@ unum_setTextAttribute(    UNumberFormat*                    fmt,
       RuleBasedNumberFormat* rbnf = dynamic_cast<RuleBasedNumberFormat*>(nf);
       U_ASSERT(rbnf != NULL);
       if (tag == UNUM_DEFAULT_RULESET) {
-        rbnf->setDefaultRuleSet(newValue, *status);
+        rbnf->setDefaultRuleSet(val, *status);
       } else {
         *status = U_UNSUPPORTED_ERROR;
       }
index 7d5eb0197b593e6e4f511e9a71f6e4ee9031f605..8e8689ffbaeb5d22963e44c02b73aadd12dedc55 100644 (file)
@@ -413,20 +413,20 @@ static void parseRRULE(const UnicodeString& rrule, int32_t& month, int32_t& dow,
             goto rruleParseError;
         }
 
-        if (attr.compare(ICAL_FREQ) == 0) {
+        if (attr.compare(ICAL_FREQ, -1) == 0) {
             // only support YEARLY frequency type
-            if (value.compare(ICAL_YEARLY) == 0) {
+            if (value.compare(ICAL_YEARLY, -1) == 0) {
                 yearly = TRUE;
             } else {
                 goto rruleParseError;
             }
-        } else if (attr.compare(ICAL_UNTIL) == 0) {
+        } else if (attr.compare(ICAL_UNTIL, -1) == 0) {
             // ISO8601 UTC format, for example, "20060315T020000Z"
             until = parseDateTimeString(value, 0, status);
             if (U_FAILURE(status)) {
                 goto rruleParseError;
             }
-        } else if (attr.compare(ICAL_BYMONTH) == 0) {
+        } else if (attr.compare(ICAL_BYMONTH, -1) == 0) {
             // Note: BYMONTH may contain multiple months, but only single month make sense for
             // VTIMEZONE property.
             if (value.length() > 2) {
@@ -436,7 +436,7 @@ static void parseRRULE(const UnicodeString& rrule, int32_t& month, int32_t& dow,
             if (U_FAILURE(status) || month < 0 || month >= 12) {
                 goto rruleParseError;
             }
-        } else if (attr.compare(ICAL_BYDAY) == 0) {
+        } else if (attr.compare(ICAL_BYDAY, -1) == 0) {
             // Note: BYDAY may contain multiple day of week separated by comma.  It is unlikely used for
             // VTIMEZONE property.  We do not support the case.
 
@@ -475,7 +475,7 @@ static void parseRRULE(const UnicodeString& rrule, int32_t& month, int32_t& dow,
             } else {
                 goto rruleParseError;
             }
-        } else if (attr.compare(ICAL_BYMONTHDAY) == 0) {
+        } else if (attr.compare(ICAL_BYMONTHDAY, -1) == 0) {
             // Note: BYMONTHDAY may contain multiple days delimitted by comma
             //
             // A value of BYMONTHDAY could be negative, for example, -1 means
@@ -885,6 +885,7 @@ public:
 
     void write(const UnicodeString& str);
     void write(UChar ch);
+    void write(const UChar* str);
     //void write(const UChar* str, int32_t length);
 private:
     UnicodeString* out;
@@ -907,6 +908,11 @@ VTZWriter::write(UChar ch) {
     out->append(ch);
 }
 
+void
+VTZWriter::write(const UChar* str) {
+    out->append(str, -1);
+}
+
 /*
 void
 VTZWriter::write(const UChar* str, int32_t length) {
@@ -1254,7 +1260,7 @@ VTimeZone::load(VTZReader& reader, UErrorCode& status) {
         UChar ch = reader.read();
         if (ch == 0xFFFF) {
             // end of file
-            if (start && line.startsWith(ICAL_END_VTIMEZONE)) {
+            if (start && line.startsWith(ICAL_END_VTIMEZONE, -1)) {
                 vtzlines->addElement(new UnicodeString(line), status);
                 if (U_FAILURE(status)) {
                     goto cleanupVtzlines;
@@ -1289,7 +1295,7 @@ VTimeZone::load(VTZReader& reader, UErrorCode& status) {
                 // LF
                 eol = TRUE;
                 if (start) {
-                    if (line.startsWith(ICAL_END_VTIMEZONE)) {
+                    if (line.startsWith(ICAL_END_VTIMEZONE, -1)) {
                         vtzlines->addElement(new UnicodeString(line), status);
                         if (U_FAILURE(status)) {
                             goto cleanupVtzlines;
@@ -1298,7 +1304,7 @@ VTimeZone::load(VTZReader& reader, UErrorCode& status) {
                         break;
                     }
                 } else {
-                    if (line.startsWith(ICAL_BEGIN_VTIMEZONE)) {
+                    if (line.startsWith(ICAL_BEGIN_VTIMEZONE, -1)) {
                         vtzlines->addElement(new UnicodeString(line), status);
                         if (U_FAILURE(status)) {
                             goto cleanupVtzlines;
@@ -1397,27 +1403,27 @@ VTimeZone::parse(UErrorCode& status) {
 
         switch (state) {
         case INI:
-            if (name.compare(ICAL_BEGIN) == 0
-                && value.compare(ICAL_VTIMEZONE) == 0) {
+            if (name.compare(ICAL_BEGIN, -1) == 0
+                && value.compare(ICAL_VTIMEZONE, -1) == 0) {
                 state = VTZ;
             }
             break;
 
         case VTZ:
-            if (name.compare(ICAL_TZID) == 0) {
+            if (name.compare(ICAL_TZID, -1) == 0) {
                 tzid = value;
-            } else if (name.compare(ICAL_TZURL) == 0) {
+            } else if (name.compare(ICAL_TZURL, -1) == 0) {
                 tzurl = value;
-            } else if (name.compare(ICAL_LASTMOD) == 0) {
+            } else if (name.compare(ICAL_LASTMOD, -1) == 0) {
                 // Always in 'Z' format, so the offset argument for the parse method
                 // can be any value.
                 lastmod = parseDateTimeString(value, 0, status);
                 if (U_FAILURE(status)) {
                     goto cleanupParse;
                 }
-            } else if (name.compare(ICAL_BEGIN) == 0) {
-                UBool isDST = (value.compare(ICAL_DAYLIGHT) == 0);
-                if (value.compare(ICAL_STANDARD) == 0 || isDST) {
+            } else if (name.compare(ICAL_BEGIN, -1) == 0) {
+                UBool isDST = (value.compare(ICAL_DAYLIGHT, -1) == 0);
+                if (value.compare(ICAL_STANDARD, -1) == 0 || isDST) {
                     // tzid must be ready at this point
                     if (tzid.length() == 0) {
                         goto cleanupParse;
@@ -1437,20 +1443,20 @@ VTimeZone::parse(UErrorCode& status) {
                     // must not be there.
                     goto cleanupParse;
                 }
-            } else if (name.compare(ICAL_END) == 0) {
+            } else if (name.compare(ICAL_END, -1) == 0) {
                 break;
             }
             break;
         case TZI:
-            if (name.compare(ICAL_DTSTART) == 0) {
+            if (name.compare(ICAL_DTSTART, -1) == 0) {
                 dtstart = value;
-            } else if (name.compare(ICAL_TZNAME) == 0) {
+            } else if (name.compare(ICAL_TZNAME, -1) == 0) {
                 zonename = value;
-            } else if (name.compare(ICAL_TZOFFSETFROM) == 0) {
+            } else if (name.compare(ICAL_TZOFFSETFROM, -1) == 0) {
                 from = value;
-            } else if (name.compare(ICAL_TZOFFSETTO) == 0) {
+            } else if (name.compare(ICAL_TZOFFSETTO, -1) == 0) {
                 to = value;
-            } else if (name.compare(ICAL_RDATE) == 0) {
+            } else if (name.compare(ICAL_RDATE, -1) == 0) {
                 // RDATE mixed with RRULE is not supported
                 if (isRRULE) {
                     goto cleanupParse;
@@ -1474,7 +1480,7 @@ VTimeZone::parse(UErrorCode& status) {
                     }
                     dstart = dend + 1;
                 }
-            } else if (name.compare(ICAL_RRULE) == 0) {
+            } else if (name.compare(ICAL_RRULE, -1) == 0) {
                 // RRULE mixed with RDATE is not supported
                 if (!isRRULE && dates->size() != 0) {
                     goto cleanupParse;
@@ -1484,7 +1490,7 @@ VTimeZone::parse(UErrorCode& status) {
                 if (U_FAILURE(status)) {
                     goto cleanupParse;
                 }
-            } else if (name.compare(ICAL_END) == 0) {
+            } else if (name.compare(ICAL_END, -1) == 0) {
                 // Mandatory properties
                 if (dtstart.length() == 0 || from.length() == 0 || to.length() == 0) {
                     goto cleanupParse;
@@ -1719,13 +1725,13 @@ VTimeZone::write(VTZWriter& writer, UErrorCode& status) const {
     if (vtzlines != NULL) {
         for (int32_t i = 0; i < vtzlines->size(); i++) {
             UnicodeString *line = (UnicodeString*)vtzlines->elementAt(i);
-            if (line->startsWith(ICAL_TZURL)
+            if (line->startsWith(ICAL_TZURL, -1)
                 && line->charAt(u_strlen(ICAL_TZURL)) == COLON) {
                 writer.write(ICAL_TZURL);
                 writer.write(COLON);
                 writer.write(tzurl);
                 writer.write(ICAL_NEWLINE);
-            } else if (line->startsWith(ICAL_LASTMOD)
+            } else if (line->startsWith(ICAL_LASTMOD, -1)
                 && line->charAt(u_strlen(ICAL_LASTMOD)) == COLON) {
                 UnicodeString utcString;
                 writer.write(ICAL_LASTMOD);
@@ -1801,7 +1807,7 @@ VTimeZone::write(UDate start, VTZWriter& writer, UErrorCode& status) /*const*/ {
         icutzprop->append(olsonzid);
         icutzprop->append((UChar)0x005B/*'['*/);
         icutzprop->append(icutzver);
-        icutzprop->append(ICU_TZINFO_PARTIAL);
+        icutzprop->append(ICU_TZINFO_PARTIAL, -1);
         appendMillis(start, *icutzprop);
         icutzprop->append((UChar)0x005D/*']'*/);
         customProps.addElement(icutzprop, status);
@@ -1856,7 +1862,7 @@ VTimeZone::writeSimple(UDate time, VTZWriter& writer, UErrorCode& status) /*cons
             icutzprop->append(olsonzid);
             icutzprop->append((UChar)0x005B/*'['*/);
             icutzprop->append(icutzver);
-            icutzprop->append(ICU_TZINFO_SIMPLE);
+            icutzprop->append(ICU_TZINFO_SIMPLE, -1);
             appendMillis(time, *icutzprop);
             icutzprop->append((UChar)0x005D/*']'*/);
             customProps.addElement(icutzprop, status);
index 3aa2dbbebcc267be80f586d8fcfccae5e3ef12d3..1f60102d59327d4c61381c80f5da4884400be625 100644 (file)
@@ -1,7 +1,7 @@
 /*
 *******************************************************************************
-* Copyright (C) 2009-2010, International Business Machines Corporation and         *
-* others. All Rights Reserved.                                                *
+* Copyright (C) 2009-2011, International Business Machines Corporation and
+* others. All Rights Reserved.
 *******************************************************************************
 */
 
@@ -64,7 +64,7 @@ vzone_getTZURL(VZone* zone, UChar* & url, int32_t & urlLength) {
 U_CAPI void U_EXPORT2
 vzone_setTZURL(VZone* zone, UChar* url, int32_t urlLength) {
     UnicodeString s(urlLength==-1, url, urlLength);
-    return ((VTimeZone*)zone)->VTimeZone::setTZURL(url);
+    ((VTimeZone*)zone)->VTimeZone::setTZURL(s);
 }
 
 U_CAPI UBool U_EXPORT2
index 82c31169f6ce62b2d612c1629b01111b6a8f9325..7b584c3dbeaebd30b1ca0af8380578238c8949a3 100644 (file)
@@ -1,7 +1,7 @@
 /*
 *******************************************************************************
-* Copyright (C) 2009-2010, International Business Machines Corporation and         *
-* others. All Rights Reserved.                                                *
+* Copyright (C) 2009-2011, International Business Machines Corporation and
+* others. All Rights Reserved.
 *******************************************************************************
 */
 
@@ -68,7 +68,7 @@ zrule_isEquivalentTo(ZRule* rule1,  ZRule* rule2) {
 U_CAPI IZRule* U_EXPORT2
 izrule_open(const UChar* name, int32_t nameLength, int32_t rawOffset, int32_t dstSavings) {
     UnicodeString s(nameLength==-1, name, nameLength);
-    return (IZRule*) new InitialTimeZoneRule(name, rawOffset, dstSavings);
+    return (IZRule*) new InitialTimeZoneRule(s, rawOffset, dstSavings);
 }
 
 U_CAPI void U_EXPORT2