Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Jul 4th, 2012  |  syntax: None  |  size: 1.39 KB  |  hits: 6  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. - (NSIndexPath) hexStringToPath: (NSString *)hexStr error: (NSError **)error {
  2.         NSCharacterSet *numbers = [NSCharacterSet decimalDigitCharacterSet];
  3.         NSRange range = [hexStr rangeOfCharacterFromSet:[numbers invertedSet]];
  4.         if ([hexStr length] < 4 || range.location == NSNotFound) {
  5.                 if (error != nil) {
  6.                         NSString *errorDescription = [NSString stringWithFormat:NSLocalizedString(@"Invalid Hex Location: %@", @"Invalid Hex Location: %@"), hexStr];
  7.                         NSDictionary *errorUserInfo = [NSDictionary dictionaryWithObjectsAndKeys:
  8.                                                                                    errorDescription, NSLocalizedDescriptionKey, nil];
  9.                         *error = [NSError errorWithDomain:@"WHErrorDomain" code:0 userInfo:errorUserInfo];
  10.                 }
  11.                
  12.                 return nil;
  13.         }
  14.        
  15.         int col, row;
  16.         sscanf([hexStr UTF8String], @"%02d%02d", &col, &row);
  17.        
  18.         if (row == 0 || row > 40 || col == 0 || col > 32) {
  19.                 if (error != nil) {
  20.                         NSString *errorDescription = [NSString stringWithFormat:NSLocalizedString(@"Invalid Hex Location: %@", @"Invalid Hex Location: %@"), hexStr];
  21.                         NSDictionary *errorUserInfo = [NSDictionary dictionaryWithObjectsAndKeys:
  22.                                                                                    errorDescription, NSLocalizedDescriptionKey, nil];
  23.                         *error = [NSError errorWithDomain:@"WHErrorDomain" code:0 userInfo:errorUserInfo];
  24.                 }
  25.                 return nil;
  26.         }
  27.        
  28.         NSLog(@"hexStr=%@ rowStr = %@ colStr = %@ row=%d col = %d", hexStr, rowStr, colStr, row, col);
  29.         return [NSIndexPath indexPathForX: col Y: row];
  30. }