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

Unified Diff: device/bluetooth/bluetooth_device.cc

Issue 288903003: [Bluetooth] Standardize Bluetooth device address format to XX:XX:XX:XX:XX:XX. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix ChromeOS tests too Created 6 years, 7 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « device/bluetooth/bluetooth_device.h ('k') | device/bluetooth/bluetooth_device_chromeos.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: device/bluetooth/bluetooth_device.cc
diff --git a/device/bluetooth/bluetooth_device.cc b/device/bluetooth/bluetooth_device.cc
index e29e34f7d5c0e6f9f89bcebe676a9f1a4761f627..5abff605e2fbbaeff0a6599c611b103f144c8cf6 100644
--- a/device/bluetooth/bluetooth_device.cc
+++ b/device/bluetooth/bluetooth_device.cc
@@ -6,6 +6,7 @@
#include <string>
+#include "base/strings/string_util.h"
#include "base/strings/utf_string_conversions.h"
#include "device/bluetooth/bluetooth_gatt_service.h"
#include "grit/device_bluetooth_strings.h"
@@ -187,4 +188,39 @@ BluetoothGattService* BluetoothDevice::GetGattService(
return NULL;
}
+// static
+std::string BluetoothDevice::CanonicalizeAddress(const std::string& address) {
+ std::string canonicalized = address;
+ if (address.size() == 12) {
+ // Might be an address in the format "1A2B3C4D5E6F". Add separators.
+ for (size_t i = 2; i < canonicalized.size(); i += 3) {
+ canonicalized.insert(i, ":");
+ }
+ }
+
+ // Verify that the length matches the canonical format "1A:2B:3C:4D:5E:6F".
+ const size_t kCanonicalAddressLength = 17;
+ if (canonicalized.size() != kCanonicalAddressLength)
+ return std::string();
+
+ const char separator = canonicalized[2];
+ for (size_t i = 0; i < canonicalized.size(); ++i) {
+ bool is_separator = (i + 1) % 3 == 0;
+ if (is_separator) {
+ // All separators in the input |address| should be consistent.
+ if (canonicalized[i] != separator)
+ return std::string();
+
+ canonicalized[i] = ':';
+ } else {
+ if (!IsHexDigit(canonicalized[i]))
+ return std::string();
+
+ canonicalized[i] = base::ToUpperASCII(canonicalized[i]);
+ }
+ }
+
+ return canonicalized;
+}
+
} // namespace device
« no previous file with comments | « device/bluetooth/bluetooth_device.h ('k') | device/bluetooth/bluetooth_device_chromeos.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698