aboutsummaryrefslogtreecommitdiffstats
path: root/Source/SPDataAdditions.m
diff options
context:
space:
mode:
Diffstat (limited to 'Source/SPDataAdditions.m')
-rw-r--r--Source/SPDataAdditions.m22
1 files changed, 22 insertions, 0 deletions
diff --git a/Source/SPDataAdditions.m b/Source/SPDataAdditions.m
index ec91f55c..8018de8a 100644
--- a/Source/SPDataAdditions.m
+++ b/Source/SPDataAdditions.m
@@ -187,5 +187,27 @@ static char base64encodingTable[64] = {
return retVal;
}
+/*
+ * Convert data objects to their string representation (max 255 chars)
+ * in the current encoding, falling back to ascii. (Mainly used for displaying
+ * large blob data in a tableView)
+ */
+- (NSString *) shortStringRepresentationUsingEncoding:(NSStringEncoding)encoding
+{
+ NSString *tmp = [[NSString alloc] initWithData:self encoding:encoding];
+ NSString *shortString;
+ if (tmp == nil)
+ tmp = [[NSString alloc] initWithData:self encoding:NSASCIIStringEncoding];
+ if (tmp == nil)
+ return @"- cannot be displayed -";
+ else {
+ if([tmp length]>255)
+ shortString = [[NSString stringWithString:tmp] substringToIndex:255];
+ else
+ shortString = [NSString stringWithString:tmp];
+ }
+ [tmp release];
+ return shortString;
+}
@end