Blender V4.3
intern/opensubdiv/internal/base/util.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2013 Blender Foundation
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
6
7namespace blender::opensubdiv {
8
9void stringSplit(std::vector<std::string> *tokens,
10 const std::string &str,
11 const std::string &separators,
12 bool skip_empty)
13{
14 size_t token_start = 0, token_length = 0;
15 for (size_t i = 0; i < str.length(); ++i) {
16 const char ch = str[i];
17 if (separators.find(ch) == std::string::npos) {
18 // Append non-separator char to a token.
19 ++token_length;
20 }
21 else {
22 // Append current token to the list (if any).
23 if (token_length > 0 || !skip_empty) {
24 std::string token = str.substr(token_start, token_length);
25 tokens->push_back(token);
26 }
27 // Re-set token pointers.
28 token_start = i + 1;
29 token_length = 0;
30 }
31 }
32 // Append token which might be at the end of the std::string.
33 if ((token_length != 0) || (!skip_empty && token_start > 0 &&
34 separators.find(str[token_start - 1]) != std::string::npos))
35 {
36 std::string token = str.substr(token_start, token_length);
37 tokens->push_back(token);
38 }
39}
40
41} // namespace blender::opensubdiv
#define str(s)
void stringSplit(std::vector< std::string > *tokens, const std::string &str, const std::string &separators, bool skip_empty)