blob: 355934246bfbb523c8d3b1743a55033b45ff6c7b [file] [log] [blame]
Dan Albert00716d72015-03-13 22:57:40 -07001/*
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
23namespace android {
24namespace base {
25
Dan Albert0d716d02015-03-19 13:24:26 -070026// Splits a string into a vector of strings.
27//
Elliott Hughes658bd7b2015-04-17 17:08:16 -070028// The string is split at each occurrence of a character in delimiters.
Dan Albert0d716d02015-03-19 13:24:26 -070029//
30// Empty splits will be omitted. I.e. Split("a,,b", ",") -> {"a", "b"}
31//
32// The empty string is not a valid delimiter list.
33std::vector<std::string> Split(const std::string& s,
34 const std::string& delimiters);
Dan Albert00716d72015-03-13 22:57:40 -070035
36// Trims whitespace off both ends of the given string.
37std::string Trim(const std::string& s);
38
39// Joins a vector of strings into a single string, using the given separator.
40template <typename StringT>
41std::string Join(const std::vector<StringT>& strings, char separator);
42
43// Tests whether 's' starts with 'prefix'.
44bool StartsWith(const std::string& s, const char* prefix);
45
46// Tests whether 's' ends with 'suffix'.
47bool EndsWith(const std::string& s, const char* suffix);
48
49} // namespace base
50} // namespace android
51
52#endif // BASE_STRINGS_H