Lines Matching defs:string

22 #include <string>
36 // Short-hand for a vector of strings. A single string and a token is synonymous.
37 using TokenList = std::vector<std::string>;
111 // Create a token range by splitting a string. Each separator gets their own token.
114 static TokenRange Split(const std::string& string, std::initializer_list<char> separators) {
117 std::string tok;
118 for (auto&& c : string) {
128 new_token_list.push_back(std::string() + sep);
164 const std::string& GetToken(size_t offset) const {
185 const std::string& operator[](int index) const {
230 TokenRange RemoveToken(const std::string& token) {
231 return RemoveIf([&](const std::string& tok) { return tok == token; });
236 return RemoveIf([](const std::string& token) { return token.empty(); });
241 TokenRange Slice(size_t offset, size_t length = std::string::npos) const {
244 if (length != std::string::npos && offset + length > Size()) {
249 if (length == std::string::npos) {
258 // Try to match the string with tokens from this range.
264 // For example, if this == ["a:", "_", "b:] and "_" is the match string, then
267 // Since the string matching can fail (e.g. ["foo"] against "bar"), then this
269 std::unique_ptr<TokenRange> MatchSubstrings(const std::string& string,
270 const std::string& wildcard) const {
273 size_t wildcard_idx = std::string::npos;
280 if (wildcard_idx != std::string::npos) {
282 std::string wildcard_substr = string.substr(wildcard_idx, wildcard_length);
285 wildcard_idx = std::string::npos;
290 const std::string& tok = *it;
298 size_t next_token_idx = string.find(tok);
299 if (next_token_idx == std::string::npos) {
302 } else if (next_token_idx != string_idx && wildcard_idx == std::string::npos) {
308 new_token_list.push_back(string.substr(next_token_idx, tok.size()));
313 size_t remaining = string.size() - string_idx;
315 if (wildcard_idx == std::string::npos) {
316 // Some characters were still remaining in the string,
337 size_t MaybeMatches(const TokenRange& token_list, const std::string& wildcard) const {
347 const std::string& name = *name_it;
350 if (wildcard_idx == std::string::npos) { // No wildcard present
356 std::string name_prefix = name.substr(0, wildcard_idx);
375 std::string Join(char separator) const {
382 static bool StartsWith(const std::string& larger, const std::string& smaller) {
419 const std::shared_ptr<std::vector<std::string>> token_list_;