Dan Albert | 00716d7 | 2015-03-13 22:57:40 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2015 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 | #ifndef BASE_STRINGS_H |
| 18 | #define BASE_STRINGS_H |
| 19 | |
| 20 | #include <string> |
| 21 | #include <vector> |
| 22 | |
| 23 | namespace android { |
| 24 | namespace base { |
| 25 | |
Dan Albert | 0d716d0 | 2015-03-19 13:24:26 -0700 | [diff] [blame] | 26 | // Splits a string into a vector of strings. |
| 27 | // |
Elliott Hughes | 658bd7b | 2015-04-17 17:08:16 -0700 | [diff] [blame^] | 28 | // The string is split at each occurrence of a character in delimiters. |
Dan Albert | 0d716d0 | 2015-03-19 13:24:26 -0700 | [diff] [blame] | 29 | // |
| 30 | // Empty splits will be omitted. I.e. Split("a,,b", ",") -> {"a", "b"} |
| 31 | // |
| 32 | // The empty string is not a valid delimiter list. |
| 33 | std::vector<std::string> Split(const std::string& s, |
| 34 | const std::string& delimiters); |
Dan Albert | 00716d7 | 2015-03-13 22:57:40 -0700 | [diff] [blame] | 35 | |
| 36 | // Trims whitespace off both ends of the given string. |
| 37 | std::string Trim(const std::string& s); |
| 38 | |
| 39 | // Joins a vector of strings into a single string, using the given separator. |
| 40 | template <typename StringT> |
| 41 | std::string Join(const std::vector<StringT>& strings, char separator); |
| 42 | |
| 43 | // Tests whether 's' starts with 'prefix'. |
| 44 | bool StartsWith(const std::string& s, const char* prefix); |
| 45 | |
| 46 | // Tests whether 's' ends with 'suffix'. |
| 47 | bool EndsWith(const std::string& s, const char* suffix); |
| 48 | |
| 49 | } // namespace base |
| 50 | } // namespace android |
| 51 | |
| 52 | #endif // BASE_STRINGS_H |