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

Side by Side Diff: device/bluetooth/bluetooth_utils.cc

Issue 13145003: Rewrite std::string("") to std::string(), Linux edition. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Ugh Created 7 years, 8 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 | Annotate | Revision Log
« no previous file with comments | « dbus/values_util.cc ('k') | device/media_transfer_protocol/media_transfer_protocol_manager.cc » ('j') | 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) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "device/bluetooth/bluetooth_utils.h" 5 #include "device/bluetooth/bluetooth_utils.h"
6 6
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/basictypes.h" 9 #include "base/basictypes.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
11 #include "base/string_util.h" 11 #include "base/string_util.h"
12 12
13 namespace { 13 namespace {
14 static const char* kCommonUuidPostfix = "-0000-1000-8000-00805f9b34fb"; 14 static const char* kCommonUuidPostfix = "-0000-1000-8000-00805f9b34fb";
15 static const char* kCommonUuidPrefix = "0000"; 15 static const char* kCommonUuidPrefix = "0000";
16 static const int kUuidSize = 36; 16 static const int kUuidSize = 36;
17 } // namespace 17 } // namespace
18 18
19 namespace device { 19 namespace device {
20 namespace bluetooth_utils { 20 namespace bluetooth_utils {
21 21
22 std::string CanonicalUuid(std::string uuid) { 22 std::string CanonicalUuid(std::string uuid) {
23 if (uuid.empty()) 23 if (uuid.empty())
24 return ""; 24 return std::string();
25 25
26 if (uuid.size() < 11 && uuid.find("0x") == 0) 26 if (uuid.size() < 11 && uuid.find("0x") == 0)
27 uuid = uuid.substr(2); 27 uuid = uuid.substr(2);
28 28
29 if (!(uuid.size() == 4 || uuid.size() == 8 || uuid.size() == 36)) 29 if (!(uuid.size() == 4 || uuid.size() == 8 || uuid.size() == 36))
30 return ""; 30 return std::string();
31 31
32 if (uuid.size() == 4 || uuid.size() == 8) { 32 if (uuid.size() == 4 || uuid.size() == 8) {
33 for (size_t i = 0; i < uuid.size(); ++i) { 33 for (size_t i = 0; i < uuid.size(); ++i) {
34 if (!IsHexDigit(uuid[i])) 34 if (!IsHexDigit(uuid[i]))
35 return ""; 35 return std::string();
36 } 36 }
37 37
38 if (uuid.size() == 4) 38 if (uuid.size() == 4)
39 return kCommonUuidPrefix + uuid + kCommonUuidPostfix; 39 return kCommonUuidPrefix + uuid + kCommonUuidPostfix;
40 40
41 return uuid + kCommonUuidPostfix; 41 return uuid + kCommonUuidPostfix;
42 } 42 }
43 43
44 std::string uuid_result(uuid); 44 std::string uuid_result(uuid);
45 for (int i = 0; i < kUuidSize; ++i) { 45 for (int i = 0; i < kUuidSize; ++i) {
46 if (i == 8 || i == 13 || i == 18 || i == 23) { 46 if (i == 8 || i == 13 || i == 18 || i == 23) {
47 if (uuid[i] != '-') 47 if (uuid[i] != '-')
48 return ""; 48 return std::string();
49 } else { 49 } else {
50 if (!IsHexDigit(uuid[i])) 50 if (!IsHexDigit(uuid[i]))
51 return ""; 51 return std::string();
52 uuid_result[i] = tolower(uuid[i]); 52 uuid_result[i] = tolower(uuid[i]);
53 } 53 }
54 } 54 }
55 return uuid_result; 55 return uuid_result;
56 } 56 }
57 57
58 } // namespace bluetooth_utils 58 } // namespace bluetooth_utils
59 } // namespace device 59 } // namespace device
OLDNEW
« no previous file with comments | « dbus/values_util.cc ('k') | device/media_transfer_protocol/media_transfer_protocol_manager.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698