normalizeBleUuid function
Canonicalizes Bluetooth SIG short UUIDs and full 128-bit UUIDs.
Implementation
String normalizeBleUuid(String value) {
final uuid = value.toLowerCase();
if (RegExp(r'^[0-9a-f]{4}$').hasMatch(uuid)) {
return '0000$uuid-0000-1000-8000-00805f9b34fb';
}
if (RegExp(r'^[0-9a-f]{8}$').hasMatch(uuid)) {
return '$uuid-0000-1000-8000-00805f9b34fb';
}
if (!RegExp(
r'^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$',
).hasMatch(uuid)) {
throw ArgumentError.value(value, 'uuid', 'Expected a Bluetooth UUID');
}
return uuid;
}