10529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch// Copyright 2014 The Chromium Authors. All rights reserved. 20529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch// Use of this source code is governed by a BSD-style license that can be 30529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch// found in the LICENSE file. 40529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch 5cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)#include "components/bookmarks/browser/bookmark_match.h" 60529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch 70529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch#include "base/logging.h" 80529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch#include "base/strings/string16.h" 90529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch 10f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)namespace bookmarks { 11f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) 120529e5d033099cbfc42635f6f6183833b09dff6eBen MurdochBookmarkMatch::BookmarkMatch() : node(NULL) {} 130529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch 140529e5d033099cbfc42635f6f6183833b09dff6eBen MurdochBookmarkMatch::~BookmarkMatch() {} 150529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch 160529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch// static 170529e5d033099cbfc42635f6f6183833b09dff6eBen Murdochstd::vector<size_t> BookmarkMatch::OffsetsFromMatchPositions( 180529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch const MatchPositions& match_positions) { 190529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch std::vector<size_t> offsets; 200529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch for (MatchPositions::const_iterator i = match_positions.begin(); 210529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch i != match_positions.end(); ++i) { 220529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch offsets.push_back(i->first); 230529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch offsets.push_back(i->second); 240529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch } 250529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch return offsets; 260529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch} 270529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch 280529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch// static 290529e5d033099cbfc42635f6f6183833b09dff6eBen MurdochBookmarkMatch::MatchPositions BookmarkMatch::ReplaceOffsetsInMatchPositions( 300529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch const MatchPositions& match_positions, 310529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch const std::vector<size_t>& offsets) { 320529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch DCHECK_EQ(2 * match_positions.size(), offsets.size()); 330529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch MatchPositions new_match_positions; 340529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch std::vector<size_t>::const_iterator offset_iter = offsets.begin(); 350529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch for (MatchPositions::const_iterator match_iter = match_positions.begin(); 360529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch match_iter != match_positions.end(); ++match_iter, ++offset_iter) { 370529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch const size_t begin = *offset_iter; 380529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch ++offset_iter; 390529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch const size_t end = *offset_iter; 400529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch if ((begin != base::string16::npos) && (end != base::string16::npos)) { 410529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch const MatchPosition new_match_position(begin, end); 420529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch new_match_positions.push_back(new_match_position); 430529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch } 440529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch } 450529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch return new_match_positions; 460529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch} 47f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) 48f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)} // namespace bookmarks 49