2011-01-19 23:19:43 +03:00
|
|
|
//
|
|
|
|
// NSString_AITruncation.m
|
|
|
|
// PSMTabBarControl
|
|
|
|
//
|
|
|
|
// Created by Evan Schoenberg on 7/14/07.
|
|
|
|
// From Adium, which is licensed under the GPL. Used in PSMTabBarControl with permission.
|
|
|
|
// The contents of this remain licensed under the GPL.
|
|
|
|
//
|
|
|
|
|
|
|
|
#import "NSString_AITruncation.h"
|
|
|
|
|
|
|
|
@implementation NSString (AITruncation)
|
|
|
|
|
2011-01-26 13:52:13 +03:00
|
|
|
+ (id)ellipsis {
|
2011-01-19 23:19:43 +03:00
|
|
|
return [NSString stringWithUTF8String:"\xE2\x80\xA6"];
|
|
|
|
}
|
|
|
|
|
2011-01-26 13:52:13 +03:00
|
|
|
- (NSString *)stringWithEllipsisByTruncatingToLength:(NSUInteger)length {
|
2011-01-19 23:19:43 +03:00
|
|
|
NSString *returnString;
|
2011-01-26 13:52:13 +03:00
|
|
|
|
|
|
|
if(length < [self length]) {
|
2011-01-19 23:19:43 +03:00
|
|
|
//Truncate and append the ellipsis
|
2011-01-26 13:52:13 +03:00
|
|
|
returnString = [[self substringToIndex:length - 1] stringByAppendingString:[NSString ellipsis]];
|
2011-01-19 23:19:43 +03:00
|
|
|
} else {
|
|
|
|
//We don't need to truncate, so don't append an ellipsis
|
|
|
|
returnString = [[self copy] autorelease];
|
|
|
|
}
|
2011-01-26 13:52:13 +03:00
|
|
|
|
2011-01-19 23:19:43 +03:00
|
|
|
return returnString;
|
|
|
|
}
|
|
|
|
|
|
|
|
@end
|