1 // Copyright 2016 The Chromium OS Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #include "string_utils.h"
6 
7 #include <sstream>
8 
9 namespace quipper {
10 
11 void TrimWhitespace(string* str) {
12   const char kWhitespaceCharacters[] = " \t\n\r";
13   size_t end = str->find_last_not_of(kWhitespaceCharacters);
14   if (end != string::npos) {
15     size_t start = str->find_first_not_of(kWhitespaceCharacters);
16     *str = str->substr(start, end + 1 - start);
17   } else {
18     // The string contains only whitespace.
19     *str = "";
20   }
21 }
22 
23 void SplitString(const string& str, char delimiter,
24                  std::vector<string>* tokens) {
25   std::stringstream ss(str);
26   string token;
27   while (std::getline(ss, token, delimiter)) tokens->push_back(token);
28 }
29 
30 }  // namespace quipper
31