Andreas Huber | e46b7be | 2009-07-14 16:56:47 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2009 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
Andreas Huber | 63d524f | 2009-10-19 10:15:44 -0700 | [diff] [blame] | 17 | #include "include/stagefright_string.h" |
Andreas Huber | e46b7be | 2009-07-14 16:56:47 -0700 | [diff] [blame] | 18 | |
| 19 | namespace android { |
| 20 | |
| 21 | // static |
| 22 | string::size_type string::npos = (string::size_type)-1; |
| 23 | |
| 24 | string::string() { |
| 25 | } |
| 26 | |
| 27 | string::string(const char *s, size_t length) |
| 28 | : mString(s, length) { |
| 29 | } |
| 30 | |
| 31 | string::string(const string &from, size_type start, size_type length) |
| 32 | : mString(from.c_str() + start, length) { |
| 33 | } |
| 34 | |
| 35 | string::string(const char *s) |
| 36 | : mString(s) { |
| 37 | } |
| 38 | |
| 39 | const char *string::c_str() const { |
| 40 | return mString.string(); |
| 41 | } |
| 42 | |
| 43 | string::size_type string::size() const { |
| 44 | return mString.length(); |
| 45 | } |
| 46 | |
| 47 | void string::clear() { |
| 48 | mString = String8(); |
| 49 | } |
| 50 | |
| 51 | string::size_type string::find(char c) const { |
| 52 | char s[2]; |
| 53 | s[0] = c; |
| 54 | s[1] = '\0'; |
| 55 | |
| 56 | ssize_t index = mString.find(s); |
| 57 | |
| 58 | return index < 0 ? npos : (size_type)index; |
| 59 | } |
| 60 | |
| 61 | bool string::operator<(const string &other) const { |
| 62 | return mString < other.mString; |
| 63 | } |
| 64 | |
| 65 | bool string::operator==(const string &other) const { |
| 66 | return mString == other.mString; |
| 67 | } |
| 68 | |
| 69 | string &string::operator+=(char c) { |
| 70 | mString.append(&c, 1); |
| 71 | |
| 72 | return *this; |
| 73 | } |
| 74 | |
| 75 | void string::erase(size_t from, size_t length) { |
| 76 | String8 s(mString.string(), from); |
| 77 | s.append(mString.string() + from + length); |
| 78 | |
| 79 | mString = s; |
| 80 | } |
| 81 | |
| 82 | } // namespace android |
| 83 | |