2 * Copyright (C) 2011 The Android Open Source Project
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
21 std::string getNextToken(const std::string & str, size_t pos, size_t * last, const std::string & delim)
23 if (str.size() == 0 || pos >= str.size()) return "";
25 pos = str.find_first_not_of(WHITESPACE, pos);
26 if (pos == std::string::npos) return "";
28 *last = str.find_first_of(delim, pos);
29 if (*last == std::string::npos) *last = str.size();
30 std::string retval = str.substr(pos, *last - pos);
31 retval = trim(retval);
36 std::string trim(const string & str)
39 string::size_type start = str.find_first_not_of(WHITESPACE, 0);
40 string::size_type end = str.find_last_not_of(WHITESPACE);
41 if (start == string::npos || end == string::npos) {
44 result = str.substr(start, end - start + 1);