]> git.saurik.com Git - apple/icu.git/blobdiff - icuSources/common/charstr.h
ICU-64243.0.1.tar.gz
[apple/icu.git] / icuSources / common / charstr.h
index 2eb87a0791fbf2c533ba715326a8e7e74b2ef179..1a97e01988f991b869773488a5f9c5cd0734b880 100644 (file)
@@ -1,6 +1,8 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
 /*
 **********************************************************************
-*   Copyright (c) 2001-2010, International Business Machines
+*   Copyright (c) 2001-2015, International Business Machines
 *   Corporation and others.  All Rights Reserved.
 **********************************************************************
 *   Date        Name        Description
@@ -21,7 +23,7 @@ U_NAMESPACE_BEGIN
 
 // Windows needs us to DLL-export the MaybeStackArray template specialization,
 // but MacOS X cannot handle it. Same as in digitlst.h.
-#if !defined(U_DARWIN)
+#if !U_PLATFORM_IS_DARWIN_BASED
 template class U_COMMON_API MaybeStackArray<char, 40>;
 #endif
 
@@ -39,7 +41,7 @@ template class U_COMMON_API MaybeStackArray<char, 40>;
 class U_COMMON_API CharString : public UMemory {
 public:
     CharString() : len(0) { buffer[0]=0; }
-    CharString(const StringPiece &s, UErrorCode &errorCode) : len(0) {
+    CharString(StringPiece s, UErrorCode &errorCode) : len(0) {
         buffer[0]=0;
         append(s, errorCode);
     }
@@ -53,6 +55,18 @@ public:
     }
     ~CharString() {}
 
+    /**
+     * Move constructor; might leave src in an undefined state.
+     * This string will have the same contents and state that the source string had.
+     */
+    CharString(CharString &&src) U_NOEXCEPT;
+    /**
+     * Move assignment operator; might leave src in an undefined state.
+     * This string will have the same contents and state that the source string had.
+     * The behavior is undefined if *this and src are the same object.
+     */
+    CharString &operator=(CharString &&src) U_NOEXCEPT;
+
     /**
      * Replaces this string's contents with the other string's contents.
      * CharString does not support the standard copy constructor nor
@@ -61,19 +75,22 @@ public:
      */
     CharString &copyFrom(const CharString &other, UErrorCode &errorCode);
 
-    UBool isEmpty() { return len==0; }
+    UBool isEmpty() const { return len==0; }
     int32_t length() const { return len; }
-    char operator[] (int32_t index) const { return buffer[index]; }
+    char operator[](int32_t index) const { return buffer[index]; }
     StringPiece toStringPiece() const { return StringPiece(buffer.getAlias(), len); }
 
     const char *data() const { return buffer.getAlias(); }
     char *data() { return buffer.getAlias(); }
 
+    /** @return last index of c, or -1 if c is not in this string */
+    int32_t lastIndexOf(char c) const;
+
     CharString &clear() { len=0; buffer[0]=0; return *this; }
     CharString &truncate(int32_t newLength);
 
     CharString &append(char c, UErrorCode &errorCode);
-    CharString &append(const StringPiece &s, UErrorCode &errorCode) {
+    CharString &append(StringPiece s, UErrorCode &errorCode) {
         return append(s.data(), s.length(), errorCode);
     }
     CharString &append(const CharString &s, UErrorCode &errorCode) {
@@ -106,6 +123,20 @@ 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.
+     * First appends a U_FILE_SEP_CHAR if necessary.
+     * Does nothing if s is empty.
+     */
+    CharString &appendPathPart(StringPiece s, UErrorCode &errorCode);
+
+    /**
+     * Appends a U_FILE_SEP_CHAR if this string is not empty
+     * and does not already end with a U_FILE_SEP_CHAR or U_FILE_ALT_SEP_CHAR.
+     */
+    CharString &ensureEndsWithFileSeparator(UErrorCode &errorCode);
 
 private:
     MaybeStackArray<char, 40> buffer;