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
3 // found in the LICENSE file.
5 #include "device/bluetooth/bluetooth_utils.h"
9 #include "base/basictypes.h"
10 #include "base/logging.h"
11 #include "base/strings/string_util.h"
14 static const char* kCommonUuidPostfix
= "-0000-1000-8000-00805f9b34fb";
15 static const char* kCommonUuidPrefix
= "0000";
16 static const int kUuidSize
= 36;
20 namespace bluetooth_utils
{
22 std::string
CanonicalUuid(std::string uuid
) {
26 if (uuid
.size() < 11 && uuid
.find("0x") == 0)
27 uuid
= uuid
.substr(2);
29 if (!(uuid
.size() == 4 || uuid
.size() == 8 || uuid
.size() == 36))
32 if (uuid
.size() == 4 || uuid
.size() == 8) {
33 for (size_t i
= 0; i
< uuid
.size(); ++i
) {
34 if (!IsHexDigit(uuid
[i
]))
39 return kCommonUuidPrefix
+ uuid
+ kCommonUuidPostfix
;
41 return uuid
+ kCommonUuidPostfix
;
44 std::string
uuid_result(uuid
);
45 for (int i
= 0; i
< kUuidSize
; ++i
) {
46 if (i
== 8 || i
== 13 || i
== 18 || i
== 23) {
50 if (!IsHexDigit(uuid
[i
]))
52 uuid_result
[i
] = tolower(uuid
[i
]);
58 } // namespace bluetooth_utils