Blender  V3.3
util.cc
Go to the documentation of this file.
1 // Copyright 2013 Blender Foundation. All rights reserved.
2 //
3 // This program is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU General Public License
5 // as published by the Free Software Foundation; either version 2
6 // of the License, or (at your option) any later version.
7 //
8 // This program is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 // GNU General Public License for more details.
12 //
13 // You should have received a copy of the GNU General Public License
14 // along with this program; if not, write to the Free Software Foundation,
15 // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 
17 #include "internal/base/util.h"
18 
19 namespace blender {
20 namespace opensubdiv {
21 
23  const string &str,
24  const string &separators,
25  bool skip_empty)
26 {
27  size_t token_start = 0, token_length = 0;
28  for (size_t i = 0; i < str.length(); ++i) {
29  const char ch = str[i];
30  if (separators.find(ch) == string::npos) {
31  // Append non-separator char to a token.
32  ++token_length;
33  }
34  else {
35  // Append current token to the list (if any).
36  if (token_length > 0 || !skip_empty) {
37  string token = str.substr(token_start, token_length);
38  tokens->push_back(token);
39  }
40  // Re-set token pointers.
41  token_start = i + 1;
42  token_length = 0;
43  }
44  }
45  // Append token which might be at the end of the string.
46  if ((token_length != 0) ||
47  (!skip_empty && token_start > 0 && separators.find(str[token_start - 1]) != string::npos)) {
48  string token = str.substr(token_start, token_length);
49  tokens->push_back(token);
50  }
51 }
52 
53 } // namespace opensubdiv
54 } // namespace blender
#define str(s)
void stringSplit(vector< string > *tokens, const string &str, const string &separators, bool skip_empty)
Definition: util.cc:22