MCPcopy Create free account
hub / github.com/davideberly/GeometricTools / GetTokens

Function GetTokens

GTE/Mathematics/StringUtility.h:58–94  ·  view source on GitHub ↗

In the default locale for C++ strings, the whitespace characters are space (0x20, ' '), form feed (0x0C, '\f'), line feed (0x0A, '\n'), carriage return (0x0D, 'r'), horizontal tab (0x09, 't') and vertical tab (0x0B, '\v'). See https://en.cppreference.com/w/cpp/string/byte/isspace for a table of ASCII values and related is* and isw* functions (with 'int32_t ch' input) that return 0 or !0.

Source from the content-addressed store, hash-verified

56 // for a table of ASCII values and related is* and isw* functions (with
57 // 'int32_t ch' input) that return 0 or !0.
58 inline void GetTokens(std::string const& input, std::string const& whiteSpace,
59 std::vector<std::string>& tokens)
60 {
61 std::string tokenString(input);
62 tokens.clear();
63 while (tokenString.length() > 0)
64 {
65 // Find the beginning of a token.
66 auto begin = tokenString.find_first_not_of(whiteSpace);
67 if (begin == std::string::npos)
68 {
69 // All tokens have been found.
70 break;
71 }
72
73 // Strip off the white space.
74 if (begin > 0)
75 {
76 tokenString = tokenString.substr(begin);
77 }
78
79 // Find the end of the token.
80 auto end = tokenString.find_first_of(whiteSpace);
81 if (end != std::string::npos)
82 {
83 std::string token = tokenString.substr(0, end);
84 tokens.push_back(token);
85 tokenString = tokenString.substr(end);
86 }
87 else
88 {
89 // This is the last token.
90 tokens.push_back(tokenString);
91 break;
92 }
93 }
94 }
95
96 // For basic text extraction, choose 'whiteSpace' to be ASCII values
97 // 0x00-0x20,0x7F-0xFF in GetTokens(...).

Callers 2

GetTextTokensFunction · 0.85
GetAdvancedTextTokensFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected