]> granicus.if.org Git - icu/commitdiff
ICU-11276 Adding UChar* method in CharString.
authorShane Carr <shane@unicode.org>
Fri, 14 Sep 2018 07:51:36 +0000 (00:51 -0700)
committerShane Carr <shane@unicode.org>
Thu, 27 Sep 2018 21:27:40 +0000 (14:27 -0700)
icu4c/source/common/charstr.cpp
icu4c/source/common/charstr.h
icu4c/source/common/cmemory.h
icu4c/source/common/uinvchar.h

index 0b785e9c01076594585211089110d93ae6ab1254..852cc539457760546b4dfaf122edff0187e1cc88 100644 (file)
@@ -126,15 +126,21 @@ char *CharString::getAppendBuffer(int32_t minCapacity,
 }
 
 CharString &CharString::appendInvariantChars(const UnicodeString &s, UErrorCode &errorCode) {
+    return appendInvariantChars(s.getBuffer(), s.length(), errorCode);
+}
+
+CharString &CharString::appendInvariantChars(const UChar* uchars, int32_t ucharsLen, UErrorCode &errorCode) {
     if(U_FAILURE(errorCode)) {
         return *this;
     }
-    if (!uprv_isInvariantUnicodeString(s)) {
+    if (!uprv_isInvariantUString(uchars, ucharsLen)) {
         errorCode = U_INVARIANT_CONVERSION_ERROR;
         return *this;
     }
-    if(ensureCapacity(len+s.length()+1, 0, errorCode)) {
-        len+=s.extract(0, 0x7fffffff, buffer.getAlias()+len, buffer.getCapacity()-len, US_INV);
+    if(ensureCapacity(len+ucharsLen+1, 0, errorCode)) {
+        u_UCharsToChars(uchars, buffer.getAlias()+len, ucharsLen);
+        len += ucharsLen;
+        buffer[len] = 0;
     }
     return *this;
 }
index 86f69c383a0b37a9933185e6c93b14d690314110..1a97e01988f991b869773488a5f9c5cd0734b880 100644 (file)
@@ -123,6 +123,7 @@ public:
                           UErrorCode &errorCode);
 
     CharString &appendInvariantChars(const UnicodeString &s, UErrorCode &errorCode);
+    CharString &appendInvariantChars(const UChar* uchars, int32_t ucharsLen, UErrorCode& errorCode);
 
     /**
      * Appends a filename/path part, e.g., a directory name.
index e3532c759e1e982425ae2bfdc7d2f9de1e8724d2..8f3b610de466969cadf4824fd121e09ecbd6a113 100644 (file)
@@ -279,6 +279,10 @@ inline T *LocalMemory<T>::allocateInsteadAndCopy(int32_t newCapacity, int32_t le
  *
  * Unlike LocalMemory and LocalArray, this class never adopts
  * (takes ownership of) another array.
+ *
+ * WARNING: MaybeStackArray only works with primitive (plain-old data) types.
+ * It does NOT know how to call a destructor! If you work with classes with
+ * destructors, consider LocalArray in localpointer.h.
  */
 template<typename T, int32_t stackCapacity>
 class MaybeStackArray {
index c4f9f88b9ad32ffa6e89ff220aeb58bf9ceaa7f9..56dddfa8fde9bbb84e2bd9bbb94b7304b72dbbc9 100644 (file)
@@ -53,22 +53,6 @@ uprv_isInvariantString(const char *s, int32_t length);
 U_INTERNAL UBool U_EXPORT2
 uprv_isInvariantUString(const UChar *s, int32_t length);
 
-#ifdef __cplusplus
-
-/**
- * Check if a UnicodeString only contains invariant characters.
- * See utypes.h for details.
- *
- * @param s Input string.
- * @return TRUE if s contains only invariant characters.
- */
-U_INTERNAL inline UBool U_EXPORT2
-uprv_isInvariantUnicodeString(const icu::UnicodeString &s) {
-    return uprv_isInvariantUString(icu::toUCharPtr(s.getBuffer()), s.length());
-}
-
-#endif  /* __cplusplus */
-
 /**
  * \def U_UPPER_ORDINAL
  * Get the ordinal number of an uppercase invariant character