AString.h revision 8accee4f0e94f19866d260be6eecd6c219eb4982
172961230a5890071bcca436eb5630172ce84ec41Andreas Huber/* 272961230a5890071bcca436eb5630172ce84ec41Andreas Huber * Copyright (C) 2010 The Android Open Source Project 372961230a5890071bcca436eb5630172ce84ec41Andreas Huber * 472961230a5890071bcca436eb5630172ce84ec41Andreas Huber * Licensed under the Apache License, Version 2.0 (the "License"); 572961230a5890071bcca436eb5630172ce84ec41Andreas Huber * you may not use this file except in compliance with the License. 672961230a5890071bcca436eb5630172ce84ec41Andreas Huber * You may obtain a copy of the License at 772961230a5890071bcca436eb5630172ce84ec41Andreas Huber * 872961230a5890071bcca436eb5630172ce84ec41Andreas Huber * http://www.apache.org/licenses/LICENSE-2.0 972961230a5890071bcca436eb5630172ce84ec41Andreas Huber * 1072961230a5890071bcca436eb5630172ce84ec41Andreas Huber * Unless required by applicable law or agreed to in writing, software 1172961230a5890071bcca436eb5630172ce84ec41Andreas Huber * distributed under the License is distributed on an "AS IS" BASIS, 1272961230a5890071bcca436eb5630172ce84ec41Andreas Huber * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 1372961230a5890071bcca436eb5630172ce84ec41Andreas Huber * See the License for the specific language governing permissions and 1472961230a5890071bcca436eb5630172ce84ec41Andreas Huber * limitations under the License. 1572961230a5890071bcca436eb5630172ce84ec41Andreas Huber */ 1672961230a5890071bcca436eb5630172ce84ec41Andreas Huber 1772961230a5890071bcca436eb5630172ce84ec41Andreas Huber#ifndef A_STRING_H_ 1872961230a5890071bcca436eb5630172ce84ec41Andreas Huber 1972961230a5890071bcca436eb5630172ce84ec41Andreas Huber#define A_STRING_H_ 2072961230a5890071bcca436eb5630172ce84ec41Andreas Huber 218accee4f0e94f19866d260be6eecd6c219eb4982Lajos Molnar#include <utils/Errors.h> 2272961230a5890071bcca436eb5630172ce84ec41Andreas Huber#include <sys/types.h> 2372961230a5890071bcca436eb5630172ce84ec41Andreas Huber 2472961230a5890071bcca436eb5630172ce84ec41Andreas Hubernamespace android { 2572961230a5890071bcca436eb5630172ce84ec41Andreas Huber 26bcf08569453dcb42730cda3230d5d375a697005bLajos Molnarstruct String8; 278accee4f0e94f19866d260be6eecd6c219eb4982Lajos Molnarstruct Parcel; 28bcf08569453dcb42730cda3230d5d375a697005bLajos Molnar 2972961230a5890071bcca436eb5630172ce84ec41Andreas Huberstruct AString { 3072961230a5890071bcca436eb5630172ce84ec41Andreas Huber AString(); 3172961230a5890071bcca436eb5630172ce84ec41Andreas Huber AString(const char *s); 3272961230a5890071bcca436eb5630172ce84ec41Andreas Huber AString(const char *s, size_t size); 33bcf08569453dcb42730cda3230d5d375a697005bLajos Molnar AString(const String8 &from); 3472961230a5890071bcca436eb5630172ce84ec41Andreas Huber AString(const AString &from); 3572961230a5890071bcca436eb5630172ce84ec41Andreas Huber AString(const AString &from, size_t offset, size_t n); 3672961230a5890071bcca436eb5630172ce84ec41Andreas Huber ~AString(); 3772961230a5890071bcca436eb5630172ce84ec41Andreas Huber 3872961230a5890071bcca436eb5630172ce84ec41Andreas Huber AString &operator=(const AString &from); 3972961230a5890071bcca436eb5630172ce84ec41Andreas Huber void setTo(const char *s); 4072961230a5890071bcca436eb5630172ce84ec41Andreas Huber void setTo(const char *s, size_t size); 4172961230a5890071bcca436eb5630172ce84ec41Andreas Huber void setTo(const AString &from, size_t offset, size_t n); 4272961230a5890071bcca436eb5630172ce84ec41Andreas Huber 4372961230a5890071bcca436eb5630172ce84ec41Andreas Huber size_t size() const; 4472961230a5890071bcca436eb5630172ce84ec41Andreas Huber const char *c_str() const; 4572961230a5890071bcca436eb5630172ce84ec41Andreas Huber 4672961230a5890071bcca436eb5630172ce84ec41Andreas Huber bool empty() const; 4772961230a5890071bcca436eb5630172ce84ec41Andreas Huber 4872961230a5890071bcca436eb5630172ce84ec41Andreas Huber void clear(); 4972961230a5890071bcca436eb5630172ce84ec41Andreas Huber void trim(); 5072961230a5890071bcca436eb5630172ce84ec41Andreas Huber void erase(size_t start, size_t n); 5172961230a5890071bcca436eb5630172ce84ec41Andreas Huber 5272961230a5890071bcca436eb5630172ce84ec41Andreas Huber void append(char c) { append(&c, 1); } 5372961230a5890071bcca436eb5630172ce84ec41Andreas Huber void append(const char *s); 5472961230a5890071bcca436eb5630172ce84ec41Andreas Huber void append(const char *s, size_t size); 5572961230a5890071bcca436eb5630172ce84ec41Andreas Huber void append(const AString &from); 5672961230a5890071bcca436eb5630172ce84ec41Andreas Huber void append(const AString &from, size_t offset, size_t n); 5772961230a5890071bcca436eb5630172ce84ec41Andreas Huber void append(int x); 5872961230a5890071bcca436eb5630172ce84ec41Andreas Huber void append(unsigned x); 5972961230a5890071bcca436eb5630172ce84ec41Andreas Huber void append(long x); 6072961230a5890071bcca436eb5630172ce84ec41Andreas Huber void append(unsigned long x); 6172961230a5890071bcca436eb5630172ce84ec41Andreas Huber void append(long long x); 6272961230a5890071bcca436eb5630172ce84ec41Andreas Huber void append(unsigned long long x); 6372961230a5890071bcca436eb5630172ce84ec41Andreas Huber void append(float x); 6472961230a5890071bcca436eb5630172ce84ec41Andreas Huber void append(double x); 6572961230a5890071bcca436eb5630172ce84ec41Andreas Huber void append(void *x); 6672961230a5890071bcca436eb5630172ce84ec41Andreas Huber 6772961230a5890071bcca436eb5630172ce84ec41Andreas Huber void insert(const AString &from, size_t insertionPos); 6872961230a5890071bcca436eb5630172ce84ec41Andreas Huber void insert(const char *from, size_t size, size_t insertionPos); 6972961230a5890071bcca436eb5630172ce84ec41Andreas Huber 7072961230a5890071bcca436eb5630172ce84ec41Andreas Huber ssize_t find(const char *substring, size_t start = 0) const; 7172961230a5890071bcca436eb5630172ce84ec41Andreas Huber 7272961230a5890071bcca436eb5630172ce84ec41Andreas Huber size_t hash() const; 7372961230a5890071bcca436eb5630172ce84ec41Andreas Huber 7472961230a5890071bcca436eb5630172ce84ec41Andreas Huber bool operator==(const AString &other) const; 75513d967dae82cd03e67bff17b927cf869d9bc43eLajos Molnar bool operator!=(const AString &other) const { 76513d967dae82cd03e67bff17b927cf869d9bc43eLajos Molnar return !operator==(other); 77513d967dae82cd03e67bff17b927cf869d9bc43eLajos Molnar } 7872961230a5890071bcca436eb5630172ce84ec41Andreas Huber bool operator<(const AString &other) const; 7972961230a5890071bcca436eb5630172ce84ec41Andreas Huber bool operator>(const AString &other) const; 8072961230a5890071bcca436eb5630172ce84ec41Andreas Huber 8172961230a5890071bcca436eb5630172ce84ec41Andreas Huber int compare(const AString &other) const; 828accee4f0e94f19866d260be6eecd6c219eb4982Lajos Molnar int compareIgnoreCase(const AString &other) const; 8372961230a5890071bcca436eb5630172ce84ec41Andreas Huber 848accee4f0e94f19866d260be6eecd6c219eb4982Lajos Molnar bool equalsIgnoreCase(const AString &other) const; 8572961230a5890071bcca436eb5630172ce84ec41Andreas Huber bool startsWith(const char *prefix) const; 86ed3e3e046840d5bf1ca84a8c0cc097425e89d6d6Andreas Huber bool endsWith(const char *suffix) const; 873c1da7224155516a08d94598eb64b64204bf10f8Lajos Molnar bool startsWithIgnoreCase(const char *prefix) const; 883c1da7224155516a08d94598eb64b64204bf10f8Lajos Molnar bool endsWithIgnoreCase(const char *suffix) const; 8972961230a5890071bcca436eb5630172ce84ec41Andreas Huber 9072961230a5890071bcca436eb5630172ce84ec41Andreas Huber void tolower(); 9172961230a5890071bcca436eb5630172ce84ec41Andreas Huber 928accee4f0e94f19866d260be6eecd6c219eb4982Lajos Molnar static AString FromParcel(const Parcel &parcel); 938accee4f0e94f19866d260be6eecd6c219eb4982Lajos Molnar status_t writeToParcel(Parcel *parcel) const; 948accee4f0e94f19866d260be6eecd6c219eb4982Lajos Molnar 9572961230a5890071bcca436eb5630172ce84ec41Andreas Huberprivate: 9672961230a5890071bcca436eb5630172ce84ec41Andreas Huber static const char *kEmptyString; 9772961230a5890071bcca436eb5630172ce84ec41Andreas Huber 9872961230a5890071bcca436eb5630172ce84ec41Andreas Huber char *mData; 9972961230a5890071bcca436eb5630172ce84ec41Andreas Huber size_t mSize; 10072961230a5890071bcca436eb5630172ce84ec41Andreas Huber size_t mAllocSize; 10172961230a5890071bcca436eb5630172ce84ec41Andreas Huber 10272961230a5890071bcca436eb5630172ce84ec41Andreas Huber void makeMutable(); 10372961230a5890071bcca436eb5630172ce84ec41Andreas Huber}; 10472961230a5890071bcca436eb5630172ce84ec41Andreas Huber 10572961230a5890071bcca436eb5630172ce84ec41Andreas HuberAString StringPrintf(const char *format, ...); 10672961230a5890071bcca436eb5630172ce84ec41Andreas Huber 10772961230a5890071bcca436eb5630172ce84ec41Andreas Huber} // namespace android 10872961230a5890071bcca436eb5630172ce84ec41Andreas Huber 10972961230a5890071bcca436eb5630172ce84ec41Andreas Huber#endif // A_STRING_H_ 11072961230a5890071bcca436eb5630172ce84ec41Andreas Huber 111