Remove unused src/base/strings/string_tokenizer.h Remove the unused CommandLine::PrependWrapper() method, which was the sole user of StringTokenizerT, and delete src/base/strings/string_tokenizer.h. Change-Id: I58255b83dca06b197d739b84169f55b3556e6081 Reviewed-on: https://gn-review.googlesource.com/c/gn/+/29880 Reviewed-by: Matt Stark <msta@google.com> Commit-Queue: Takuto Ikuta <tikuta@google.com>
diff --git a/src/base/command_line.cc b/src/base/command_line.cc index dacf1cc..c0e6ed6 100644 --- a/src/base/command_line.cc +++ b/src/base/command_line.cc
@@ -12,7 +12,6 @@ #include "base/files/file_path.h" #include "base/logging.h" #include "base/strings/string_split.h" -#include "base/strings/string_tokenizer.h" #include "base/strings/string_util.h" #include "base/strings/utf_string_conversions.h" #include "util/build_config.h" @@ -448,23 +447,6 @@ AppendSwitchesAndArguments(this, other.argv(), parse_switches_); } -void CommandLine::PrependWrapper(const CommandLine::StringType& wrapper) { - if (wrapper.empty()) - return; - // Split the wrapper command based on whitespace (with quoting). - using CommandLineTokenizer = - StringTokenizerT<StringType, StringType::const_iterator>; - CommandLineTokenizer tokenizer(wrapper, FILE_PATH_LITERAL(" ")); - tokenizer.set_quote_chars(FILE_PATH_LITERAL("'\"")); - std::vector<StringType> wrapper_argv; - while (tokenizer.GetNext()) - wrapper_argv.emplace_back(tokenizer.token()); - - // Prepend the wrapper and update the switches/arguments |begin_args_|. - argv_.insert(argv_.begin(), wrapper_argv.begin(), wrapper_argv.end()); - begin_args_ += wrapper_argv.size(); -} - #if defined(OS_WIN) void CommandLine::ParseFromString(const std::u16string& command_line) { std::u16string command_line_string;
diff --git a/src/base/command_line.h b/src/base/command_line.h index 2e0cb3b..1bce836 100644 --- a/src/base/command_line.h +++ b/src/base/command_line.h
@@ -224,10 +224,6 @@ // If |include_program| is true, include |other|'s program as well. void AppendArguments(const CommandLine& other, bool include_program); - // Insert a command before the current command. - // Common for debuggers, like "gdb --args". - void PrependWrapper(const StringType& wrapper); - #if defined(OS_WIN) // Initialize by parsing the given command line string. // The program name is assumed to be the first item in the string.
diff --git a/src/base/strings/string_tokenizer.h b/src/base/strings/string_tokenizer.h deleted file mode 100644 index fe9401d..0000000 --- a/src/base/strings/string_tokenizer.h +++ /dev/null
@@ -1,250 +0,0 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef BASE_STRINGS_STRING_TOKENIZER_H_ -#define BASE_STRINGS_STRING_TOKENIZER_H_ - -#include <algorithm> -#include <string> -#include <string_view> - -namespace base { - -// StringTokenizerT is a simple string tokenizer class. It works like an -// iterator that with each step (see the Advance method) updates members that -// refer to the next token in the input string. The user may optionally -// configure the tokenizer to return delimiters. -// -// EXAMPLE 1: -// -// char input[] = "this is a test"; -// CStringTokenizer t(input, input + strlen(input), " "); -// while (t.GetNext()) { -// printf("%s\n", t.token().c_str()); -// } -// -// Output: -// -// this -// is -// a -// test -// -// -// EXAMPLE 2: -// -// std::string input = "no-cache=\"foo, bar\", private"; -// StringTokenizer t(input, ", "); -// t.set_quote_chars("\""); -// while (t.GetNext()) { -// printf("%s\n", t.token().c_str()); -// } -// -// Output: -// -// no-cache="foo, bar" -// private -// -// -// EXAMPLE 3: -// -// bool next_is_option = false, next_is_value = false; -// std::string input = "text/html; charset=UTF-8; foo=bar"; -// StringTokenizer t(input, "; ="); -// t.set_options(StringTokenizer::RETURN_DELIMS); -// while (t.GetNext()) { -// if (t.token_is_delim()) { -// switch (*t.token_begin()) { -// case ';': -// next_is_option = true; -// break; -// case '=': -// next_is_value = true; -// break; -// } -// } else { -// const char* label; -// if (next_is_option) { -// label = "option-name"; -// next_is_option = false; -// } else if (next_is_value) { -// label = "option-value"; -// next_is_value = false; -// } else { -// label = "mime-type"; -// } -// printf("%s: %s\n", label, t.token().c_str()); -// } -// } -// -// -template <class str, class const_iterator> -class StringTokenizerT { - public: - typedef typename str::value_type char_type; - - // Options that may be pass to set_options() - enum { - // Specifies the delimiters should be returned as tokens - RETURN_DELIMS = 1 << 0, - }; - - // The string object must live longer than the tokenizer. In particular, this - // should not be constructed with a temporary. The deleted rvalue constructor - // blocks the most obvious instances of this (e.g. passing a string literal to - // the constructor), but caution must still be exercised. - StringTokenizerT(const str& string, const str& delims) { - Init(string.begin(), string.end(), delims); - } - - // Don't allow temporary strings to be used with string tokenizer, since - // Init() would otherwise save iterators to a temporary string. - StringTokenizerT(str&&, const str& delims) = delete; - - StringTokenizerT(const_iterator string_begin, - const_iterator string_end, - const str& delims) { - Init(string_begin, string_end, delims); - } - - // Set the options for this tokenizer. By default, this is 0. - void set_options(int options) { options_ = options; } - - // Set the characters to regard as quotes. By default, this is empty. When - // a quote char is encountered, the tokenizer will switch into a mode where - // it ignores delimiters that it finds. It switches out of this mode once it - // finds another instance of the quote char. If a backslash is encountered - // within a quoted string, then the next character is skipped. - void set_quote_chars(const str& quotes) { quotes_ = quotes; } - - // Call this method to advance the tokenizer to the next delimiter. This - // returns false if the tokenizer is complete. This method must be called - // before calling any of the token* methods. - bool GetNext() { - if (quotes_.empty() && options_ == 0) - return QuickGetNext(); - else - return FullGetNext(); - } - - // Start iterating through tokens from the beginning of the string. - void Reset() { token_end_ = start_pos_; } - - // Returns true if token is a delimiter. When the tokenizer is constructed - // with the RETURN_DELIMS option, this method can be used to check if the - // returned token is actually a delimiter. - bool token_is_delim() const { return token_is_delim_; } - - // If GetNext() returned true, then these methods may be used to read the - // value of the token. - const_iterator token_begin() const { return token_begin_; } - const_iterator token_end() const { return token_end_; } - str token() const { return str(token_begin_, token_end_); } - std::basic_string_view<typename str::value_type> token_piece() const { - return std::basic_string_view<typename str::value_type>( - &*token_begin_, std::distance(token_begin_, token_end_)); - } - - private: - void Init(const_iterator string_begin, - const_iterator string_end, - const str& delims) { - start_pos_ = string_begin; - token_begin_ = string_begin; - token_end_ = string_begin; - end_ = string_end; - delims_ = delims; - options_ = 0; - token_is_delim_ = false; - } - - // Implementation of GetNext() for when we have no quote characters. We have - // two separate implementations because AdvanceOne() is a hot spot in large - // text files with large tokens. - bool QuickGetNext() { - token_is_delim_ = false; - for (;;) { - token_begin_ = token_end_; - if (token_end_ == end_) - return false; - ++token_end_; - if (delims_.find(*token_begin_) == str::npos) - break; - // else skip over delimiter. - } - while (token_end_ != end_ && delims_.find(*token_end_) == str::npos) - ++token_end_; - return true; - } - - // Implementation of GetNext() for when we have to take quotes into account. - bool FullGetNext() { - AdvanceState state; - token_is_delim_ = false; - for (;;) { - token_begin_ = token_end_; - if (token_end_ == end_) - return false; - ++token_end_; - if (AdvanceOne(&state, *token_begin_)) - break; - if (options_ & RETURN_DELIMS) { - token_is_delim_ = true; - return true; - } - // else skip over delimiter. - } - while (token_end_ != end_ && AdvanceOne(&state, *token_end_)) - ++token_end_; - return true; - } - - bool IsDelim(char_type c) const { return delims_.find(c) != str::npos; } - - bool IsQuote(char_type c) const { return quotes_.find(c) != str::npos; } - - struct AdvanceState { - bool in_quote; - bool in_escape; - char_type quote_char; - AdvanceState() : in_quote(false), in_escape(false), quote_char('\0') {} - }; - - // Returns true if a delimiter was not hit. - bool AdvanceOne(AdvanceState* state, char_type c) { - if (state->in_quote) { - if (state->in_escape) { - state->in_escape = false; - } else if (c == '\\') { - state->in_escape = true; - } else if (c == state->quote_char) { - state->in_quote = false; - } - } else { - if (IsDelim(c)) - return false; - state->in_quote = IsQuote(state->quote_char = c); - } - return true; - } - - const_iterator start_pos_; - const_iterator token_begin_; - const_iterator token_end_; - const_iterator end_; - str delims_; - str quotes_; - int options_; - bool token_is_delim_; -}; - -typedef StringTokenizerT<std::string, std::string::const_iterator> - StringTokenizer; -typedef StringTokenizerT<std::u16string, std::u16string::const_iterator> - WStringTokenizer; -typedef StringTokenizerT<std::string, const char*> CStringTokenizer; - -} // namespace base - -#endif // BASE_STRINGS_STRING_TOKENIZER_H_