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 17 #include "include/stagefright_string.h" 18 19 #include <media/stagefright/MediaDebug.h> 20 21 namespace android { 22 23 // static 24 string::size_type string::npos = (string::size_type)-1; 25 26 string::string() { 27 } 28 29 string::string(const char *s, size_t length) 30 : mString(s, length) { 31 } 32 33 string::string(const string &from, size_type start, size_type length) { 34 CHECK(start <= from.size()); 35 if (length == npos) { 36 length = from.size() - start; 37 } else { 38 CHECK(start + length <= from.size()); 39 } 40 41 mString.setTo(from.c_str() + start, length); 42 } 43 44 string::string(const char *s) 45 : mString(s) { 46 } 47 48 const char *string::c_str() const { 49 return mString.string(); 50 } 51 52 string::size_type string::size() const { 53 return mString.length(); 54 } 55 56 void string::clear() { 57 mString = String8(); 58 } 59 60 string::size_type string::find(char c) const { 61 char s[2]; 62 s[0] = c; 63 s[1] = '\0'; 64 65 ssize_t index = mString.find(s); 66 67 return index < 0 ? npos : (size_type)index; 68 } 69 70 bool string::operator<(const string &other) const { 71 return mString < other.mString; 72 } 73 74 bool string::operator==(const string &other) const { 75 return mString == other.mString; 76 } 77 78 string &string::operator+=(char c) { 79 mString.append(&c, 1); 80 81 return *this; 82 } 83 84 void string::erase(size_t from, size_t length) { 85 String8 s(mString.string(), from); 86 s.append(mString.string() + from + length); 87 88 mString = s; 89 } 90 91 } // namespace android 92 93