Pastie now auto-senses if line-wrap is a bad or good idea. Feedback?
## mark a section (Learn more)
@implementation NSMutableString (NSMutableStringHypenAdditions) -(void) addSoftHypens; { NSMutableAttributedString *string = [[[NSMutableAttributedString alloc] initWithString:self] autorelease]; NSRange wordRange = NSMakeRange([string length], 0); NSString *shy = [NSString stringWithFormat: @"%C", 0xad]; do { wordRange = [string doubleClickAtIndex:wordRange.location-2]; NSUInteger hyphenIndex = NSMaxRange(wordRange); do { hyphenIndex = [string lineBreakByHyphenatingBeforeIndex:hyphenIndex withinRange:wordRange]; if (hyphenIndex!=NSNotFound) { [self insertString:shy atIndex:hyphenIndex]; } } while (hyphenIndex!=NSNotFound); } while (wordRange.location>2); } @end
This paste will be private.
From the Design Piracy series on my blog: