
Untitled
By: a guest on
Jul 4th, 2012 | syntax:
None | size: 1.39 KB | hits: 6 | expires: Never
- (NSIndexPath) hexStringToPath: (NSString *)hexStr error: (NSError **)error {
NSCharacterSet *numbers = [NSCharacterSet decimalDigitCharacterSet];
NSRange range = [hexStr rangeOfCharacterFromSet:[numbers invertedSet]];
if ([hexStr length] < 4 || range.location == NSNotFound) {
if (error != nil) {
NSString *errorDescription = [NSString stringWithFormat:NSLocalizedString(@"Invalid Hex Location: %@", @"Invalid Hex Location: %@"), hexStr];
NSDictionary *errorUserInfo = [NSDictionary dictionaryWithObjectsAndKeys:
errorDescription, NSLocalizedDescriptionKey, nil];
*error = [NSError errorWithDomain:@"WHErrorDomain" code:0 userInfo:errorUserInfo];
}
return nil;
}
int col, row;
sscanf([hexStr UTF8String], @"%02d%02d", &col, &row);
if (row == 0 || row > 40 || col == 0 || col > 32) {
if (error != nil) {
NSString *errorDescription = [NSString stringWithFormat:NSLocalizedString(@"Invalid Hex Location: %@", @"Invalid Hex Location: %@"), hexStr];
NSDictionary *errorUserInfo = [NSDictionary dictionaryWithObjectsAndKeys:
errorDescription, NSLocalizedDescriptionKey, nil];
*error = [NSError errorWithDomain:@"WHErrorDomain" code:0 userInfo:errorUserInfo];
}
return nil;
}
NSLog(@"hexStr=%@ rowStr = %@ colStr = %@ row=%d col = %d", hexStr, rowStr, colStr, row, col);
return [NSIndexPath indexPathForX: col Y: row];
}