Skip to content

Commit

Permalink
Move TrimWhitespace to the base namespace.
Browse files Browse the repository at this point in the history
R=viettrungluu@chromium.org, viettrungluu

Review URL: https://codereview.chromium.org/183853011

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@254521 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
brettw@chromium.org committed Mar 3, 2014
1 parent d283bc0 commit 8af69c6
Show file tree
Hide file tree
Showing 84 changed files with 176 additions and 161 deletions.
2 changes: 1 addition & 1 deletion ash/shell/app_list.cc
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ class ExampleAppListViewDelegate : public app_list::AppListViewDelegate {

virtual void StartSearch() OVERRIDE {
base::string16 query;
TrimWhitespace(model_->search_box()->text(), TRIM_ALL, &query);
base::TrimWhitespace(model_->search_box()->text(), base::TRIM_ALL, &query);
query = base::i18n::ToLower(query);

model_->results()->DeleteAll();
Expand Down
6 changes: 3 additions & 3 deletions base/command_line.cc
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ void AppendSwitchesAndArguments(CommandLine& command_line,
bool parse_switches = true;
for (size_t i = 1; i < argv.size(); ++i) {
CommandLine::StringType arg = argv[i];
TrimWhitespace(arg, TRIM_ALL, &arg);
base::TrimWhitespace(arg, base::TRIM_ALL, &arg);

CommandLine::StringType switch_string;
CommandLine::StringType switch_value;
Expand Down Expand Up @@ -293,7 +293,7 @@ FilePath CommandLine::GetProgram() const {
}

void CommandLine::SetProgram(const FilePath& program) {
TrimWhitespace(program.value(), TRIM_ALL, &argv_[0]);
base::TrimWhitespace(program.value(), base::TRIM_ALL, &argv_[0]);
}

bool CommandLine::HasSwitch(const std::string& switch_string) const {
Expand Down Expand Up @@ -422,7 +422,7 @@ void CommandLine::PrependWrapper(const CommandLine::StringType& wrapper) {
#if defined(OS_WIN)
void CommandLine::ParseFromString(const std::wstring& command_line) {
std::wstring command_line_string;
TrimWhitespace(command_line, TRIM_ALL, &command_line_string);
base::TrimWhitespace(command_line, base::TRIM_ALL, &command_line_string);
if (command_line_string.empty())
return;

Expand Down
2 changes: 1 addition & 1 deletion base/i18n/file_util_icu.cc
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ void ReplaceIllegalCharactersInPath(base::FilePath::StringType* file_name,
DCHECK(!(IllegalCharacters::GetInstance()->contains(replace_char)));

// Remove leading and trailing whitespace.
TrimWhitespace(*file_name, TRIM_ALL, file_name);
base::TrimWhitespace(*file_name, base::TRIM_ALL, file_name);

IllegalCharacters* illegal = IllegalCharacters::GetInstance();
int cursor = 0; // The ICU macros expect an int.
Expand Down
2 changes: 1 addition & 1 deletion base/linux_util.cc
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ std::string GetLinuxDistro() {

void SetLinuxDistro(const std::string& distro) {
std::string trimmed_distro;
TrimWhitespaceASCII(distro, TRIM_ALL, &trimmed_distro);
base::TrimWhitespaceASCII(distro, base::TRIM_ALL, &trimmed_distro);
base::strlcpy(g_linux_distro, trimmed_distro.c_str(), kDistroSize);
}

Expand Down
11 changes: 6 additions & 5 deletions base/nix/mime_util_xdg.cc
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ bool IconTheme::LoadIndexTheme(const FilePath& file) {
break;

std::string entry;
TrimWhitespaceASCII(buf, TRIM_ALL, &entry);
base::TrimWhitespaceASCII(buf, base::TRIM_ALL, &entry);
if (entry.length() == 0 || entry[0] == '#') {
// Blank line or Comment.
continue;
Expand All @@ -284,10 +284,10 @@ bool IconTheme::LoadIndexTheme(const FilePath& file) {
if (r.size() < 2)
continue;

TrimWhitespaceASCII(r[0], TRIM_ALL, &key);
base::TrimWhitespaceASCII(r[0], base::TRIM_ALL, &key);
for (size_t i = 1; i < r.size(); i++)
value.append(r[i]);
TrimWhitespaceASCII(value, TRIM_ALL, &value);
base::TrimWhitespaceASCII(value, base::TRIM_ALL, &value);

if (current_info) {
if (key == "Size") {
Expand Down Expand Up @@ -366,15 +366,16 @@ bool IconTheme::SetDirectories(const std::string& dirs) {
std::string::size_type pos = 0, epos;
std::string dir;
while ((epos = dirs.find(',', pos)) != std::string::npos) {
TrimWhitespaceASCII(dirs.substr(pos, epos - pos), TRIM_ALL, &dir);
base::TrimWhitespaceASCII(dirs.substr(pos, epos - pos), base::TRIM_ALL,
&dir);
if (dir.length() == 0) {
DLOG(WARNING) << "Invalid index.theme: blank subdir";
return false;
}
subdirs_[dir] = num++;
pos = epos + 1;
}
TrimWhitespaceASCII(dirs.substr(pos), TRIM_ALL, &dir);
base::TrimWhitespaceASCII(dirs.substr(pos), base::TRIM_ALL, &dir);
if (dir.length() == 0) {
DLOG(WARNING) << "Invalid index.theme: blank subdir";
return false;
Expand Down
5 changes: 3 additions & 2 deletions base/process/process_metrics_linux.cc
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ static uint64 ReadFileToUint64(const base::FilePath file) {
std::string file_as_string;
if (!ReadFileToString(file, &file_as_string))
return 0;
TrimWhitespaceASCII(file_as_string, TRIM_ALL, &file_as_string);
base::TrimWhitespaceASCII(file_as_string, base::TRIM_ALL, &file_as_string);
uint64 file_as_uint64 = 0;
if (!base::StringToUint64(file_as_string, &file_as_uint64))
return 0;
Expand Down Expand Up @@ -71,7 +71,8 @@ size_t ReadProcStatusAndGetFieldAsSizeT(pid_t pid, const std::string& field) {
std::string value_str;
tokenizer.token_piece().CopyToString(&value_str);
std::string value_str_trimmed;
TrimWhitespaceASCII(value_str, TRIM_ALL, &value_str_trimmed);
base::TrimWhitespaceASCII(value_str, base::TRIM_ALL,
&value_str_trimmed);
std::vector<std::string> split_value_str;
SplitString(value_str_trimmed, ' ', &split_value_str);
if (split_value_str.size() != 2 || split_value_str[1] != "kB") {
Expand Down
12 changes: 6 additions & 6 deletions base/strings/string_util.cc
Original file line number Diff line number Diff line change
Expand Up @@ -242,18 +242,16 @@ void TruncateUTF8ToByteSize(const std::string& input,
output->clear();
}

} // namespace base

TrimPositions TrimWhitespace(const base::string16& input,
TrimPositions TrimWhitespace(const string16& input,
TrimPositions positions,
base::string16* output) {
return base::TrimStringT(input, base::kWhitespaceUTF16, positions, output);
string16* output) {
return TrimStringT(input, kWhitespaceUTF16, positions, output);
}

TrimPositions TrimWhitespaceASCII(const std::string& input,
TrimPositions positions,
std::string* output) {
return base::TrimStringT(input, base::kWhitespaceASCII, positions, output);
return TrimStringT(input, kWhitespaceASCII, positions, output);
}

// This function is only for backward-compatibility.
Expand All @@ -264,6 +262,8 @@ TrimPositions TrimWhitespace(const std::string& input,
return TrimWhitespaceASCII(input, positions, output);
}

} // namespace base

template<typename STR>
STR CollapseWhitespaceT(const STR& text,
bool trim_sequences_with_line_breaks) {
Expand Down
22 changes: 11 additions & 11 deletions base/strings/string_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -188,16 +188,6 @@ BASE_EXPORT void TruncateUTF8ToByteSize(const std::string& input,
const size_t byte_size,
std::string* output);

} // namespace base

#if defined(OS_WIN)
#include "base/strings/string_util_win.h"
#elif defined(OS_POSIX)
#include "base/strings/string_util_posix.h"
#else
#error Define string operations appropriately for your platform
#endif

// Trims any whitespace from either end of the input string. Returns where
// whitespace was found.
// The non-wide version has two functions:
Expand All @@ -211,7 +201,7 @@ enum TrimPositions {
TRIM_TRAILING = 1 << 1,
TRIM_ALL = TRIM_LEADING | TRIM_TRAILING,
};
BASE_EXPORT TrimPositions TrimWhitespace(const base::string16& input,
BASE_EXPORT TrimPositions TrimWhitespace(const string16& input,
TrimPositions positions,
base::string16* output);
BASE_EXPORT TrimPositions TrimWhitespaceASCII(const std::string& input,
Expand All @@ -224,6 +214,16 @@ BASE_EXPORT TrimPositions TrimWhitespace(const std::string& input,
TrimPositions positions,
std::string* output);

} // namespace base

#if defined(OS_WIN)
#include "base/strings/string_util_win.h"
#elif defined(OS_POSIX)
#include "base/strings/string_util_posix.h"
#else
#error Define string operations appropriately for your platform
#endif

// Searches for CR or LF characters. Removes all contiguous whitespace
// strings that contain them. This is useful when trying to deal with text
// copied from terminals.
Expand Down
7 changes: 4 additions & 3 deletions chrome/browser/autocomplete/autocomplete_input.cc
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@ AutocompleteInput::AutocompleteInput(
<< "Text: '" << text << "', cp: " << cursor_position;
// None of the providers care about leading white space so we always trim it.
// Providers that care about trailing white space handle trimming themselves.
if ((TrimWhitespace(text, TRIM_LEADING, &text_) & TRIM_LEADING) != 0)
if ((base::TrimWhitespace(text, base::TRIM_LEADING, &text_) &
base::TRIM_LEADING) != 0)
AdjustCursorPositionIfNecessary(text.length() - text_.length(),
&cursor_position_);

Expand All @@ -83,8 +84,8 @@ AutocompleteInput::AutocompleteInput(
if (chars_removed) {
// Remove spaces between opening question mark and first actual character.
base::string16 trimmed_text;
if ((TrimWhitespace(text_, TRIM_LEADING, &trimmed_text) & TRIM_LEADING) !=
0) {
if ((base::TrimWhitespace(text_, base::TRIM_LEADING, &trimmed_text) &
base::TRIM_LEADING) != 0) {
AdjustCursorPositionIfNecessary(text_.length() - trimmed_text.length(),
&cursor_position_);
text_ = trimmed_text;
Expand Down
2 changes: 1 addition & 1 deletion chrome/browser/autocomplete/autocomplete_match.cc
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ base::string16 AutocompleteMatch::SanitizeString(const base::string16& text) {
// NOTE: This logic is mirrored by |sanitizeString()| in
// omnibox_custom_bindings.js.
base::string16 result;
TrimWhitespace(text, TRIM_LEADING, &result);
base::TrimWhitespace(text, base::TRIM_LEADING, &result);
base::RemoveChars(result, kInvalidChars, &result);
return result;
}
Expand Down
2 changes: 1 addition & 1 deletion chrome/browser/autocomplete/keyword_provider.cc
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ base::string16 KeywordProvider::SplitReplacementStringFromInput(
bool trim_leading_whitespace) {
// The input may contain leading whitespace, strip it.
base::string16 trimmed_input;
TrimWhitespace(input, TRIM_LEADING, &trimmed_input);
base::TrimWhitespace(input, base::TRIM_LEADING, &trimmed_input);

// And extract the replacement string.
base::string16 remaining_input;
Expand Down
2 changes: 1 addition & 1 deletion chrome/browser/chromeos/options/vpn_config_view.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1029,7 +1029,7 @@ const std::string VPNConfigView::GetTextFromField(views::Textfield* textfield,
if (!trim_whitespace)
return untrimmed;
std::string result;
TrimWhitespaceASCII(untrimmed, TRIM_ALL, &result);
base::TrimWhitespaceASCII(untrimmed, base::TRIM_ALL, &result);
return result;
}

Expand Down
2 changes: 1 addition & 1 deletion chrome/browser/chromeos/options/wifi_config_view.cc
Original file line number Diff line number Diff line change
Expand Up @@ -736,7 +736,7 @@ std::string WifiConfigView::GetSsid() const {
std::string result;
if (ssid_textfield_ != NULL) {
std::string untrimmed = base::UTF16ToUTF8(ssid_textfield_->text());
TrimWhitespaceASCII(untrimmed, TRIM_ALL, &result);
base::TrimWhitespaceASCII(untrimmed, base::TRIM_ALL, &result);
}
return result;
}
Expand Down
4 changes: 2 additions & 2 deletions chrome/browser/chromeos/system/syslogs_provider.cc
Original file line number Diff line number Diff line change
Expand Up @@ -155,11 +155,11 @@ LogDictionaryType* GetSystemLogs(base::FilePath* zip_file_name,
LogDictionaryType* logs = new LogDictionaryType();
while (data.length() > 0) {
std::string key = ReadKey(&data);
TrimWhitespaceASCII(key, TRIM_ALL, &key);
base::TrimWhitespaceASCII(key, base::TRIM_ALL, &key);
if (!key.empty()) {
std::string value = ReadValue(&data);
if (IsStringUTF8(value)) {
TrimWhitespaceASCII(value, TRIM_ALL, &value);
base::TrimWhitespaceASCII(value, base::TRIM_ALL, &value);
if (value.empty())
(*logs)[key] = kEmptyLogEntry;
else
Expand Down
2 changes: 1 addition & 1 deletion chrome/browser/devtools/adb_client_socket.cc
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ class HttpOverAdbSocket {
if (endline_pos != std::string::npos) {
std::string len = response_.substr(content_pos + 15,
endline_pos - content_pos - 15);
TrimWhitespace(len, TRIM_ALL, &len);
base::TrimWhitespace(len, base::TRIM_ALL, &len);
if (!base::StringToInt(len, &expected_length)) {
CheckNetResultOrDie(net::ERR_FAILED);
return;
Expand Down
4 changes: 2 additions & 2 deletions chrome/browser/download/download_browsertest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1950,11 +1950,11 @@ IN_PROC_BROWSER_TEST_F(DownloadTest, MAYBE_DownloadTest_History) {
EXPECT_EQ(download_url, item->GetURL());
// The following are set by download-test1.lib.mock-http-headers.
std::string etag = item->GetETag();
TrimWhitespaceASCII(etag, TRIM_ALL, &etag);
base::TrimWhitespaceASCII(etag, base::TRIM_ALL, &etag);
EXPECT_EQ("abracadabra", etag);

std::string last_modified = item->GetLastModifiedTime();
TrimWhitespaceASCII(last_modified, TRIM_ALL, &last_modified);
base::TrimWhitespaceASCII(last_modified, base::TRIM_ALL, &last_modified);
EXPECT_EQ("Mon, 13 Nov 2006 20:31:09 GMT", last_modified);
}

Expand Down
2 changes: 1 addition & 1 deletion chrome/browser/extensions/user_script_master.cc
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ static bool GetDeclarationValue(const base::StringPiece& line,
if (temp.empty() || !IsWhitespace(temp[0]))
return false;

TrimWhitespaceASCII(temp, TRIM_ALL, value);
base::TrimWhitespaceASCII(temp, base::TRIM_ALL, value);
return true;
}

Expand Down
3 changes: 2 additions & 1 deletion chrome/browser/file_select_helper.cc
Original file line number Diff line number Diff line change
Expand Up @@ -479,7 +479,8 @@ bool FileSelectHelper::IsAcceptTypeValid(const std::string& accept_type) {
std::string unused;
if (accept_type.length() <= 1 ||
StringToLowerASCII(accept_type) != accept_type ||
TrimWhitespaceASCII(accept_type, TRIM_ALL, &unused) != TRIM_NONE) {
base::TrimWhitespaceASCII(accept_type, base::TRIM_ALL, &unused) !=
base::TRIM_NONE) {
return false;
}
return true;
Expand Down
2 changes: 1 addition & 1 deletion chrome/browser/google/google_url_tracker.cc
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ void GoogleURLTracker::OnURLFetchComplete(const net::URLFetcher* source) {
// "<scheme>://[www.]google.<TLD>/".
std::string url_str;
source->GetResponseAsString(&url_str);
TrimWhitespace(url_str, TRIM_ALL, &url_str);
base::TrimWhitespace(url_str, base::TRIM_ALL, &url_str);
GURL url(url_str);
if (!url.is_valid() || (url.path().length() > 1) || url.has_query() ||
url.has_ref() ||
Expand Down
2 changes: 1 addition & 1 deletion chrome/browser/google/google_util_chromeos.cc
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ std::string ReadBrandFromFile() {
base::FilePath brand_file_path(kRLZBrandFilePath);
if (!base::ReadFileToString(brand_file_path, &brand))
LOG(WARNING) << "Brand code file missing: " << brand_file_path.value();
TrimWhitespace(brand, TRIM_ALL, &brand);
base::TrimWhitespace(brand, base::TRIM_ALL, &brand);
return brand;
}

Expand Down
4 changes: 2 additions & 2 deletions chrome/browser/history/in_memory_url_index_types.cc
Original file line number Diff line number Diff line change
Expand Up @@ -144,9 +144,9 @@ String16Vector String16VectorFromString16(
size_t initial_whitespace = 0;
if (break_on_space) {
base::string16 trimmed_word;
TrimWhitespace(word, TRIM_LEADING, &trimmed_word);
base::TrimWhitespace(word, base::TRIM_LEADING, &trimmed_word);
initial_whitespace = word.length() - trimmed_word.length();
TrimWhitespace(trimmed_word, TRIM_TRAILING, &word);
base::TrimWhitespace(trimmed_word, base::TRIM_TRAILING, &word);
}
if (word.empty())
continue;
Expand Down
4 changes: 2 additions & 2 deletions chrome/browser/net/firefox_proxy_settings.cc
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ bool ParsePrefFile(const base::FilePath& pref_file,
}
std::string value = line.substr(start_value + 1,
stop_value - start_value - 1);
TrimWhitespace(value, TRIM_ALL, &value);
base::TrimWhitespace(value, base::TRIM_ALL, &value);
// Value could be a boolean.
bool is_value_true = LowerCaseEqualsASCII(value, "true");
if (is_value_true || LowerCaseEqualsASCII(value, "false")) {
Expand Down Expand Up @@ -298,7 +298,7 @@ bool FirefoxProxySettings::GetSettingsFromFile(const base::FilePath& pref_file,
base::StringTokenizer string_tok(proxy_bypass, ",");
while (string_tok.GetNext()) {
std::string token = string_tok.token();
TrimWhitespaceASCII(token, TRIM_ALL, &token);
base::TrimWhitespaceASCII(token, base::TRIM_ALL, &token);
if (!token.empty())
settings->proxy_bypass_list_.push_back(token);
}
Expand Down
4 changes: 2 additions & 2 deletions chrome/browser/profiles/profile_shortcut_manager_win.cc
Original file line number Diff line number Diff line change
Expand Up @@ -596,10 +596,10 @@ base::string16 SanitizeShortcutProfileNameString(
pos = sanitized.find_first_of(kReservedCharacters, pos + 1);
}

TrimWhitespace(sanitized, TRIM_LEADING, &sanitized);
base::TrimWhitespace(sanitized, base::TRIM_LEADING, &sanitized);
if (sanitized.size() > kMaxProfileShortcutFileNameLength)
sanitized.erase(kMaxProfileShortcutFileNameLength);
TrimWhitespace(sanitized, TRIM_TRAILING, &sanitized);
base::TrimWhitespace(sanitized, base::TRIM_TRAILING, &sanitized);

return sanitized;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -938,7 +938,8 @@ void RenderViewContextMenu::AppendPrintItem() {
void RenderViewContextMenu::AppendSearchProvider() {
DCHECK(profile_);

TrimWhitespace(params_.selection_text, TRIM_ALL, &params_.selection_text);
base::TrimWhitespace(params_.selection_text, base::TRIM_ALL,
&params_.selection_text);
if (params_.selection_text.empty())
return;

Expand Down
2 changes: 1 addition & 1 deletion chrome/browser/search_engines/template_url_service.cc
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ base::string16 TemplateURLService::CleanUserInputKeyword(
const base::string16& keyword) {
// Remove the scheme.
base::string16 result(base::i18n::ToLower(keyword));
TrimWhitespace(result, TRIM_ALL, &result);
base::TrimWhitespace(result, base::TRIM_ALL, &result);
url_parse::Component scheme_component;
if (url_parse::ExtractScheme(base::UTF16ToUTF8(keyword).c_str(),
static_cast<int>(keyword.length()),
Expand Down
4 changes: 2 additions & 2 deletions chrome/browser/spellchecker/spellcheck_custom_dictionary.cc
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ ChecksumStatus LoadFile(const base::FilePath& file_path, WordList& words) {
if (checksum != base::MD5String(contents))
return INVALID_CHECKSUM;
}
TrimWhitespaceASCII(contents, TRIM_ALL, &contents);
base::TrimWhitespaceASCII(contents, base::TRIM_ALL, &contents);
base::SplitString(contents, '\n', &words);
return VALID_CHECKSUM;
}
Expand All @@ -80,7 +80,7 @@ bool IsInvalidWord(const std::string& word) {
word.length() >
chrome::spellcheck_common::MAX_CUSTOM_DICTIONARY_WORD_BYTES ||
word.empty() ||
TRIM_NONE != TrimWhitespaceASCII(word, TRIM_ALL, &tmp);
base::TRIM_NONE != base::TrimWhitespaceASCII(word, base::TRIM_ALL, &tmp);
}

// Loads the custom spellcheck dictionary from |path| into |custom_words|. If
Expand Down
Loading

0 comments on commit 8af69c6

Please sign in to comment.