Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(683)

Side by Side Diff: chrome/test/model_test_utils.cc

Issue 3141033: Remove wstrings from bookmarks, part 13. (Closed)
Patch Set: macoops3 Created 10 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « chrome/test/model_test_utils.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "model_test_utils.h" 5 #include "model_test_utils.h"
6 6
7 #include "base/utf_string_conversions.h" 7 #include "base/utf_string_conversions.h"
8 #include "chrome/browser/bookmarks/bookmark_model.h" 8 #include "chrome/browser/bookmarks/bookmark_model.h"
9 #include "googleurl/src/gurl.h" 9 #include "googleurl/src/gurl.h"
10 10
11 namespace model_test_utils { 11 namespace model_test_utils {
12 12
13 std::wstring ModelStringFromNode(const BookmarkNode* node) { 13 std::string ModelStringFromNode(const BookmarkNode* node) {
14 // Since the children of the node are not available as a vector, 14 // Since the children of the node are not available as a vector,
15 // we'll just have to do it the hard way. 15 // we'll just have to do it the hard way.
16 int child_count = node->GetChildCount(); 16 int child_count = node->GetChildCount();
17 std::wstring child_string; 17 std::string child_string;
18 for (int i = 0; i < child_count; ++i) { 18 for (int i = 0; i < child_count; ++i) {
19 const BookmarkNode* child = node->GetChild(i); 19 const BookmarkNode* child = node->GetChild(i);
20 if (child->is_folder()) { 20 if (child->is_folder()) {
21 child_string += child->GetTitle() + L":[ " + ModelStringFromNode(child) 21 child_string += UTF16ToUTF8(child->GetTitleAsString16()) + ":[ " +
22 + L"] "; 22 ModelStringFromNode(child) + "] ";
23 } else { 23 } else {
24 child_string += child->GetTitle() + L" "; 24 child_string += UTF16ToUTF8(child->GetTitleAsString16()) + " ";
25 } 25 }
26 } 26 }
27 return child_string; 27 return child_string;
28 } 28 }
29 29
30 // Helper function which does the actual work of creating the nodes for 30 // Helper function which does the actual work of creating the nodes for
31 // a particular level in the hierarchy. 31 // a particular level in the hierarchy.
32 std::wstring::size_type AddNodesFromString(BookmarkModel& model, 32 std::string::size_type AddNodesFromString(BookmarkModel& model,
33 const BookmarkNode* node, 33 const BookmarkNode* node,
34 const std::wstring& model_string, 34 const std::string& model_string,
35 std::wstring::size_type start_pos) { 35 std::string::size_type start_pos) {
36 DCHECK(node); 36 DCHECK(node);
37 int index = node->GetChildCount(); 37 int index = node->GetChildCount();
38 static const std::wstring folder_tell(L":["); 38 static const std::string folder_tell(":[");
39 std::wstring::size_type end_pos = model_string.find(' ', start_pos); 39 std::string::size_type end_pos = model_string.find(' ', start_pos);
40 while (end_pos != std::wstring::npos) { 40 while (end_pos != std::string::npos) {
41 std::wstring::size_type part_length = end_pos - start_pos; 41 std::string::size_type part_length = end_pos - start_pos;
42 std::wstring node_name = model_string.substr(start_pos, part_length); 42 std::string node_name = model_string.substr(start_pos, part_length);
43 // Are we at the end of a folder group? 43 // Are we at the end of a folder group?
44 if (node_name != L"]") { 44 if (node_name != "]") {
45 // No, is it a folder? 45 // No, is it a folder?
46 std::wstring tell; 46 std::string tell;
47 if (part_length > 2) 47 if (part_length > 2)
48 tell = node_name.substr(part_length - 2, 2); 48 tell = node_name.substr(part_length - 2, 2);
49 if (tell == folder_tell) { 49 if (tell == folder_tell) {
50 node_name = node_name.substr(0, part_length - 2); 50 node_name = node_name.substr(0, part_length - 2);
51 const BookmarkNode* new_node = 51 const BookmarkNode* new_node =
52 model.AddGroup(node, index, WideToUTF16Hack(node_name)); 52 model.AddGroup(node, index, UTF8ToUTF16(node_name));
53 end_pos = AddNodesFromString(model, new_node, model_string, 53 end_pos = AddNodesFromString(model, new_node, model_string,
54 end_pos + 1); 54 end_pos + 1);
55 } else { 55 } else {
56 std::string url_string("http://"); 56 std::string url_string("http://");
57 url_string += std::string(node_name.begin(), node_name.end()); 57 url_string += std::string(node_name.begin(), node_name.end());
58 url_string += ".com"; 58 url_string += ".com";
59 model.AddURL(node, index, WideToUTF16Hack(node_name), GURL(url_string)); 59 model.AddURL(node, index, UTF8ToUTF16(node_name), GURL(url_string));
60 ++end_pos; 60 ++end_pos;
61 } 61 }
62 ++index; 62 ++index;
63 start_pos = end_pos; 63 start_pos = end_pos;
64 end_pos = model_string.find(' ', start_pos); 64 end_pos = model_string.find(' ', start_pos);
65 } else { 65 } else {
66 ++end_pos; 66 ++end_pos;
67 break; 67 break;
68 } 68 }
69 } 69 }
70 return end_pos; 70 return end_pos;
71 } 71 }
72 72
73 void AddNodesFromModelString(BookmarkModel& model, 73 void AddNodesFromModelString(BookmarkModel& model,
74 const BookmarkNode* node, 74 const BookmarkNode* node,
75 const std::wstring& model_string) { 75 const std::string& model_string) {
76 DCHECK(node); 76 DCHECK(node);
77 const std::wstring folder_tell(L":["); 77 const std::string folder_tell(":[");
78 std::wstring::size_type start_pos = 0; 78 std::string::size_type start_pos = 0;
79 std::wstring::size_type end_pos = 79 std::string::size_type end_pos =
80 AddNodesFromString(model, node, model_string, start_pos); 80 AddNodesFromString(model, node, model_string, start_pos);
81 DCHECK(end_pos == std::wstring::npos); 81 DCHECK(end_pos == std::string::npos);
82 } 82 }
83 83
84 } // namespace model_test_utils 84 } // namespace model_test_utils
OLDNEW
« no previous file with comments | « chrome/test/model_test_utils.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698