AString.h revision 72961230a5890071bcca436eb5630172ce84ec41
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
2172961230a5890071bcca436eb5630172ce84ec41Andreas Huber#include <sys/types.h>
2272961230a5890071bcca436eb5630172ce84ec41Andreas Huber
2372961230a5890071bcca436eb5630172ce84ec41Andreas Hubernamespace android {
2472961230a5890071bcca436eb5630172ce84ec41Andreas Huber
2572961230a5890071bcca436eb5630172ce84ec41Andreas Huberstruct AString {
2672961230a5890071bcca436eb5630172ce84ec41Andreas Huber    AString();
2772961230a5890071bcca436eb5630172ce84ec41Andreas Huber    AString(const char *s);
2872961230a5890071bcca436eb5630172ce84ec41Andreas Huber    AString(const char *s, size_t size);
2972961230a5890071bcca436eb5630172ce84ec41Andreas Huber    AString(const AString &from);
3072961230a5890071bcca436eb5630172ce84ec41Andreas Huber    AString(const AString &from, size_t offset, size_t n);
3172961230a5890071bcca436eb5630172ce84ec41Andreas Huber    ~AString();
3272961230a5890071bcca436eb5630172ce84ec41Andreas Huber
3372961230a5890071bcca436eb5630172ce84ec41Andreas Huber    AString &operator=(const AString &from);
3472961230a5890071bcca436eb5630172ce84ec41Andreas Huber    void setTo(const char *s);
3572961230a5890071bcca436eb5630172ce84ec41Andreas Huber    void setTo(const char *s, size_t size);
3672961230a5890071bcca436eb5630172ce84ec41Andreas Huber    void setTo(const AString &from, size_t offset, size_t n);
3772961230a5890071bcca436eb5630172ce84ec41Andreas Huber
3872961230a5890071bcca436eb5630172ce84ec41Andreas Huber    size_t size() const;
3972961230a5890071bcca436eb5630172ce84ec41Andreas Huber    const char *c_str() const;
4072961230a5890071bcca436eb5630172ce84ec41Andreas Huber
4172961230a5890071bcca436eb5630172ce84ec41Andreas Huber    bool empty() const;
4272961230a5890071bcca436eb5630172ce84ec41Andreas Huber
4372961230a5890071bcca436eb5630172ce84ec41Andreas Huber    void clear();
4472961230a5890071bcca436eb5630172ce84ec41Andreas Huber    void trim();
4572961230a5890071bcca436eb5630172ce84ec41Andreas Huber    void erase(size_t start, size_t n);
4672961230a5890071bcca436eb5630172ce84ec41Andreas Huber
4772961230a5890071bcca436eb5630172ce84ec41Andreas Huber    void append(char c) { append(&c, 1); }
4872961230a5890071bcca436eb5630172ce84ec41Andreas Huber    void append(const char *s);
4972961230a5890071bcca436eb5630172ce84ec41Andreas Huber    void append(const char *s, size_t size);
5072961230a5890071bcca436eb5630172ce84ec41Andreas Huber    void append(const AString &from);
5172961230a5890071bcca436eb5630172ce84ec41Andreas Huber    void append(const AString &from, size_t offset, size_t n);
5272961230a5890071bcca436eb5630172ce84ec41Andreas Huber    void append(int x);
5372961230a5890071bcca436eb5630172ce84ec41Andreas Huber    void append(unsigned x);
5472961230a5890071bcca436eb5630172ce84ec41Andreas Huber    void append(long x);
5572961230a5890071bcca436eb5630172ce84ec41Andreas Huber    void append(unsigned long x);
5672961230a5890071bcca436eb5630172ce84ec41Andreas Huber    void append(long long x);
5772961230a5890071bcca436eb5630172ce84ec41Andreas Huber    void append(unsigned long long x);
5872961230a5890071bcca436eb5630172ce84ec41Andreas Huber    void append(float x);
5972961230a5890071bcca436eb5630172ce84ec41Andreas Huber    void append(double x);
6072961230a5890071bcca436eb5630172ce84ec41Andreas Huber    void append(void *x);
6172961230a5890071bcca436eb5630172ce84ec41Andreas Huber
6272961230a5890071bcca436eb5630172ce84ec41Andreas Huber    void insert(const AString &from, size_t insertionPos);
6372961230a5890071bcca436eb5630172ce84ec41Andreas Huber    void insert(const char *from, size_t size, size_t insertionPos);
6472961230a5890071bcca436eb5630172ce84ec41Andreas Huber
6572961230a5890071bcca436eb5630172ce84ec41Andreas Huber    ssize_t find(const char *substring, size_t start = 0) const;
6672961230a5890071bcca436eb5630172ce84ec41Andreas Huber
6772961230a5890071bcca436eb5630172ce84ec41Andreas Huber    size_t hash() const;
6872961230a5890071bcca436eb5630172ce84ec41Andreas Huber
6972961230a5890071bcca436eb5630172ce84ec41Andreas Huber    bool operator==(const AString &other) const;
7072961230a5890071bcca436eb5630172ce84ec41Andreas Huber    bool operator<(const AString &other) const;
7172961230a5890071bcca436eb5630172ce84ec41Andreas Huber    bool operator>(const AString &other) const;
7272961230a5890071bcca436eb5630172ce84ec41Andreas Huber
7372961230a5890071bcca436eb5630172ce84ec41Andreas Huber    int compare(const AString &other) const;
7472961230a5890071bcca436eb5630172ce84ec41Andreas Huber
7572961230a5890071bcca436eb5630172ce84ec41Andreas Huber    bool startsWith(const char *prefix) const;
7672961230a5890071bcca436eb5630172ce84ec41Andreas Huber
7772961230a5890071bcca436eb5630172ce84ec41Andreas Huber    void tolower();
7872961230a5890071bcca436eb5630172ce84ec41Andreas Huber
7972961230a5890071bcca436eb5630172ce84ec41Andreas Huberprivate:
8072961230a5890071bcca436eb5630172ce84ec41Andreas Huber    static const char *kEmptyString;
8172961230a5890071bcca436eb5630172ce84ec41Andreas Huber
8272961230a5890071bcca436eb5630172ce84ec41Andreas Huber    char *mData;
8372961230a5890071bcca436eb5630172ce84ec41Andreas Huber    size_t mSize;
8472961230a5890071bcca436eb5630172ce84ec41Andreas Huber    size_t mAllocSize;
8572961230a5890071bcca436eb5630172ce84ec41Andreas Huber
8672961230a5890071bcca436eb5630172ce84ec41Andreas Huber    void makeMutable();
8772961230a5890071bcca436eb5630172ce84ec41Andreas Huber};
8872961230a5890071bcca436eb5630172ce84ec41Andreas Huber
8972961230a5890071bcca436eb5630172ce84ec41Andreas HuberAString StringPrintf(const char *format, ...);
9072961230a5890071bcca436eb5630172ce84ec41Andreas Huber
9172961230a5890071bcca436eb5630172ce84ec41Andreas Huber}  // namespace android
9272961230a5890071bcca436eb5630172ce84ec41Andreas Huber
9372961230a5890071bcca436eb5630172ce84ec41Andreas Huber#endif  // A_STRING_H_
9472961230a5890071bcca436eb5630172ce84ec41Andreas Huber
95