Debian Codegraph @

packages/seacas/libraries/aprepro_lib/apr_tokenize.cc

raw
1 // Copyright(C) 1999-2020 National Technology & Engineering Solutions
2 // of Sandia, LLC (NTESS). Under the terms of Contract DE-NA0003525 with
3 // NTESS, the U.S. Government retains certain rights in this software.
4 //
5 // See packages/seacas/LICENSE for details
6
7 #include "apr_tokenize.h"
8 #include <algorithm>
9
10 std::vector<std::string> SEAMS::tokenize(const std::string &str, const std::string &separators)
11 {
12 std::vector<std::string> tokens;
13 auto first = std::begin(str);
14 while (first != std::end(str)) {
15 const auto second =
16 std::find_first_of(first, std::end(str), std::begin(separators), std::end(separators));
17 if (first != second) {
18 tokens.emplace_back(first, second);
19 }
20 if (second == std::end(str)) {
21 break;
22 }
23 first = std::next(second);
24 }
25 return tokens;
26 }
27
28 #if 0
29 #include <iostream>
30 typedef std::vector<std::string> TokenList;
31
32 int main()
33 {
34 char s[128];
35 while(!std::cin.eof()) {
36 std::cout << "Enter a string: ";
37 std::cin.getline(s,128);
38 std::string input_line(s);
39 if (input_line != "quit") {
40 std::vector<std::string> tokens = tokenize(input_line, ": \t\r\v\n");
41 std::cout << "There were " << tokens.size() << " tokens in the line\n";
42 TokenList::const_iterator I = tokens.begin();
43 while (I != tokens.end()) {
44 std::cout << "'" << *I++ << "'\t";
45 }
46 std::cout << '\n';
47 } else {
48 exit(0);
49 }
50 }
51 }
52 #endif