1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68
|
//
// MWTAMSStringCategories.m
// avtams
//
// Created by matthew on Sun Mar 21 2004.
// Copyright (c) 2004 __MyCompanyName__. All rights reserved.
//
#import "MWTAMSStringCategories.h"
@implementation NSString(MWTAMSStringCategories)
-(NSString *) copyrelease
{
return [[self copy] autorelease];
}
-(int) numberOfCodeComponents
{
return [[self codeComponents] count];
}
-(NSString *) lastCodeComponents: (int) cnt
{
NSArray *myComponents;
int n;
myComponents = [self codeComponents];
n = [myComponents count];
if(cnt < n)
{
NSArray *myNewSelf;
myNewSelf = [myComponents subarrayWithRange: NSMakeRange(n - cnt, cnt)];
return [myNewSelf componentsJoinedByString: @">"];
}
else return [self copyrelease];
}
-(NSString *) lastCodeComponent
{
return [self lastCodeComponents: 1];
}
-(NSString *) firstCodeComponents: (int) cnt
{
NSArray *myComponents;
int n;
myComponents = [self codeComponents];
n = [myComponents count];
if(cnt < n)
{
NSArray *myNewSelf;
myNewSelf = [myComponents subarrayWithRange: NSMakeRange(0, cnt)];
return [myNewSelf componentsJoinedByString: @">"];
}
else return [self copyrelease];
}
-(NSString *) firstCodeComponent
{
return [self firstCodeComponents: 1];
}
-(NSArray *) codeComponents
{
return [self componentsSeparatedByString: @">"];
}
@end
|