Index: components/bookmarks/browser/titled_url_match.cc |
diff --git a/components/bookmarks/browser/titled_url_match.cc b/components/bookmarks/browser/titled_url_match.cc |
index 313ae4ef17704659e8cc8fa45a64447a4202bf14..2c2b1d2b4163da793d2c8b763ee38f8be52879ea 100644 |
--- a/components/bookmarks/browser/titled_url_match.cc |
+++ b/components/bookmarks/browser/titled_url_match.cc |
@@ -5,7 +5,7 @@ |
#include "components/bookmarks/browser/titled_url_match.h" |
#include "base/logging.h" |
-#include "base/strings/string16.h" |
+#include "base/strings/string_util.h" |
namespace bookmarks { |
@@ -47,4 +47,21 @@ TitledUrlMatch::MatchPositions TitledUrlMatch::ReplaceOffsetsInMatchPositions( |
return new_match_positions; |
} |
+// static |
+void TitledUrlMatch::CorrectTitleAndMatchPositions( |
+ base::string16* title, |
+ MatchPositions* title_match_positions) { |
+ size_t leading_whitespace_chars = title->length(); |
+ base::TrimWhitespace(*title, base::TRIM_LEADING, title); |
+ leading_whitespace_chars -= title->length(); |
+ if (leading_whitespace_chars == 0) { |
sky
2016/12/16 19:32:54
no {}
mattreynolds
2016/12/19 20:09:15
Done.
|
+ return; |
+ } |
+ for (MatchPositions::iterator it = title_match_positions->begin(); |
+ it != title_match_positions->end(); ++it) { |
+ (*it) = MatchPosition(it->first - leading_whitespace_chars, |
sky
2016/12/16 19:32:54
optional: do an in place update, e.g. it->first -=
mattreynolds
2016/12/19 20:09:15
Done.
|
+ it->second - leading_whitespace_chars); |
+ } |
+} |
+ |
} // namespace bookmarks |