]> git.saurik.com Git - apple/icu.git/blobdiff - icuSources/common/charstr.cpp
ICU-57132.0.1.tar.gz
[apple/icu.git] / icuSources / common / charstr.cpp
index cdd58281b38a425c7d0a90c881cb92ac0395b7af..1b27c683de2f1809ef786043d11bbdb91c69a959 100644 (file)
@@ -1,6 +1,6 @@
 /*
 *******************************************************************************
 /*
 *******************************************************************************
-*   Copyright (C) 2010, International Business Machines
+*   Copyright (C) 2010-2015, International Business Machines
 *   Corporation and others.  All Rights Reserved.
 *******************************************************************************
 *   file name:  charstr.cpp
 *   Corporation and others.  All Rights Reserved.
 *******************************************************************************
 *   file name:  charstr.cpp
@@ -16,6 +16,7 @@
 #include "charstr.h"
 #include "cmemory.h"
 #include "cstring.h"
 #include "charstr.h"
 #include "cmemory.h"
 #include "cstring.h"
+#include "uinvchar.h"
 
 U_NAMESPACE_BEGIN
 
 
 U_NAMESPACE_BEGIN
 
@@ -27,6 +28,15 @@ CharString &CharString::copyFrom(const CharString &s, UErrorCode &errorCode) {
     return *this;
 }
 
     return *this;
 }
 
+int32_t CharString::lastIndexOf(char c) const {
+    for(int32_t i=len; i>0;) {
+        if(buffer[--i]==c) {
+            return i;
+        }
+    }
+    return -1;
+}
+
 CharString &CharString::truncate(int32_t newLength) {
     if(newLength<0) {
         newLength=0;
 CharString &CharString::truncate(int32_t newLength) {
     if(newLength<0) {
         newLength=0;
@@ -101,6 +111,13 @@ char *CharString::getAppendBuffer(int32_t minCapacity,
 }
 
 CharString &CharString::appendInvariantChars(const UnicodeString &s, UErrorCode &errorCode) {
 }
 
 CharString &CharString::appendInvariantChars(const UnicodeString &s, UErrorCode &errorCode) {
+    if(U_FAILURE(errorCode)) {
+        return *this;
+    }
+    if (!uprv_isInvariantUnicodeString(s)) {
+        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+s.length()+1, 0, errorCode)) {
         len+=s.extract(0, 0x7fffffff, buffer.getAlias()+len, buffer.getCapacity()-len, US_INV);
     }
@@ -127,4 +144,28 @@ UBool CharString::ensureCapacity(int32_t capacity,
     return TRUE;
 }
 
     return TRUE;
 }
 
+CharString &CharString::appendPathPart(const StringPiece &s, UErrorCode &errorCode) {
+    if(U_FAILURE(errorCode)) {
+        return *this;
+    }
+    if(s.length()==0) {
+        return *this;
+    }
+    char c;
+    if(len>0 && (c=buffer[len-1])!=U_FILE_SEP_CHAR && c!=U_FILE_ALT_SEP_CHAR) {
+        append(U_FILE_SEP_CHAR, errorCode);
+    }
+    append(s, errorCode);
+    return *this;
+}
+
+CharString &CharString::ensureEndsWithFileSeparator(UErrorCode &errorCode) {
+    char c;
+    if(U_SUCCESS(errorCode) && len>0 &&
+            (c=buffer[len-1])!=U_FILE_SEP_CHAR && c!=U_FILE_ALT_SEP_CHAR) {
+        append(U_FILE_SEP_CHAR, errorCode);
+    }
+    return *this;
+}
+
 U_NAMESPACE_END
 U_NAMESPACE_END