Report abuse

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
@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