Permalink
Browse files

120 columns in helper classes

  • Loading branch information...
1 parent 8dda596 commit 74250108e1e04c1533c41e1fbaec978fea8c678e @eofster eofster committed Nov 25, 2012
@@ -36,42 +36,32 @@
@implementation ABAddressBook (AKAddressBookLocalizingAdditions)
- (NSString *)ak_localizedLabel:(NSString *)label {
- NSString *theString;
-
- if ([label isEqualToString:kABPhoneWorkLabel]) {
- theString = NSLocalizedStringFromTable(@"work", @"AddressBookLabels",
- @"Work phone number.");
- } else if ([label isEqualToString:kABPhoneHomeLabel]) {
- theString = NSLocalizedStringFromTable(@"home", @"AddressBookLabels",
- @"Home phone number.");
- } else if ([label isEqualToString:kABPhoneMobileLabel]) {
- theString = NSLocalizedStringFromTable(@"mobile", @"AddressBookLabels",
- @"Mobile phone number.");
- } else if ([label isEqualToString:kABPhoneMainLabel]) {
- theString = NSLocalizedStringFromTable(@"main", @"AddressBookLabels",
- @"Main phone number.");
- } else if ([label isEqualToString:kABPhoneHomeFAXLabel]) {
- theString = NSLocalizedStringFromTable(@"home fax", @"AddressBookLabels",
- @"Home FAX number.");
- } else if ([label isEqualToString:kABPhoneWorkFAXLabel]) {
- theString = NSLocalizedStringFromTable(@"work fax", @"AddressBookLabels",
- @"Work FAX number.");
- } else if ([label isEqualToString:kABPhonePagerLabel]) {
- theString = NSLocalizedStringFromTable(@"pager", @"AddressBookLabels",
- @"Pager number.");
- } else if ([label isEqualToString:kABOtherLabel]) {
- theString = NSLocalizedStringFromTable(@"other", @"AddressBookLabels",
- @"Other number.");
- } else if ([label isEqualToString:@"sip"]) {
- theString = NSLocalizedStringFromTable(@"sip", @"AddressBookLabels",
- @"SIP address.");
- } else {
- CFStringRef localizedLabel
- = ABCopyLocalizedPropertyOrLabel((CFStringRef)label);
- theString = [(NSString *)localizedLabel autorelease];
- }
-
- return theString;
+ NSString *theString;
+
+ if ([label isEqualToString:kABPhoneWorkLabel]) {
+ theString = NSLocalizedStringFromTable(@"work", @"AddressBookLabels", @"Work phone number.");
+ } else if ([label isEqualToString:kABPhoneHomeLabel]) {
+ theString = NSLocalizedStringFromTable(@"home", @"AddressBookLabels", @"Home phone number.");
+ } else if ([label isEqualToString:kABPhoneMobileLabel]) {
+ theString = NSLocalizedStringFromTable(@"mobile", @"AddressBookLabels", @"Mobile phone number.");
+ } else if ([label isEqualToString:kABPhoneMainLabel]) {
+ theString = NSLocalizedStringFromTable(@"main", @"AddressBookLabels", @"Main phone number.");
+ } else if ([label isEqualToString:kABPhoneHomeFAXLabel]) {
+ theString = NSLocalizedStringFromTable(@"home fax", @"AddressBookLabels", @"Home FAX number.");
+ } else if ([label isEqualToString:kABPhoneWorkFAXLabel]) {
+ theString = NSLocalizedStringFromTable(@"work fax", @"AddressBookLabels", @"Work FAX number.");
+ } else if ([label isEqualToString:kABPhonePagerLabel]) {
+ theString = NSLocalizedStringFromTable(@"pager", @"AddressBookLabels", @"Pager number.");
+ } else if ([label isEqualToString:kABOtherLabel]) {
+ theString = NSLocalizedStringFromTable(@"other", @"AddressBookLabels", @"Other number.");
+ } else if ([label isEqualToString:@"sip"]) {
+ theString = NSLocalizedStringFromTable(@"sip", @"AddressBookLabels", @"SIP address.");
+ } else {
+ CFStringRef localizedLabel = ABCopyLocalizedPropertyOrLabel((CFStringRef)label);
+ theString = [(NSString *)localizedLabel autorelease];
+ }
+
+ return theString;
}
@end
@@ -36,35 +36,35 @@ @implementation ABRecord (AKRecordQueryingAdditions)
@dynamic ak_fullName;
- (NSString *)ak_fullName {
- NSString *firstName = [self valueForProperty:kABFirstNameProperty];
- NSString *lastName = [self valueForProperty:kABLastNameProperty];
- NSString *company = [self valueForProperty:kABOrganizationProperty];
- NSInteger personFlags = [[self valueForProperty:kABPersonFlags] integerValue];
- BOOL isPerson = (personFlags & kABShowAsMask) == kABShowAsPerson;
- BOOL isCompany = (personFlags & kABShowAsMask) == kABShowAsCompany;
-
- ABAddressBook *AB = [ABAddressBook sharedAddressBook];
- NSString *theString = nil;
- if (isPerson) {
- if ([firstName length] > 0 && [lastName length] > 0) {
- if ([AB defaultNameOrdering] == kABFirstNameFirst) {
- theString = [NSString stringWithFormat:@"%@ %@", firstName, lastName];
- } else {
- theString = [NSString stringWithFormat:@"%@ %@", lastName, firstName];
- }
- } else if ([firstName length] > 0) {
- theString = firstName;
- } else if ([lastName length] > 0) {
- theString = lastName;
- }
+ NSString *firstName = [self valueForProperty:kABFirstNameProperty];
+ NSString *lastName = [self valueForProperty:kABLastNameProperty];
+ NSString *company = [self valueForProperty:kABOrganizationProperty];
+ NSInteger personFlags = [[self valueForProperty:kABPersonFlags] integerValue];
+ BOOL isPerson = (personFlags & kABShowAsMask) == kABShowAsPerson;
+ BOOL isCompany = (personFlags & kABShowAsMask) == kABShowAsCompany;
- } else if (isCompany) {
- if ([company length] > 0) {
- theString = company;
+ ABAddressBook *AB = [ABAddressBook sharedAddressBook];
+ NSString *theString = nil;
+ if (isPerson) {
+ if ([firstName length] > 0 && [lastName length] > 0) {
+ if ([AB defaultNameOrdering] == kABFirstNameFirst) {
+ theString = [NSString stringWithFormat:@"%@ %@", firstName, lastName];
+ } else {
+ theString = [NSString stringWithFormat:@"%@ %@", lastName, firstName];
+ }
+ } else if ([firstName length] > 0) {
+ theString = firstName;
+ } else if ([lastName length] > 0) {
+ theString = lastName;
+ }
+
+ } else if (isCompany) {
+ if ([company length] > 0) {
+ theString = company;
+ }
}
- }
-
- return theString;
+
+ return theString;
}
@end
@@ -32,11 +32,11 @@
@implementation NSString (AKStringCreatingAdditions)
+ (NSString *)ak_uuidString {
- CFUUIDRef theUUID = CFUUIDCreate(NULL);
- CFStringRef string = CFUUIDCreateString(NULL, theUUID);
- CFRelease(theUUID);
-
- return [(NSString *)string autorelease];
+ CFUUIDRef theUUID = CFUUIDCreate(NULL);
+ CFStringRef string = CFUUIDCreateString(NULL, theUUID);
+ CFRelease(theUUID);
+
+ return [(NSString *)string autorelease];
}
@end
@@ -32,16 +32,14 @@
// A category for escaping strings.
@interface NSString (AKStringEscapingAdditions)
-// Returns a new string created from the receiver where every occurrence of the
-// first character from a given string is escaped with a backslash.
+// Returns a new string created from the receiver where every occurrence of the first character from a given string is
+// escaped with a backslash.
- (NSString *)ak_escapeFirstCharacterFromString:(NSString *)string;
-// Returns a new string created from the receiver where every quote character,
-// i.e. |"|, is escaped with a backslash.
+// Returns a new string created from the receiver where every quote character, i.e. |"|, is escaped with a backslash.
- (NSString *)ak_escapeQuotes;
-// Returns a new string created from the receiver where every parenthesis, i.e.
-// |(| or |)|, is escaped with a backslash.
+// Returns a new string created from the receiver where every parenthesis, i.e. |(| or |)|, is escaped with a backslash.
- (NSString *)ak_escapeParentheses;
@end
@@ -32,32 +32,28 @@
@implementation NSString (AKStringEscapingAdditions)
- (NSString *)ak_escapeFirstCharacterFromString:(NSString *)string {
- NSMutableString *newString = [NSMutableString stringWithString:self];
- NSString *escapeCharacterString
- = [string substringWithRange:NSMakeRange(0, 1)];
- NSRange escapeCharacterRange
- = [newString rangeOfString:escapeCharacterString];
- while (escapeCharacterRange.location != NSNotFound) {
- [newString insertString:@"\\" atIndex:escapeCharacterRange.location];
- NSRange searchRange;
- searchRange.location = escapeCharacterRange.location + 2;
- searchRange.length = [newString length] - searchRange.location;
- escapeCharacterRange = [newString rangeOfString:escapeCharacterString
- options:0
- range:searchRange];
- }
-
- return [[newString copy] autorelease];
+ NSMutableString *newString = [NSMutableString stringWithString:self];
+ NSString *escapeCharacterString = [string substringWithRange:NSMakeRange(0, 1)];
+ NSRange escapeCharacterRange = [newString rangeOfString:escapeCharacterString];
+ while (escapeCharacterRange.location != NSNotFound) {
+ [newString insertString:@"\\" atIndex:escapeCharacterRange.location];
+ NSRange searchRange;
+ searchRange.location = escapeCharacterRange.location + 2;
+ searchRange.length = [newString length] - searchRange.location;
+ escapeCharacterRange = [newString rangeOfString:escapeCharacterString options:0 range:searchRange];
+ }
+
+ return [[newString copy] autorelease];
}
- (NSString *)ak_escapeQuotes {
- return [self ak_escapeFirstCharacterFromString:@"\""];
+ return [self ak_escapeFirstCharacterFromString:@"\""];
}
- (NSString *)ak_escapeParentheses {
- NSString *returnString = [self ak_escapeFirstCharacterFromString:@")"];
-
- return [returnString ak_escapeFirstCharacterFromString:@"("];
+ NSString *returnString = [self ak_escapeFirstCharacterFromString:@")"];
+
+ return [returnString ak_escapeFirstCharacterFromString:@"("];
}
@end
View
@@ -34,14 +34,14 @@
@implementation NSString (AKStringPJSUAAdditions)
+ (NSString *)stringWithPJString:(pj_str_t)pjString {
- return [[[NSString alloc] initWithBytes:pjString.ptr
- length:(NSUInteger)pjString.slen
- encoding:NSUTF8StringEncoding]
- autorelease];
+ return [[[NSString alloc] initWithBytes:pjString.ptr
+ length:(NSUInteger)pjString.slen
+ encoding:NSUTF8StringEncoding]
+ autorelease];
}
- (pj_str_t)pjString {
- return pj_str((char *)[self cStringUsingEncoding:NSUTF8StringEncoding]);
+ return pj_str((char *)[self cStringUsingEncoding:NSUTF8StringEncoding]);
}
@end
@@ -34,8 +34,8 @@
// A category for scanning strings.
@interface NSString (AKStringScanningAdditions)
-// A Boolean value indicating whether the receiver is a telephone number, e.g.
-// it consists of contiguous digits with an optional leading plus character.
+// A Boolean value indicating whether the receiver is a telephone number, e.g. it consists of contiguous digits with
+// an optional leading plus character.
@property (nonatomic, readonly, assign) BOOL ak_isTelephoneNumber;
// A Boolean value indicating whether the receiver consists only of a-z or A-Z.
@@ -38,28 +38,26 @@ @implementation NSString (AKStringScanningAdditions)
@dynamic ak_isIPAddress;
- (BOOL)ak_isTelephoneNumber {
- NSPredicate *telephoneNumberPredicate
- = [NSPredicate predicateWithFormat:@"SELF MATCHES '\\\\+?\\\\d+'"];
-
- return ([telephoneNumberPredicate evaluateWithObject:self]) ? YES : NO;
+ NSPredicate *telephoneNumberPredicate = [NSPredicate predicateWithFormat:@"SELF MATCHES '\\\\+?\\\\d+'"];
+
+ return ([telephoneNumberPredicate evaluateWithObject:self]) ? YES : NO;
}
- (BOOL)ak_hasLetters {
- NSPredicate *containsLettersPredicate
- = [NSPredicate predicateWithFormat:@"SELF MATCHES '.*[a-zA-Z].*'"];
-
- return ([containsLettersPredicate evaluateWithObject:self]) ? YES : NO;
+ NSPredicate *containsLettersPredicate = [NSPredicate predicateWithFormat:@"SELF MATCHES '.*[a-zA-Z].*'"];
+
+ return ([containsLettersPredicate evaluateWithObject:self]) ? YES : NO;
}
- (BOOL)ak_isIPAddress {
- NSPredicate *IPAddressPredicate
- = [NSPredicate predicateWithFormat:@"SELF MATCHES "
- "'\\\\b(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\\\."
- "(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\\\."
- "(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\\\."
- "(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\\\b'"];
-
- return ([IPAddressPredicate evaluateWithObject:self]) ? YES : NO;
+ NSPredicate *IPAddressPredicate
+ = [NSPredicate predicateWithFormat:@"SELF MATCHES "
+ "'\\\\b(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\\\."
+ "(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\\\."
+ "(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\\\."
+ "(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\\\b'"];
+
+ return ([IPAddressPredicate evaluateWithObject:self]) ? YES : NO;
}
@end
@@ -34,13 +34,10 @@
// A category for window resizing.
@interface NSWindow (AKWindowResizingAdditions)
-// Sets |aView| content view for the receiver and resizes the receiver with
-// optional animation.
-- (void)ak_resizeAndSwapToContentView:(NSView *)aView
- animate:(BOOL)performAnimation;
+// Sets |aView| content view for the receiver and resizes the receiver with optional animation.
+- (void)ak_resizeAndSwapToContentView:(NSView *)aView animate:(BOOL)performAnimation;
-// Calls |ak_resizeAndSwapToContentView:animate:| with |performAnimation| set
-// to NO.
+// Calls |ak_resizeAndSwapToContentView:animate:| with |performAnimation| set to NO.
- (void)ak_resizeAndSwapToContentView:(NSView *)aView;
@end
@@ -33,34 +33,33 @@
@implementation NSWindow (AKWindowResizingAdditions)
-- (void)ak_resizeAndSwapToContentView:(NSView *)aView
- animate:(BOOL)performAnimation {
- // Compute view size delta.
- NSSize currentSize = [[self contentView] frame].size;
- NSSize newSize = [aView frame].size;
- CGFloat deltaWidth = newSize.width - currentSize.width;
- CGFloat deltaHeight = newSize.height - currentSize.height;
-
- // Compute new window size.
- NSRect windowFrame = [self frame];
- windowFrame.size.height += deltaHeight;
- windowFrame.origin.y -= deltaHeight;
- windowFrame.size.width += deltaWidth;
-
- // Show temp view while changing views.
- NSView *tempView = [[NSView alloc] initWithFrame:[[self contentView] frame]];
- [self setContentView:tempView];
- [tempView release];
-
- // Set new window frame.
- [self setFrame:windowFrame display:YES animate:performAnimation];
-
- // Swap to the new view.
- [self setContentView:aView];
+- (void)ak_resizeAndSwapToContentView:(NSView *)aView animate:(BOOL)performAnimation {
+ // Compute view size delta.
+ NSSize currentSize = [[self contentView] frame].size;
+ NSSize newSize = [aView frame].size;
+ CGFloat deltaWidth = newSize.width - currentSize.width;
+ CGFloat deltaHeight = newSize.height - currentSize.height;
+
+ // Compute new window size.
+ NSRect windowFrame = [self frame];
+ windowFrame.size.height += deltaHeight;
+ windowFrame.origin.y -= deltaHeight;
+ windowFrame.size.width += deltaWidth;
+
+ // Show temp view while changing views.
+ NSView *tempView = [[NSView alloc] initWithFrame:[[self contentView] frame]];
+ [self setContentView:tempView];
+ [tempView release];
+
+ // Set new window frame.
+ [self setFrame:windowFrame display:YES animate:performAnimation];
+
+ // Swap to the new view.
+ [self setContentView:aView];
}
- (void)ak_resizeAndSwapToContentView:(NSView *)aView {
- [self ak_resizeAndSwapToContentView:aView animate:NO];
+ [self ak_resizeAndSwapToContentView:aView animate:NO];
}
@end
@@ -32,23 +32,21 @@
@class AKSIPURI;
-// Instances of AKSIPURIFormatter create string representations of AKSIPURI, and
-// convert textual representations of SIP URIs into AKSIPURI objects.
+// Instances of AKSIPURIFormatter create string representations of AKSIPURI, and convert textual representations of SIP
+// URIs into AKSIPURI objects.
@interface AKSIPURIFormatter : NSFormatter {
- @private
- BOOL formatsTelephoneNumbers_;
- BOOL telephoneNumberFormatterSplitsLastFourDigits_;
+ @private
+ BOOL formatsTelephoneNumbers_;
+ BOOL telephoneNumberFormatterSplitsLastFourDigits_;
}
// A Boolean value indicating whether the receiver formats telephone numbers.
@property (nonatomic, assign) BOOL formatsTelephoneNumbers;
-// A Boolean value indicating whether the receiver's telephone number formatter
-// splits last four digits.
+// A Boolean value indicating whether the receiver's telephone number formatter splits last four digits.
@property (nonatomic, assign) BOOL telephoneNumberFormatterSplitsLastFourDigits;
-// Wrapper for |getObjectValue:forString:errorDescription:|. Returns AKSIPURI
-// object converted from a given string.
+// Wrapper for |getObjectValue:forString:errorDescription:|. Returns AKSIPURI object converted from a given string.
- (AKSIPURI *)SIPURIFromString:(NSString *)SIPURIString;
@end
Oops, something went wrong.

0 comments on commit 7425010

Please sign in to comment.