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

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

Issue 2127373006: Use base::StartWith() in more places when appropriate. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix build Created 4 years, 5 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
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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_uuid.h" 5 #include "device/bluetooth/bluetooth_uuid.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/strings/string_util.h" 10 #include "base/strings/string_util.h"
11 11
12 namespace device { 12 namespace device {
13 13
14 namespace { 14 namespace {
15 15
16 const char* kCommonUuidPostfix = "-0000-1000-8000-00805f9b34fb"; 16 const char kCommonUuidPostfix[] = "-0000-1000-8000-00805f9b34fb";
17 const char* kCommonUuidPrefix = "0000"; 17 const char kCommonUuidPrefix[] = "0000";
18 18
19 // Returns the canonical, 128-bit canonical, and the format of the UUID 19 // Returns the canonical, 128-bit canonical, and the format of the UUID
20 // in |canonical|, |canonical_128|, and |format| based on |uuid|. 20 // in |canonical|, |canonical_128|, and |format| based on |uuid|.
21 void GetCanonicalUuid(std::string uuid, 21 void GetCanonicalUuid(std::string uuid,
22 std::string* canonical, 22 std::string* canonical,
23 std::string* canonical_128, 23 std::string* canonical_128,
24 BluetoothUUID::Format* format) { 24 BluetoothUUID::Format* format) {
25 // Initialize the values for the failure case. 25 // Initialize the values for the failure case.
26 canonical->clear(); 26 canonical->clear();
27 canonical_128->clear(); 27 canonical_128->clear();
28 *format = BluetoothUUID::kFormatInvalid; 28 *format = BluetoothUUID::kFormatInvalid;
29 29
30 if (uuid.empty()) 30 if (uuid.empty())
31 return; 31 return;
32 32
33 if (uuid.size() < 11 && uuid.find("0x") == 0) 33 if (uuid.size() < 11 &&
34 base::StartsWith(uuid, "0x", base::CompareCase::SENSITIVE)) {
34 uuid = uuid.substr(2); 35 uuid = uuid.substr(2);
36 }
35 37
36 if (!(uuid.size() == 4 || uuid.size() == 8 || uuid.size() == 36)) 38 if (!(uuid.size() == 4 || uuid.size() == 8 || uuid.size() == 36))
37 return; 39 return;
38 40
39 for (size_t i = 0; i < uuid.size(); ++i) { 41 for (size_t i = 0; i < uuid.size(); ++i) {
40 if (i == 8 || i == 13 || i == 18 || i == 23) { 42 if (i == 8 || i == 13 || i == 18 || i == 23) {
41 if (uuid[i] != '-') 43 if (uuid[i] != '-')
42 return; 44 return;
43 } else { 45 } else {
44 if (!base::IsHexDigit(uuid[i])) 46 if (!base::IsHexDigit(uuid[i]))
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
87 89
88 bool BluetoothUUID::operator!=(const BluetoothUUID& uuid) const { 90 bool BluetoothUUID::operator!=(const BluetoothUUID& uuid) const {
89 return canonical_value_ != uuid.canonical_value_; 91 return canonical_value_ != uuid.canonical_value_;
90 } 92 }
91 93
92 void PrintTo(const BluetoothUUID& uuid, std::ostream* out) { 94 void PrintTo(const BluetoothUUID& uuid, std::ostream* out) {
93 *out << uuid.canonical_value(); 95 *out << uuid.canonical_value();
94 } 96 }
95 97
96 } // namespace device 98 } // namespace device
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698