| 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
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..b650f331b59b042136aeefc5cc9813f5a32bb245
|
| --- /dev/null
|
| +++ b/components/bookmarks/browser/titled_url_match.cc
|
| @@ -0,0 +1,50 @@
|
| +// Copyright 2016 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.
|
| +
|
| +#include "components/bookmarks/browser/titled_url_match.h"
|
| +
|
| +#include "base/logging.h"
|
| +#include "base/strings/string16.h"
|
| +
|
| +namespace bookmarks {
|
| +
|
| +TitledUrlMatch::TitledUrlMatch() : node(NULL) {}
|
| +
|
| +TitledUrlMatch::TitledUrlMatch(const TitledUrlMatch& other) = default;
|
| +
|
| +TitledUrlMatch::~TitledUrlMatch() {}
|
| +
|
| +// static
|
| +std::vector<size_t> TitledUrlMatch::OffsetsFromMatchPositions(
|
| + const MatchPositions& match_positions) {
|
| + std::vector<size_t> offsets;
|
| + for (MatchPositions::const_iterator i = match_positions.begin();
|
| + i != match_positions.end(); ++i) {
|
| + offsets.push_back(i->first);
|
| + offsets.push_back(i->second);
|
| + }
|
| + return offsets;
|
| +}
|
| +
|
| +// static
|
| +TitledUrlMatch::MatchPositions TitledUrlMatch::ReplaceOffsetsInMatchPositions(
|
| + const MatchPositions& match_positions,
|
| + const std::vector<size_t>& offsets) {
|
| + DCHECK_EQ(2 * match_positions.size(), offsets.size());
|
| + MatchPositions new_match_positions;
|
| + std::vector<size_t>::const_iterator offset_iter = offsets.begin();
|
| + for (MatchPositions::const_iterator match_iter = match_positions.begin();
|
| + match_iter != match_positions.end(); ++match_iter, ++offset_iter) {
|
| + const size_t begin = *offset_iter;
|
| + ++offset_iter;
|
| + const size_t end = *offset_iter;
|
| + if ((begin != base::string16::npos) && (end != base::string16::npos)) {
|
| + const MatchPosition new_match_position(begin, end);
|
| + new_match_positions.push_back(new_match_position);
|
| + }
|
| + }
|
| + return new_match_positions;
|
| +}
|
| +
|
| +} // namespace bookmarks
|
|
|