summaryrefslogtreecommitdiffstats
path: root/media/libstagefright/string.cpp
blob: 8b2c36c2d9d62245852880c545a0dd2df42d8557 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
/*
 * Copyright (C) 2009 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include "include/stagefright_string.h"

#include <media/stagefright/MediaDebug.h>

namespace android {

// static
string::size_type string::npos = (string::size_type)-1;

string::string() {
}

string::string(const char *s, size_t length)
    : mString(s, length) {
}

string::string(const string &from, size_type start, size_type length) {
    CHECK(start <= from.size());
    if (length == npos) {
        length = from.size() - start;
    } else {
        CHECK(start + length <= from.size());
    }

    mString.setTo(from.c_str() + start, length);
}

string::string(const char *s)
    : mString(s) {
}

const char *string::c_str() const {
    return mString.string();
}

string::size_type string::size() const {
    return mString.length();
}

void string::clear() {
    mString = String8();
}

string::size_type string::find(char c) const {
    char s[2];
    s[0] = c;
    s[1] = '\0';

    ssize_t index = mString.find(s);

    return index < 0 ? npos : (size_type)index;
}

bool string::operator<(const string &other) const {
    return mString < other.mString;
}

bool string::operator==(const string &other) const {
    return mString == other.mString;
}

string &string::operator+=(char c) {
    mString.append(&c, 1);

    return *this;
}

void string::erase(size_t from, size_t length) {
    String8 s(mString.string(), from);
    s.append(mString.string() + from + length);
    
    mString = s;
}

}  // namespace android