use fallback to latin1 for invalid UTF8 names

This commit is contained in:
matthias.ringwald 2010-05-28 21:55:29 +00:00
parent 3a3bdd0105
commit c84ced3eff

View File

@ -449,7 +449,14 @@ static void packet_handler(uint8_t packet_type, uint16_t channel, uint8_t *packe
// get lenght: first null byte or max 248 chars
int nameLen = 0;
while (nameLen < 248 && packet[9+nameLen]) nameLen++;
// Bluetooth specification mandates UTF-8 encoding...
NSString *name = [[NSString alloc] initWithBytes:&packet[9] length:nameLen encoding:NSUTF8StringEncoding];
// but fallback to latin-1 for non-standard products like old Microsoft Wireless Presenter
if (!name){
name = [[NSString alloc] initWithBytes:&packet[9] length:nameLen encoding:NSISOLatin1StringEncoding];
}
// check again
if (name){
device.name = name;
// set in device info
NSString *addrString = [[device addressString] retain];
@ -462,6 +469,7 @@ static void packet_handler(uint8_t packet_type, uint16_t channel, uint8_t *packe
[addrString release];
[self sendDeviceInfo:device];
}
}
discoveryDeviceIndex++;
[self discoveryRemoteName];
}