+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
/*
**********************************************************************
-* Copyright (c) 2001-2011, International Business Machines
+* Copyright (c) 2001-2015, International Business Machines
* Corporation and others. All Rights Reserved.
**********************************************************************
* Date Name Description
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);
}
}
~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
*/
CharString ©From(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(); }
+ /**
+ * Allocates length()+1 chars and copies the NUL-terminated data().
+ * The caller must uprv_free() the result.
+ */
+ char *cloneData(UErrorCode &errorCode) const;
+
+ bool operator==(StringPiece other) const {
+ return len == other.length() && (len == 0 || uprv_memcmp(data(), other.data(), len) == 0);
+ }
+ bool operator!=(StringPiece other) const {
+ return !operator==(other);
+ }
+
+ /** @return last index of c, or -1 if c is not in this string */
+ int32_t lastIndexOf(char c) const;
+
+ bool contains(StringPiece s) 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) {
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(const StringPiece &s, UErrorCode &errorCode);
+ 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;