michael@0: /* michael@0: * Copyright (C) 2005 The Android Open Source Project michael@0: * michael@0: * Licensed under the Apache License, Version 2.0 (the "License"); michael@0: * you may not use this file except in compliance with the License. michael@0: * You may obtain a copy of the License at michael@0: * michael@0: * http://www.apache.org/licenses/LICENSE-2.0 michael@0: * michael@0: * Unless required by applicable law or agreed to in writing, software michael@0: * distributed under the License is distributed on an "AS IS" BASIS, michael@0: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. michael@0: * See the License for the specific language governing permissions and michael@0: * limitations under the License. michael@0: */ michael@0: michael@0: #ifndef ANDROID_STRING16_H michael@0: #define ANDROID_STRING16_H michael@0: michael@0: #include michael@0: #include michael@0: #include michael@0: michael@0: // --------------------------------------------------------------------------- michael@0: michael@0: extern "C" { michael@0: michael@0: } michael@0: michael@0: // --------------------------------------------------------------------------- michael@0: michael@0: namespace android { michael@0: michael@0: // --------------------------------------------------------------------------- michael@0: michael@0: class String8; michael@0: class TextOutput; michael@0: michael@0: //! This is a string holding UTF-16 characters. michael@0: class String16 michael@0: { michael@0: public: michael@0: String16(); michael@0: String16(const String16& o); michael@0: String16(const String16& o, michael@0: size_t len, michael@0: size_t begin=0); michael@0: explicit String16(const char16_t* o); michael@0: explicit String16(const char16_t* o, size_t len); michael@0: explicit String16(const String8& o); michael@0: explicit String16(const char* o); michael@0: explicit String16(const char* o, size_t len); michael@0: michael@0: ~String16(); michael@0: michael@0: inline const char16_t* string() const; michael@0: inline size_t size() const; michael@0: michael@0: inline const SharedBuffer* sharedBuffer() const; michael@0: michael@0: void setTo(const String16& other); michael@0: status_t setTo(const char16_t* other); michael@0: status_t setTo(const char16_t* other, size_t len); michael@0: status_t setTo(const String16& other, michael@0: size_t len, michael@0: size_t begin=0); michael@0: michael@0: status_t append(const String16& other); michael@0: status_t append(const char16_t* other, size_t len); michael@0: michael@0: inline String16& operator=(const String16& other); michael@0: michael@0: inline String16& operator+=(const String16& other); michael@0: inline String16 operator+(const String16& other) const; michael@0: michael@0: status_t insert(size_t pos, const char16_t* chrs); michael@0: status_t insert(size_t pos, michael@0: const char16_t* chrs, size_t len); michael@0: michael@0: ssize_t findFirst(char16_t c) const; michael@0: ssize_t findLast(char16_t c) const; michael@0: michael@0: bool startsWith(const String16& prefix) const; michael@0: bool startsWith(const char16_t* prefix) const; michael@0: michael@0: status_t makeLower(); michael@0: michael@0: status_t replaceAll(char16_t replaceThis, michael@0: char16_t withThis); michael@0: michael@0: status_t remove(size_t len, size_t begin=0); michael@0: michael@0: inline int compare(const String16& other) const; michael@0: michael@0: inline bool operator<(const String16& other) const; michael@0: inline bool operator<=(const String16& other) const; michael@0: inline bool operator==(const String16& other) const; michael@0: inline bool operator!=(const String16& other) const; michael@0: inline bool operator>=(const String16& other) const; michael@0: inline bool operator>(const String16& other) const; michael@0: michael@0: inline bool operator<(const char16_t* other) const; michael@0: inline bool operator<=(const char16_t* other) const; michael@0: inline bool operator==(const char16_t* other) const; michael@0: inline bool operator!=(const char16_t* other) const; michael@0: inline bool operator>=(const char16_t* other) const; michael@0: inline bool operator>(const char16_t* other) const; michael@0: michael@0: inline operator const char16_t*() const; michael@0: michael@0: private: michael@0: const char16_t* mString; michael@0: }; michael@0: michael@0: TextOutput& operator<<(TextOutput& to, const String16& val); michael@0: michael@0: // --------------------------------------------------------------------------- michael@0: // No user servicable parts below. michael@0: michael@0: inline int compare_type(const String16& lhs, const String16& rhs) michael@0: { michael@0: return lhs.compare(rhs); michael@0: } michael@0: michael@0: inline int strictly_order_type(const String16& lhs, const String16& rhs) michael@0: { michael@0: return compare_type(lhs, rhs) < 0; michael@0: } michael@0: michael@0: inline const char16_t* String16::string() const michael@0: { michael@0: return mString; michael@0: } michael@0: michael@0: inline size_t String16::size() const michael@0: { michael@0: return SharedBuffer::sizeFromData(mString)/sizeof(char16_t)-1; michael@0: } michael@0: michael@0: inline const SharedBuffer* String16::sharedBuffer() const michael@0: { michael@0: return SharedBuffer::bufferFromData(mString); michael@0: } michael@0: michael@0: inline String16& String16::operator=(const String16& other) michael@0: { michael@0: setTo(other); michael@0: return *this; michael@0: } michael@0: michael@0: inline String16& String16::operator+=(const String16& other) michael@0: { michael@0: append(other); michael@0: return *this; michael@0: } michael@0: michael@0: inline String16 String16::operator+(const String16& other) const michael@0: { michael@0: String16 tmp(*this); michael@0: tmp += other; michael@0: return tmp; michael@0: } michael@0: michael@0: inline int String16::compare(const String16& other) const michael@0: { michael@0: return strzcmp16(mString, size(), other.mString, other.size()); michael@0: } michael@0: michael@0: inline bool String16::operator<(const String16& other) const michael@0: { michael@0: return strzcmp16(mString, size(), other.mString, other.size()) < 0; michael@0: } michael@0: michael@0: inline bool String16::operator<=(const String16& other) const michael@0: { michael@0: return strzcmp16(mString, size(), other.mString, other.size()) <= 0; michael@0: } michael@0: michael@0: inline bool String16::operator==(const String16& other) const michael@0: { michael@0: return strzcmp16(mString, size(), other.mString, other.size()) == 0; michael@0: } michael@0: michael@0: inline bool String16::operator!=(const String16& other) const michael@0: { michael@0: return strzcmp16(mString, size(), other.mString, other.size()) != 0; michael@0: } michael@0: michael@0: inline bool String16::operator>=(const String16& other) const michael@0: { michael@0: return strzcmp16(mString, size(), other.mString, other.size()) >= 0; michael@0: } michael@0: michael@0: inline bool String16::operator>(const String16& other) const michael@0: { michael@0: return strzcmp16(mString, size(), other.mString, other.size()) > 0; michael@0: } michael@0: michael@0: inline bool String16::operator<(const char16_t* other) const michael@0: { michael@0: return strcmp16(mString, other) < 0; michael@0: } michael@0: michael@0: inline bool String16::operator<=(const char16_t* other) const michael@0: { michael@0: return strcmp16(mString, other) <= 0; michael@0: } michael@0: michael@0: inline bool String16::operator==(const char16_t* other) const michael@0: { michael@0: return strcmp16(mString, other) == 0; michael@0: } michael@0: michael@0: inline bool String16::operator!=(const char16_t* other) const michael@0: { michael@0: return strcmp16(mString, other) != 0; michael@0: } michael@0: michael@0: inline bool String16::operator>=(const char16_t* other) const michael@0: { michael@0: return strcmp16(mString, other) >= 0; michael@0: } michael@0: michael@0: inline bool String16::operator>(const char16_t* other) const michael@0: { michael@0: return strcmp16(mString, other) > 0; michael@0: } michael@0: michael@0: inline String16::operator const char16_t*() const michael@0: { michael@0: return mString; michael@0: } michael@0: michael@0: }; // namespace android michael@0: michael@0: // --------------------------------------------------------------------------- michael@0: michael@0: #endif // ANDROID_STRING16_H